SDL2和CMake在OS X 10.11上运行
SDL2 and CMake on OS X 10.11
我知道有一些答案(例如这里、这里或这里),但我无法让它发挥作用:
考虑MWEmain.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
如果我将FindSDL2.cmake包含在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
,您可以看到实际的链接。
相关文章:
- Mac os x app bundle 在下载并运行时崩溃,但在终端或更改 Info.plist 时运行良好
- Homebrew OS X OpenCV - 在另一台Mac上运行时寻找dylib
- 我无法在C++(Clion,Mac OS)中运行Gurobi
- C++代码编译,但在 Zorin OS 上运行时显示错误
- 在 Mac OS 上运行 x11
- 为什么在Windows和Mac OS中运行UnionFind时存在广泛的运行时变化?
- 运行Mac OS X C 程序与OpenGL 3.3一起工作
- 在OS Ubuntu中运行GDB时,如何导出阀门值为文本文件
- C 类文件未在Linux OS上运行的Eclipse Mars中构建二进制文件
- 如何通过C 在Mac OS中运行外部程序
- 为什么当我键入名称时我的可执行文件不会运行?(Mac OS X Mountain Lion)Mac OS X 10.8.
- QT/C++,OS X:退出应用程序时可选择隐藏(),以便应用程序继续运行,并在单击dock中的图标后再次显示
- Simplecrypt让我的QT应用程序在OS X Mountain Lion上崩溃,但在Windows上完美运行
- 如何将运行 OS/X El Capitan 的 Mac 上的 clang 升级到 LLVM 3.8
- 非常简单的C++代码在Android上崩溃,但在OS X上运行良好
- SDL2和CMake在OS X 10.11上运行
- 无法在Xcode版本4.3.2的Mac OS X Lion 10.7.5上运行Matlab Mex文件
- C++:在Mac OS X,Qt 5.0上运行代码(在Linux中创建)
- Cocos 2dx游戏无法在Mac OS 64位上运行,但在iOS模拟器上运行
- 使用 clang 和 Visual Studio 2013 运行时从 OS X 交叉编译到 Windows