2
我已阅读并尝试了几乎所有的教程/维基/ SO后,页面片断我能找到让这个CMake的工作....cmake的简单子目录不包括文件
我有一个超级简单目录结构:
ROOT/
|- CMakeLists.txt
|- main.cpp
|- sub/
|-CMakeLists.txt
|-subx/
|-CMakeLists.txt
|-subx.h
|-subx.cpp
|-suby/
|-CMakeLists.txt
|-suby.h
|-suby.cpp
的main.cpp中是一个超级简单的CPP项目:
//omitting all unnecessary code
int main() {
subx s;
s.defined_method();
s.another_defined_method(1);
return 0;
}
你可以假设,每个人的缘故,该SUBX和suby定义是正确的,工作得很好,因为他们当我手工编译时做。
当我通过CMake的编译,我得到以下错误:
"/path/to/cmake" --build /path/to/Debug --target CS220_Project -- -j 4
Linking CXX executable simple_project
Undefined symbols for architecture x86_64:
"subx::defined_method()", referenced from:
_main in main.cpp.o
"subx::another_defined_method(int)", 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)
make[3]: *** [simple_project] Error 1
make[2]: *** [CMakeFiles/simple_project.dir/all] Error 2
make[1]: *** [CMakeFiles/simple_project.dir/rule] Error 2
make: *** [simple_project] Error 2
根的CMakeLists.txt文件如下:
cmake_minimum_required(VERSION 2.8.4)
project(simple_project)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_subdirectory(sub)
add_executable(simple_project ${SOURCE_FILES})
子的CMakeLists.txt文件如下:
add_subdirectory(subx)
add_subdirectory(suby)
subx & suby CMakeLists.txt文件看起来:(它们包括它们各自的区别)
set(SUBX_SOURCES subx.cpp)
#Add any files in this directory
add_executable(SUBX ${SUBX_SOURCES})
我已经试过之类的东西add_library,文件(水珠)等,我不能,我的生活得到了在任何子目录与main.cpp中程序编译的文件。
你是先生,是神派。谢谢。 – lilott8 2014-10-16 22:42:27