【发布时间】:2017-04-13 19:39:52
【问题描述】:
我一直在尝试遵循供应商的教程: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".
我们将不胜感激。
【问题讨论】: