Clang linking with a .so file

user245019

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 file.

I'm using this command:

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

What am I doing wrong?

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

Some programmer dude

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 linker's 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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Clang linking with a .so file

From Dev

Linking/using .so file in another

From Dev

Linking so file within android ndk

From Dev

C++ Linking to .so file within makefile

From Dev

clang appears not to be linking to a library

From Dev

dlclose() not unloading .so-file which is linking to boost

From Dev

Clang linking error on Mac OSX

From Dev

Issue - kextload linking (Linking with .a file)

From Dev

Linking with libbluetooth.so

From Dev

libboost_*.so: file not recognized: File truncated When dynamically linking using libtool and automake to generate makefile

From Dev

libboost_*.so: file not recognized: File truncated When dynamically linking using libtool and automake to generate makefile

From Dev

Linking static libraries with clang independent of order

From Dev

Problems linking msvc intrinsics using clang on windows

From Dev

CMake "OBJECT" library: clang not linking properly

From Dev

linking clang lib allways undefined symbol

From Dev

Linking Boost with cmake and clang - undefined reference to symbol

From Dev

Explaining Clang dynamic/static library linking process

From Dev

Cross-compiling for ARM while linking to libssh - libssh.so: file not recognized

From Java

Failed linking file resources

From Dev

Large .a file not linking in android

From Dev

Linking CSS File To JSP

From Dev

CSS file not linking to HTML

From Dev

Linking to an embedded file in word

From Dev

Linking to Css file in CodeIgniter

From Dev

Linking to File With Space in JQuery

From Dev

Linking to Boost in DLL file

From Dev

Android NDK linking with shared .so

From Dev

linking html file with js file

From Dev

Cmake and clang tooling linking error (outside of source tree)

Related Related

HotTag

Archive