使用库和CMake有问题

Having issues with using libraries and CMake

本文关键字:CMake 有问题      更新时间:2023-10-16
C:Program Files (x86)JetBrainsCLion 1.0.1bincmakebincmake.exe" --build C:UsersAnthony.clion10systemcmakegeneratedd04e461ad04e461aDebug --target all -- -j 8
-- Configuring incomplete, errors occurred!
CMake Error at CMakeLists.txt:19 (add_library):
See also "C:/Users/Anthony/.clion10/system/cmake/generated/d04e461a/d04e461a/Debug/CMakeFiles/CMakeOutput.log".
  add_library cannot create target "Majick" because another target with the
  same name already exists.  The existing target is an executable created in
  source directory "C:/Users/Anthony/ClionProjects/Majick".  See
  documentation for policy CMP0002 for more details.
Makefile:163: recipe for target 'cmake_check_build_system' failed
mingw32-make.exe: *** [cmake_check_build_system] Error 1

我做这件事有很多问题,是我的错。我一点也不明白。我想,习惯了方便的链接已经害死了我。这是我有的。

cmake_minimum_required(VERSION 3.2)
project(Majick)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(OpenGL REQUIRED)
#add_subdirectory(C:/Users/Anthony/ClionProjects/glfw Majick/glfw)
#add_subdirectory(C:/Users/Anthony/ClionProjects/glm Majick/glm)
#add_subdirectory(C:/Users/Anthony/ClionProjects/glew Majick/glew)
set(SOURCE_FILES main.cpp)
add_executable(Majick ${SOURCE_FILES})
include_directories(${OPENGL_INCLUDE_DIRS} ${GLFW_INCLUDE_DIRS} ${GLM_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS})
link_directories(C:/Users/Anthony/ClionProjects/glew/lib/Release/x64 C:/Users/Anthony/ClionProjects/glfw/lib-mingw)
target_link_libraries(Majick ${OPENGL_LIBRARIES} ${GLFW_LIBRARIES} ${GLEW_LIBRARIES} glfw3 glew32s opengl32)
add_library(Majick STATIC)
这让我觉得自己很蠢,但我不知道发生了什么。我花了五个小时左右的时间在谷歌上搜索,但一无所获。有没有人介意帮我解决我的问题,也许提供一些地方,我可以得到更多的信息在CMake?

错误信息非常清楚:有两个具有相同名称的目标,这在CMake中是不可能的。

add_executable(Majick ${SOURCE_FILES})
...
add_library(Majick STATIC)

我想第二个目标应该被删除了