6
嗨我想編譯一個只有一個主要功能的項目,但CMake發現更多。cmake發現多個主要功能
我的CMake的是這樣的:
cmake_minimum_required(VERSION 2.8)
project(my_proj)
include_directories(".")
add_subdirectory(main)
add_subdirectory(resources)
find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED COMPONENTS system regex program_options)
include_directories(${Boost_INCLUDE_DIRS})
file(GLOB_RECURSE SRC_FILES ${PROJECT_SOURCE_DIR}/*.cpp)
file(GLOB_RECURSE HDR_FILES ${PROJECT_SOURCE_DIR}/*.hpp)
add_executable(my_proj ${SRC_FILES} ${HDR_FILES})
target_link_libraries(my_proj ${OpenCV_LIBS})
target_link_libraries(my_proj ${OpenCV_LIBS}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${Boost_REGEX_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY})
我有.HPP和.cpp文件多個文件夾,這就是爲什麼我添加file(GLOB_RECURSE...
報表,也include_directories(".")
。
我得到一個錯誤,它編譯,指出所有文件後:
CMakeFiles/my_proj.dir/CMakeFiles/CompilerIdCXX/CMakeCXXCompilerId.cpp.o: In function `main':
/media/N/my_proj/build/CMakeFiles/CompilerIdCXX/CMakeCXXCompilerId.cpp:209: multiple definition of `main'
CMakeFiles/my_proj.dir/main.cpp.o:/media/N/my_proj/main.cpp:10: first defined here
CMakeFiles/my_proj.dir/main/solution2/sources/CRunSolution2.cpp.o: In function `boost::filesystem3::path::codecvt()':
/usr/include/boost/filesystem/v3/path.hpp:377: undefined reference to `boost::filesystem3::path::wchar_t_codecvt_facet()'
有沒有人遇到這樣的事情?如果是的話,如何解決它?
+1「列表中選擇源文件和頭文件在你的CMakeLists.txt直接」 – iankits
所以你建議我通過添加的文件有?像'add_executable(my_proj main.cpp dir1/sources/cls1.cpp ... dir1/headers/cls1.hpp ...)'而不是'file(GLOB_RESCUE ...)''? –
是的,您可以通過SET(src_files file1.cpp ...)創建一個變量並使用該變量 – Peter