使用find_package查找SDL2时出现奇怪的错误

时间:2016-10-07 10:40:27

标签: c++ cmake sdl-2 mingw-w64 msys

我目前正在尝试为我的应用程序创建一个基于CMake的构建系统,该系统使用SDL2作为其图形输出。 但是当使用MSYS为Mingw32-w64构建时,我收到了非常奇怪的错误消息。

考虑以下示例项目。它使用findSDL2.cmake找到here on github。 (main.cxx只是一个空的main函数和一个#include <SDL2.h>

# Version requirement and project info
cmake_minimum_required(VERSION 3.1.3)
project(app)

# Try to find libsdl2
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
find_package(SDL2 REQUIRED)

message(STATUS "Include directory: " ${SDL2_INCLUDE_DIR})
message(STATUS "Libraries: " ${SDL2_LIBRARY})

# Define target as executable
add_executable(app main.cxx)

# Include own include files
target_include_directories(app PUBLIC ${SDL2_INCLUDE_DIR})

# Link to libraries
target_link_libraries(app  ${SDL2_LIBRARY})

# Require support for at least C++14.
set_property(TARGET app PROPERTY CXX_STANDARD 14)
set_property(TARGET app PROPERTY CXX_STANDARD_REQUIRED ON)

在我的测试系统上,使用MSYS构建Mingw64,安装了SDL2:

katharina@k-pc MINGW64 /d/app
$ pkg-config --cflags sdl2
-Dmain=SDL_main -I/mingw64/include/SDL2

手动构建项目也可以正常工作:

Katharina@k-pc MINGW64 /d/app
$ clang++ -I/mingw64/include/SDL2 -lmingw32 -lSDL2main -lSDL2 main.cxx              
Katharina@k-pc MINGW64 /d/app
$

但是当使用CMake项目创建makefile时,会出现一个奇怪的错误:

Katharina@k-pc MINGW64 /d/app/build
$ cmake "MSYS Makefiles" ./..
-- The C compiler identification is Clang 3.8.0
-- The CXX compiler identification is Clang 3.8.0
/* ... */
-- Found SDL2: mingw32;/mingw64/lib/libSDL2main.a;/mingw64/lib/libSDL2.a

/* My debug output. Note that all paths are correct! */
-- Include directory: /mingw64/include/SDL2
-- Libraries: mingw32/mingw64/lib/libSDL2main.a/mingw64/lib/libSDL2.a
/*   */

-- Configuring done
-- Generating done
-- Build files have been written to: /d/app/build

Katharina@k-pc MINGW64 /d/app/build
$ make -j
Scanning dependencies of target app
make[2]: *** No rule to make target '/mingw64/include/SDL2/SDL.h', needed by 'CMakeFiles/app.dir/main.cxx.obj'.  Stop.
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/app.dir/all' failed
make[1]: *** [CMakeFiles/app.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Katharina@k-pc MINGW64 /d/app/build
$

CMake实际上能够找到我用于手动编译的完全相同的编译器标志! 那么,这里有什么问题?我的项目文件中有错误吗?这看起来很奇怪!

0 个答案:

没有答案