我是靠谱客的博主 清秀奇异果,最近开发中收集的这篇文章主要介绍java调用clang编译的so,用SO进行Clang链接,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I keep getting

ld: library not found for -lchaiscript_stdlib-5.3.1.so

clang: error: linker command failed with exit code 1 (use -v to see invocation)

When trying to link to a .so

The command I'm using is.

clang++ Main.cpp -o foo -L./ -lchaiscript_stdlib-5.3.1.so

What am I doing wrong?

libchaiscript_stdlib-5.3.1.so is in the same directory as Main.cpp I thought the -L./ would add the .so to the library seach paths.

解决方案

Yes the -L option adds the search path, but the linker adds the .so (or .a) suffix itself (just like it adds the lib prefix). So you only need to have -lchaiscript_stdlib-5.3.1 and the linker will find it.

You can also skip the adding of the path, and link directly with the file:

clang++ Main.cpp -o foo libchaiscript_stdlib-5.3.1.so

Note that the runtime linker (which is what actually loads the shared libraries when you run your program) might not be able to find the library if it's not in the runtime linkers path. You can tell the (compile time) linker to add a path to the shared-library path in the generated program though:

clang++ Main.cpp -o foo libchaiscript_stdlib-5.3.1.so -Wl,-rpath,/absolute/path

The -Wl option tells the compiler front-end to pass an option to the linker, and the linker option -rpath adds a path to the runtime-linker search path.

最后

以上就是清秀奇异果为你收集整理的java调用clang编译的so,用SO进行Clang链接的全部内容,希望文章能够帮你解决java调用clang编译的so,用SO进行Clang链接所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部