有使用库和CMake的问题

时间:2015-06-06 18:53:14

标签: c++ cmake

C:\Program Files (x86)\JetBrains\CLion 1.0.1\bin\cmake\bin\cmake.exe" --build C:\Users\Anthony\.clion10\system\cmake\generated\d04e461a\d04e461a\Debug --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的更多信息?

1 个答案:

答案 0 :(得分:0)

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

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

我想第二个目标只需要删除。