使用ceres库时报错:undefined reference to `ceres::Problem::Problem()‘

编译cmake项目链接ceres库时名称没有写对导致报错:

myCeres.cpp:(.text.startup+0x247): undefined reference to `ceres::Problem::Problem()'
myCeres.cpp:(.text.startup+0x2aa): undefined reference to `ceres::CostFunction::CostFunction()'
myCeres.cpp:(.text.startup+0x31d): undefined reference to `ceres::Problem::AddResidualBlock(ceres::CostFunction*, ceres::LossFunction*, double* const*, int)'
myCeres.cpp:(.text.startup+0x905): undefined reference to `ceres::Solve(ceres::Solver::Options const&, ceres::Problem*, ceres::Solver::Summary*)'
myCeres.cpp:(.text.startup+0x97b): undefined reference to `ceres::Solver::Summary::BriefReport[abi:cxx11]() const'
myCeres.cpp:(.text.startup+0xa1a): undefined reference to `ceres::Problem::~Problem()'
myCeres.cpp:(.text.startup+0xb83): undefined reference to `ceres::Problem::~Problem()'
myCeres.cpp:(.text.startup+0xb95): undefined reference to `ceres::CostFunction::~CostFunction()'

解决方法

在链接ceres库时使用CERES_LIBRARIES,而不是CERES_LIBS

add_executable(myCeres myCeres.cpp)
target_link_libraries(myCeres ${OpenCV_LIBS} ${CERES_LIBRARIES})