用cygwin" make [2]:***没有规则可以制作目标' cygwin' "

时间:2014-04-10 20:51:09

标签: c++ gcc makefile cmake cygwin

在尝试使用Windows上的cmake在cygwin中编译项目时,我得到了完全无法谷歌的错误。

有问题的CMakeLists.txt文件是:

# Minimum cmake version (required)
cmake_minimum_required( VERSION 2.8.4 )

# Project name
project( sdlinterface )

# Find SDL2
include( FindPkgConfig )
pkg_search_module( SDL2 REQUIRED sdl2 )

set (PROJECT_INCLUDE_DIR 
    ${SDL2_INCLUDE_DIRS}    # SDL headers
    ${PROJECT_SOURCE_DIR}/include
)   

set (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)

set(PROJECT_SRCS 
    ${PROJECT_SOURCE_DIR}/SDLMain.cpp
    ${PROJECT_SOURCE_DIR}/SDLWindow.cpp
    ${PROJECT_SOURCE_DIR}/SDLEventLoop.cpp
)

# Set the compiler flags (specifically the c++11 one)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

include_directories("${PROJECT_BINARY_DIR}")
include_directories("${PROJECT_INCLUDE_DIR}")

add_library(${PROJECT_NAME} SHARED ${PROJECT_SRCS})
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)

# Link project with SDL
target_link_libraries(${PROJECT_NAME} 
    SDL2
)

为什么在我打电话时会想到编译一个cygwin目标?

完整的错误消息是

$ make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/xxxx/Projects/sdlgame/Source/build
make[2]: *** No rule to make target 'cygwin', needed by 'cygsdlinterface.dll'.  Stop.
CMakeFiles/Makefile2:170: recipe for target 'Libraries/LEngine/sdlinterface/build/CMakeFiles/sdlinterface.dir/all' failed
make[1]: *** [Libraries/LEngine/sdlinterface/build/CMakeFiles/sdlinterface.dir/all] Error 2
Makefile:75: recipe for target 'all' failed
make: *** [all] Error 2

1 个答案:

答案 0 :(得分:2)

也许不是解决方案,但至少有一些想法

  1. 使用“Unix Makefiles”生成器(可能你这样做)
  2. 在初始化之前使用PROJECT_SOURCE_DIR(PROJECT_INCLUDE_DIR)
  3. 您添加到ADD_LIBRARY的文件可能与$ {CMAKE_CURRENT_SOURCE_DIR}路径相关,因此您无需明确指定
  4. 而不是include( FindPkgConfig )您可以使用find_package(PkgConfig)
  5. 使用${SDL2_LIBRARIES}${SDL2_LDFLAGS}代替target_link_libraries(... SDL2)