简体   繁体   中英

Error when linking shared library after compiling objects

I compiled the object files, and then tried to compile the executable, which failed by saying that there are undefined references to functions in "theLib".

g++ -I./theLib/src -c -o obj/main.o src/main.cpp

(works so far)

g++ -L./theLib -Wl,-rpath=./theLib obj/main.o -ltheLib -o exe

(error: libtheLib.so: undefined reference to 'some_function' )

I checked for answers everywhere, and they all just suggest moving the -ltheLib part after the dependencies (which I did). But it still doesn't work. What really boggles my mind is that the same library compiles just fine for an example in a different directory.

The library is in C. Can that mess up trying to compile C++? Or am I just missing something with compiling the .o files first?

Turns out the library depended on functions that I had to implement and provide in my own source code. I never knew that some libraries did that, but lesson learned. Once I implemented the functions that were causing the errors and added those source files, it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM