[英]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". 我编译了目标文件,然后尝试编译可执行文件,但由于说“ 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'
) (错误:
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). 我到处检查了答案,它们都建议将
-ltheLib
部分移到依赖项之后(我这样做了)。 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++? 该库位于C中。尝试编译C ++会麻烦吗? Or am I just missing something with compiling the
.o
files first? 还是我只是缺少一些首先编译
.o
文件的东西?
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.
一旦我实现了导致错误的功能并添加了这些源文件,它便开始工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.