我正在尝试建立一个简单的项目,以便可以学习一些OpenGL。这是我的CmakeList.txt:
cmake_minimum_required (VERSION 3.8)
project ("opengl_1")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
find_package(OpenGL REQUIRED)
if (OpenGL_FOUND)
include_directories(${OPENGL_INCLUDE_DIR})
endif()
find_package(GLFW REQUIRED)
if (GLFW_FOUND)
include_directories(${GLFW_INCLUDE_DIR})
endif()
file(GLOB_RECURSE SRC "src/*")
file(GLOB_RECURSE INCLUDES "include/*")
include_directories("include")
# Add source to this project's executable.
add_executable (opengl1 ${SRC} ${INCLUDES})
target_link_libraries(opengl1 ${OPENGL_LIBRARIES} ${GLFW_LIBRARIES})
由于在Windows上生成编译命令文件的问题,我放弃了Visual Studio 2017的Visual Studio代码。它需要忍者生成器,我在使用cmake时遇到了很多麻烦。
现在,我cd
在我的项目目录中,然后执行cmake .
:
-- Building for: Visual Studio 15 2017
-- The C compiler identification is MSVC 19.14.26431.0
-- The CXX compiler identification is MSVC 19.14.26431.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenGL: opengl32
-- Found GLFW: C:/libraries/glfw/include (found version "3.2.1")
-- Configuring done
-- Generating done
-- Build files have been written to: ...
在任何地方都没有提到忍者生成器。但是,当我在VS2017中打开解决方案并使用“生成”更新intellisense时,我得到:
1> Does not match the generator used previously: Visual Studio 15 2017
1> Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.
CMake Error: Error: generator : Ninja
Does not match the generator used previously: Visual Studio 15 2017
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.
当我删除这些东西时,错误仍然出现。
这是怎么回事?如果我仍然需要忍者,有人可以告诉我我需要做什么吗?
谢谢!
答案 0 :(得分:0)
因此,我将回答我自己的问题,因为这需要立即进行一系列奇怪的事情才能使该错误发生。
Cmake Project
选项制作的Cmake文件,我怀疑这是在后台使用了Ninja 作为(3)的结果,代码完成不再按预期工作。要纠正这种情况:
cmake .
这应该默认为正常的MSBUILD例程并解决问题。当我从非VS命令提示符下生成构建文件时,以某种方式cmake -G Ninja .
在后台 even 中运行。 VS命令提示符对其进行了修复。
希望这对某人有帮助。这让我感到困惑。