SO related 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 .so The command that I use 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 located in the same directory as Main.cpp. I thought -L./ would add .so in the path to the library path.

+6
source share
1 answer

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

You can also skip adding the path and link it directly to the file:

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

Note that the runtime linker (which actually loads the shared libraries when your program starts) may not be able to find the library if it is not in the path of the runtime linker. You can specify the linker (compilation time) to add the path to the shared library path in the generated program:

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

The -Wl option tells the compiler to pass the option to the linker, and the -rpath linker -rpath adds the path to the search path in the runtime.

+15
source

Source: https://habr.com/ru/post/973416/


All Articles