c – CMake找不到源文件(add_executable)
发布时间:2020-12-16 10:13:58 所属栏目:百科 来源:网络整理
导读:我一直在尝试按照供应商的教程: CMake-Tutorial,查看文档: Cmake-Documentation,尽可能使用YouTube上的资源进行自我教育,但我真的很难为使用OpenGL设置环境.在使用了Glitter样板和open.gl和learnopengl.com上的教程时,我已经决定了解构建过程太重要了,不需
我一直在尝试按照供应商的教程:
CMake-Tutorial,查看文档:
Cmake-Documentation,尽可能使用YouTube上的资源进行自我教育,但我真的很难为使用OpenGL设置环境.在使用了Glitter样板和open.gl和learnopengl.com上的教程时,我已经决定了解构建过程太重要了,不需要调查.
在我的调查中,我遇到了CMake错误“找不到源文件”,下面会更详细地显示.问题似乎来自“add_executable”. 这里提出了一个类似的问题:CMake – Cannot find file.解决方案涉及确保为每个变量正确设置${PROJECT_SOURCE_DIR},我相信我已经完成了. 我的文件结构: + infuriating_project + bin // post compile results + src // my humble code + deps // external code +glew + include + src +glfw + include + src +glm +soil + lib + src 我的CMakeLists.txt: cmake_minimum_required (VERSION 3.0) # Version Information --------------------------------------------------------- project (openGL-practice) SET (VERSION_MAJOR 1) SET (VERSION_MINOR 0) SET (VERSION_FEATURE 0) SET (VERSION_PATCH 0) SET (VERSION "${VERSION_MAJOR}.${VERSION_MINOR}") SET (VERSION "${VERSION}.${VERSION_FEATURE}.${VERSION_PATCH}") MESSAGE ("Version: ${VERSION}") # Configure Source & Binary Directories --------------------------------------- SET (PROJECT_ROOT "${PROJECT_SOURCE_DIR}") SET (PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src") SET (PROJECT_BINARY_DIR "${PROJECT_BINARY_DIR}/bin") MESSAGE ("Source path: ${PROJECT_SOURCE_DIR}") MESSAGE ("Binary path: ${PROJECT_BINARY_DIR}") # Configure Depenency Directories --------------------------------------------- SET (PROJECT_DEPS "${PROJECT_ROOT}/deps") SET (glew_inc "${PROJECT_DEPS}/glew/include/GL/") SET (glew_src "${PROJECT_DEPS}/glew/src/") SET (glfw_inc "${PROJECT_DEPS}/glfw/include/GLFW/") SET (glfw_src "${PROJECT_DEPS}/glfw/src/") SET (glm "${PROJECT_DEPS}/glm/glm/") SET (soil_lib "${PROJECT_DEPS}/lib/") SET (soil_src "${PROJECT_DEPS}/src/") # Include directories --------------------------------------------------------- include_directories(" ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR} ${glew_inc} ${glew_src} ${glfw_inc} ${glfw_src} ${glm} ${soil_lib} ${soil_src} ${PROJECT_ROOT} ") # Add executable -------------------------------------------------------------- add_executable(main main.cpp) 提供以下错误: CMake Error at CMakeLists.txt:46 (add_executable): Cannot find source file: main.cpp Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error: CMake can not determine linker language for target: main CMake Error: Cannot determine link language for target "main". 任何和所有的帮助将非常感谢. 解决方法
我想提一点.
> include_directories有助于查找头文件.源文件必须始终具有完整的相对路径. 假设你的main.cpp在src中,正确的语法是 add_executable(main ${PROJECT_SOURCE_DIR}/main.cpp) >包括${PROJECT_BINARY_DIR}没有意义. 希望能帮助到你. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |