提问人:Draxent 提问时间:4/27/2016 最后编辑:Draxent 更新时间:4/27/2016 访问量:3935
CLion - cmake 未定义引用
CLion - cmake undefined reference
问:
我想用CLion执行一个工作项目。
所以我试图通过 cmake 模拟 Makefile,但我不太擅长。我确定错误在 cmake 内部,因为该项目正在使用常规 Makefile。不幸的是,我无法显示有关该项目的大量信息。我希望我将展示的内容足以获得您的帮助。
项目目录结构(不显示文件)如下所示:
.
├── CMakeLists.txt
├── makefile
├── include
│ ├── data
│ ├── io
│ ├── learning
│ ├── metric
│ ├── scoring
│ └── io
└── src
├── data
├── io
├── learning
├── metric
├── scoring
├── utils
└── main.cc
./CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(Project)
set(DCMAKE_CXX_COMPILER "g++-5")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(Boost 1.57.0 COMPONENTS program_options system filesystem REQUIRED)
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
include_directories(${Boost_INCLUDE_DIRS})
include_directories("include")
include_directories("src")
add_executable(Project src/main.cc)
target_link_libraries(Project ${Boost_LIBRARIES})
项目编译时没有错误,但在链接过程中失败。
部分错误报告如下:
[ 50%] Linking CXX executable Project
CMakeFiles/Project.dir/src/main.cc.o: in function "metric::ir::ir_metric_factory(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)":
./include/metric/metricfactory.h:47: undefined reference to "metric::ir::Dcg::NAME_[abi:cxx11]"
./include/metric/metricfactory.h:49: undefined reference to "metric::ir::Ndcg::NAME_[abi:cxx11]"
./include/metric/metricfactory.h:51: undefined reference to "metric::ir::Tndcg::NAME_[abi:cxx11]"
./include/metric/metricfactory.h:53: undefined reference to "metric::ir::Map::NAME_[abi:cxx11]"
CMakeFiles/Project.dir/src/main.cc.o: in function "main":
./src/main.cc:130: undefined reference to "learning::forests::LambdaMart::NAME_[abi:cxx11]"
./src/main.cc:170: undefined reference to "learning::forests::Mart::NAME_[abi:cxx11]"
./src/main.cc:171: undefined reference to "learning::forests::LambdaMart::NAME_[abi:cxx11]"
./src/main.cc:172: undefined reference to "learning::forests::ObliviousMart::NAME_[abi:cxx11]"
./src/main.cc:173: undefined reference to "learning::forests::ObliviousLambdaMart::NAME_[abi:cxx11]"
./src/main.cc:174: undefined reference to "learning::linear::CoordinateAscent::NAME_[abi:cxx11]"
./src/main.cc:175: undefined reference to "learning::forests::Project::NAME_[abi:cxx11]"
./src/main.cc:176: undefined reference to "learning::CustomLTR::NAME_[abi:cxx11]"
./src/main.cc:181: undefined reference to "metric::ir::Dcg::NAME_[abi:cxx11]"
./src/main.cc:182: undefined reference to "metric::ir::Ndcg::NAME_[abi:cxx11]"
./src/main.cc:183: undefined reference to "metric::ir::Tndcg::NAME_[abi:cxx11]"
./src/main.cc:184: undefined reference to "metric::ir::Map::NAME_[abi:cxx11]"
./src/main.cc:247: undefined reference to "metric::ir::Dcg::NAME_[abi:cxx11]"
./src/main.cc:248: undefined reference to "metric::ir::Ndcg::NAME_[abi:cxx11]"
./src/main.cc:249: undefined reference to "metric::ir::Tndcg::NAME_[abi:cxx11]"
./src/main.cc:250: undefined reference to "metric::ir::Map::NAME_[abi:cxx11]"
./src/main.cc:319: undefined reference to "learning::forests::LambdaMart::NAME_[abi:cxx11]"
./src/main.cc:324: undefined reference to "learning::forests::Mart::NAME_[abi:cxx11]"
./src/main.cc:329: undefined reference to "learning::forests::ObliviousMart::NAME_[abi:cxx11]"
./src/main.cc:334: undefined reference to "learning::forests::ObliviousLambdaMart::NAME_[abi:cxx11]"
./src/main.cc:339: undefined reference to "learning::linear::CoordinateAscent::NAME_[abi:cxx11]"
./src/main.cc:346: undefined reference to "learning::linear::CoordinateAscent::CoordinateAscent(unsigned int, double, double, unsigned int, unsigned int)"
./src/main.cc:347: undefined reference to "learning::forests::Project::NAME_[abi:cxx11]"
./src/main.cc:351: undefined reference to "learning::CustomLTR::NAME_[abi:cxx11]"
./src/main.cc:352: undefined reference to "learning::CustomLTR::CustomLTR()"
( other errors lines )
collect2: error: ld returned 1 exit status
make[2]: *** [Project] Error 1
make[1]: *** [CMakeFiles/Project.dir/all] Error 2
make: *** [all] Error 2
答:
0赞
Draxent
4/27/2016
#1
好的,多亏了 Tsyvarev 的帮助,我解决了它。
./CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(Project)
set(DCMAKE_CXX_COMPILER "g++-5")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(Boost 1.57.0 COMPONENTS program_options system filesystem REQUIRED)
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
include_directories(${Boost_INCLUDE_DIRS})
include_directories("include")
file(GLOB_RECURSE SOURCES src/*.cc) #*/
add_executable(Project ${SOURCES})
target_link_libraries(Project ${Boost_LIBRARIES})
我曾经添加源而不是.file(GLOB_RECURSE SOURCES src/*.cc)
include_directories("src")
评论
learning::
src/learning
metric::
add_executable()
src/main.cc
include_directories(src)
add_executable()
include_directories()