我正在使用Eclipse-CDT在Ubuntu x64上设置一个C++项目.我基本上是在打招呼世界并链接到商业第三方图书馆.
我已经包含了链接到其库的头文件,但我仍然遇到链接器错误.除了明显的问题之外,这里是否存在一些可能的问题(例如我99%肯定我正在链接到正确的库).
Eclipse说:
Building target: LinkProblem Invoking: GCC C++ Linker g++ -L/home/notroot/workspace/somelib-3/somelib/target/bin -o"LinkProblem" ./src/LinkProblem.o -lsomelib1 -lpthread -lsomelib2 -lsomelib3 ./src/LinkProblem.o: In function `main': /home/notroot/workspace/LinkProblem/Debug/../src/LinkProblem.cpp:17: undefined reference to `SomeClass::close()' ./src/LinkProblem.o: In function `SomeOtherClass': /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:148: undefined reference to `SomeClass::SomeClass()' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:148: undefined reference to `vtable for SomeOtherClass' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:151: undefined reference to `SomeClass::~SomeClass()' ./src/LinkProblem.o: In function `~SomeOtherClass': /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `vtable for SomeOtherClass' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `SomeClass::~SomeClass()' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `SomeClass::~SomeClass()' collect2: ld returned 1 exit status make: *** …
我在构建用C++编码的可执行文件时遇到了一个奇怪的问题,它使用的C++库本身依赖于C库.我使用gcc和使用g ++的所有其他源模块编译了构成C库的C模块.C和C++库都是静态库.
当我在C++源代码中包含来自C库的头文件时,我将其包装在extern"C"中:
extern "C"
{
#include <c-library-header.h>
}
Run Code Online (Sandbox Code Playgroud)
现在奇怪的是链接时得到"未定义的引用"错误,但这些错误取决于我列出库的顺序:
我本以为在g ++命令行中出现静态库的顺序是完全无关紧要的.有人有任何线索吗?
我对 C++ 和犰狳很陌生,并且遇到了下面描述的构建错误。我正在尝试测试以下简单代码以将犰狳矩阵保存为 hdf5 文件:
\n\n#include <iostream>\n#include <armadillo>\n\nusing namespace std;\nusing namespace arma;\n\nint main()\n{\n mat A = randu<mat>(240,320);\n A.save("A.hdf5",hdf5_binary);\n\n return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n编译时,我收到以下错误:
\n\n/usr/include/armadillo_bits/hdf5_misc.hpp:131: undefined reference in \xc2\xab arma_H5T_NATIVE_DOUBLE \xc2\xbb\n/usr/include/armadillo_bits/hdf5_misc.hpp:131: undefined reference in \xc2\xab arma_H5Tcopy \xc2\xbb\nobj/Debug/main.o: in function \xc2\xab bool arma::diskio::save_hdf5_binary<double> (arma::Mat<double> const&, std::string const&) \xc2\xbb:\n/usr/include/armadillo_bits/diskio_meat.hpp:1299: undefined reference in \xc2\xab arma_H5Eset_auto \xc2\xbb\n/usr/include/armadillo_bits/diskio_meat.hpp:1308: undefined reference in \xc2\xab arma::H5check_version(unsigned int, unsigned int, unsigned int) \xc2\xbb\n/usr/include/armadillo_bits/diskio_meat.hpp:1308: undefined reference in \xc2\xab arma_H5Fcreate \xc2\xbb\n/usr/include/armadillo_bits/diskio_meat.hpp:1315: undefined reference in \xc2\xab arma_H5Screate_simple \xc2\xbb\n/usr/include/armadillo_bits/diskio_meat.hpp:1324: undefined reference in \xc2\xab …
Run Code Online (Sandbox Code Playgroud)