![](/img/trans.png)
[英]Using SDL2 with SDL2_image on OSX 10.11 (CMake 3.3 within CLion 1.1)
[英]SDL2 and CMake on OS X 10.11
我知道有一些答案(例如here , here或here ),但我無法使其正常工作:
考慮一個MWE main.cpp
// depending on the source of the example,
// one of the two includes is used
//#include <SDL2/SDL.h>
#include "SDL.h"
int main() {
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Quit SDL
SDL_Quit();
return 0;
}
我在OS X 10.11上下載了 SDL2 v2.0.4,並將SDL2.framework文件復制到了/ Library / Frameworks文件夾中。
現在,我試圖找到一個有效的CMake腳本來編譯main.cpp 。
首先我嘗試
find_package(SDL)
add_executable(example main.cpp)
target_include_directories(example ${SDL_INCLUDE_DIR})
target_link_libraries(example ${SDL_LIBRARY})
但是我收到錯誤消息
Could NOT find SDL (missing: SDL_LIBRARY) (found version "2.0.4")
CMake Error at CMakeLists.txt:3 (target_include_directories):
target_include_directories called with invalid arguments
如果我在cmake子目錄中包含FindSDL2.cmake並使用腳本
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
add_executable(example main.cpp)
CMake的作品,但我得到一個鏈接器錯誤:
Undefined symbols for architecture x86_64:
"_SDL_Init", referenced from:
_main in main.cpp.o
"_SDL_Quit", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
您是否知道我的問題是什么以及如何以這種方式正確使用SDL2?
您需要為目標添加target_link_libraries(YOUR_TARGET ${SDL2_LIBRARY})
-它不針對sdl進行鏈接。
如果運行make VERBOSE=1
,則可以看到實際的鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.