Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么在向类添加新函数后,应用程序会编译,但在链接阶段失败?_C++_Cmake_Mingw W64_Boost Ublas - Fatal编程技术网

C++ 为什么在向类添加新函数后,应用程序会编译,但在链接阶段失败?

C++ 为什么在向类添加新函数后,应用程序会编译,但在链接阶段失败?,c++,cmake,mingw-w64,boost-ublas,C++,Cmake,Mingw W64,Boost Ublas,我的项目正在使用以下方法构建: Eclipse, CMakeLists.txt, MinGW 4.8.1 项目编译和应用程序链接正常。但加上 boost::ublas::matrix类型的“Helper.cpp”中的3个函数和“CamData.cpp”中的2个函数 链接器放弃,无法再找到函数(未定义的引用错误),尽管它可以编译这些函数(编译对象文件*.cpp.obj时没有错误) 代码结构 Main.cpp CMain.cpp Helper.cpp (Boost::ublas::matrix<

我的项目正在使用以下方法构建:
Eclipse
CMakeLists.txt
MinGW 4.8.1

项目编译和应用程序链接正常。但加上

boost::ublas::matrix类型的“Helper.cpp”中的3个函数和“CamData.cpp”中的2个函数

链接器放弃,无法再找到函数(未定义的引用错误),尽管它可以编译这些函数(编译对象文件*.cpp.obj时没有错误

代码结构

Main.cpp
CMain.cpp
Helper.cpp (Boost::ublas::matrix<double> Fnction1, ...) 
CamData.cpp (Boost::ublas::matrix<double> Funtion4, ...)
在main.cpp中注释掉函数和它们的调用后,可以再次链接程序。你知道是什么导致了这一切吗

下面的错误日志

class Helper{
    Helper();
    virtual ~Helper();
template<typename T>
using bMatrix =  boost::numeric::ublas::matrix<T>;

bMatrix<double> getmatrixQ(double w, double x, double y, double z);
bMatrix<double> rotate_x(bMatrix<double> M, double angleinrad);  
bMatrix<double> getTransformationMatrix(bMatrix<double> M, double x, double y, double z);
};
[100%] Linking CXX executable Project.exe
CMakeFiles\Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x116c): undefined reference to `esg::CHelper::getmatrixQ(double, doubl
e, double, double)'
CMakeFiles\Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1230): undefined reference to `esg::CHelper::rotate_x(boost::numeric:
:ublas::matrix<double, boost::numeric::ublas::basic_row_major<unsigned int, int>, boost::numeric::ublas::unbounded_array<double, std::alloca
tor<double> > >, double)'
CMakeFiles\Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1344): undefined reference to `esg::CHelper::getTransformationMatrix(
boost::numeric::ublas::matrix<double, boost::numeric::ublas::basic_row_major<unsigned int, int>, boost::numeric::ublas::unbounded_array<doub
le, std::allocator<double> > >, double, double, double)'
CMakeFiles\Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x149d): undefined reference to `esg::CCamData::initpinhole(esg::Pinhol
eIntrinsics&)'
CMakeFiles\Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x15d3): undefined reference to `esg::CCamData::createProjectionMatrix(
boost::numeric::ublas::matrix<double, boost::numeric::ublas::basic_row_major<unsigned int, int>, boost::numeric::ublas::unbounded_array<doub
le, std::allocator<double> > >, boost::numeric::ublas::matrix<double, boost::numeric::ublas::basic_row_major<unsigned int, int>, boost::nume
ric::ublas::unbounded_array<double, std::allocator<double> > >&, long)'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\Project.dir\build.make:548: recipe for target 'Project.exe' failed
mingw32-make.exe[2]: *** [Project.exe] Error 1
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Project.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/Project.dir/all] Error 2
Makefile:82: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2  
[100%]链接CXX可执行项目.exe
CMakeFiles\Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x116c):对`esg::CHelper::getmatrixQ(double,doubl)的未定义引用
e、 双,双)'
CMakeFiles\Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1230):对`esg::CHelper::rotate_x的未定义引用(boost::numeric:
:ublas::矩阵,双)'
CMakeFiles\Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1344):对`esg::CHelper::getTransformationMatrix'的未定义引用(
boost::numeric::ublas::matrix,double,double,double)'
CMakeFiles\Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x149d):对`esg::CCamData::initpinhole(esg::pinhole)的未定义引用
电子信息系统&)
CMakeFiles\Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x15d3):对`esg::CCamData::createProjectionMatrix'的未定义引用(
boost::numeric::ublas::matrix,boost::numeric::ublas::matrix&,long)'
collect2.exe:错误:ld返回了1个退出状态
CMakeFiles\Project.dir\build.make:548:目标'Project.exe'的配方失败
mingw32 make.exe[2]:***[Project.exe]错误1
CMakeFiles\Makefile2:66:目标“CMakeFiles/Project.dir/all”的配方失败
mingw32 make.exe[1]:***[CMakeFiles/Project.dir/all]错误2
Makefile:82:目标“全部”的配方失败
mingw32-make.exe:**[all]错误2

好吧,这就是为什么我在链接时收到错误,而不是在编译时收到错误

cpp文件中的函数声明如下:

Type Function_Name (arguments)
{
  // do something
}   
Type Class_name::Function_Name (arguments)
{
  // do something
}   
但应该是这样的:

Type Function_Name (arguments)
{
  // do something
}   
Type Class_name::Function_Name (arguments)
{
  // do something
}   

因此,它在链接时无法找到它们,但可以在
cpp
文件中单独编译它们。

我们需要一个最小的完整示例。请删除标记c++11和boost,因为它们是重复的或不相关的。现在是“最小和完整的!”:-)除了投票否决之外,您对解决方案有何见解?根据错误日志,您用于
add\u executable
的源文件均未实现给定的功能。注意,该实现应该使用与声明完全相同的签名和命名空间。