我正在使用 eclipse 构建一个非常小的 C/C++ 项目,并且在构建过程中得到以下信息:
make all<br/>
Building file: ../Metric.cpp<br/>
Invoking: GCC C++ Compiler<br/>
g++ -I/usr/include/glib-2.0 -I/usr/include/libgtop-2.0 -I/usr/lib/glib-2.0/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Metric.d" -MT"Metric.d" -o"Metric.o" "../Metric.cpp"<br/>
Finished building: ../Metric.cpp<br/>
Building target: linuxMonitor<br/>
Invoking: GCC C++ Linker<br/>
g++ -L/usr/lib -o"linuxMonitor" ./Metric.o<br/>
./Metric.o: In function <code>main':<br/>
/home/mike/workspace_c/linuxMonitor/Debug/../Metric.cpp:27: undefined reference to</code>glibtop_init'<br/>
collect2: ld returned 1 exit status<br/>
make: *** [linuxMonitor] Error 1<br/>
我想不通的是链接失败的原因,或者要使用哪个链接标志才能使这该死的东西正常工作! -L/usr/lib
应该将链接器指向库所在的目录,但它仍然失败。当我做 -l/usr/lib/myLibrary.a
它仍然没有说它找不到 -l/usr/lib/myLibrary.a
任何有关为链接器使用正确命令的提示或建议,我们将不胜感激!我卡住了!
-迈克
最佳答案
你的库文件应该是 libsomething.a 和 g++ 选项 -lsomething
g++ 的联机帮助页对此有更具体的说明:
-l library
...
The linker searches a standard list of directories for the library,
which is actually a file named liblibrary.a. The linker then uses
this file as if it had been specified precisely by name.
The directories searched include several standard system
directories plus any that you specify with -L.
...
The only difference between using an -l option and
specifying a file name is that -l surrounds library with lib and .a
and searches several directories.
关于c++ - 为什么我在链接期间得到 "undefined reference to ` glibtop_init'"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2256351/