我正在尝试使用 ceres-solver 包。使用自制软件安装后,我添加了创建的 CMakeLists.txt 文件,如下所示:
cmake_minimum_required(VERSION 3.8)
project(myproject)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(untitled ${SOURCE_FILES})
# add extra include directories
include_directories(/usr/local/include)
include_directories(/usr/local/include/eigen3)
# add extra lib directories
link_directories(/usr/local/lib)
但是,当我尝试使用 Ceres 包时,出现链接错误。作为一个非常简单的测试用例,我使用以下代码:
#include "ceres.h"
int main(int argc, char** argv) {
ceres::Problem problem;
return 0;
}
这会引发以下错误:
Undefined symbols for architecture x86_64:
"ceres::Problem::Problem()", referenced from:
_main in main.cpp.o
"ceres::Problem::~Problem()", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
通过查看stackoverflow,我现在知道我可能从CMakeLists.txt 中遗漏了一些东西,但无论我尝试什么,我似乎都无法摆脱错误。关于如何解决这个问题的任何建议?
我目前在 OS 10.12.6 上使用 CLion for Mac 工作。
发布解决方案编辑
根据 PureVision 的建议,我将 CMakeLists.txt 更改为以下内容,一切都很好
cmake_minimum_required(VERSION 3.8)
project(myproject)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
# add extra include directories
include_directories(/usr/local/include)
include_directories(/usr/local/include/eigen3)
# add extra lib directories
link_directories(/usr/local/lib)
link_libraries(glog)
link_libraries(ceres)
add_executable(myproject ${SOURCE_FILES})