Clang Linking with SO

房东的猫 提交于 2019-12-03 06:17:34

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!