c++ - 为什么我在链接期间得到 "undefined reference to ` glibtop_init'"?

标签 c++ gcc linker g++

我正在使用 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/

相关文章:

gcc - 宏 asm 内联错误

C 系统调用 msgsnd() : invalid argument error on certain compiler versions

c++ - 移植Qt4到Qt5 : unresolved external symbols

c - 使用GDB时缺少ELF符号 "var"?

c++ - 在使用 GCC 4.8.5 构建的应用程序中未定义对 cxx11 函数的引用

c++ - 主程序中的函数正常,否则 undefined reference

c++ - Armadillo 中的字段初始化

c++ - 这段编译良好的荒谬代码是 Clang 和 GCC 中的错误吗?

c++ - 如何用sfinae检查,type是否有operator()?

c++ - 包括其他驱动器号和E1696文档的源文件和头文件