我试图在CLION上将SDLmain与CMakeLists联系起来 OpenGL,GLEW和GLUT已成功链接,但SDLmain存在问题。
的CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(Mario)
set(GL_ROOT /System/Library/Frameworks/OpenGL.framework)
set(GL_INC ${GL_ROOT}/Headers)
set(GL_LIB ${GL_ROOT}/Libraries/libGL.dylib)
set(GLEW_VER 1.13.0)
set(GLEW_ROOT /usr/local/Cellar/glew/${GLEW_VER})
set(GLEW_INC ${GLEW_ROOT}/include/GL)
set(GLEW_LIB ${GLEW_ROOT}/lib/libGLEW.dylib)
set(GLUT_VER 2.8.1)
set(GLUT_ROOT /usr/local/Cellar/freeglut/${GLUT_VER})
set(GLUT_INC ${GLUT_ROOT}/include/GL)
set(GLUT_LIB ${GLUT_ROOT}/lib/libGLUT.dylib)
set(SDL_VER 1.2.15)
set(SDL_ROOT /usr/local/Cellar/sdl/${SDL_VER})
set(SDL_INC ${SDL_ROOT}/include/SDL)
set(SDL_LIB ${SDL_ROOT}/lib/libSDL.dylib)
set(SDL_IMG_VER 1.2.12_2)
set(SDL_IMG_ROOT /usr/local/Cellar/sdl_image/${SDL_IMG_VER})
set(SDL_IMG_INC ${SDL_IMG_ROOT}/include/SDL)
set(SDL_IMG_LIB ${SDL_IMG_ROOT}/lib/libSDL_image.dylib)
set(SDL_MAIN ${SDL_ROOT}/lib/libSDLmain.a)
include_directories(${GL_INC} ${GLEW_INC} ${GLUT_INC} ${SDL_INC} ${SDL_IMG_INC})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -v")
set(SOURCE_FILES main.cpp ${SDL_MAIN} mario.cpp game.cpp game.h textures.cpp textures.h)
add_executable(Mario ${SOURCE_FILES})
target_link_libraries(Mario ${GL_LIB} ${GLEW_LIB} ${GLUT_LIB} ${SDL_LIB} ${SDL_IMG_LIB} ${SDL_MAIN})
输出:
Apple LLVM version 7.3.0 (clang-703.0.29)
Target: x86_64-apple-darwin15.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.11.0 -o Mario -search_paths_first -headerpad_max_install_names CMakeFiles/Mario.dir/main.cpp.o CMakeFiles/Mario.dir/mario.cpp.o CMakeFiles/Mario.dir/game.cpp.o CMakeFiles/Mario.dir/textures.cpp.o /System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib /usr/local/Cellar/glew/1.13.0/lib/libGLEW.dylib /usr/local/Cellar/freeglut/2.8.1/lib/libGLUT.dylib /usr/local/Cellar/sdl/1.2.15/lib/libSDL.dylib /usr/local/Cellar/sdl_image/1.2.12_2/lib/libSDL_image.dylib /usr/local/Cellar/sdl/1.2.15/lib/libSDLmain.a -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_CFBundleCopyBundleURL", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_CFBundleGetInfoDictionary", referenced from:
_main in libSDLmain.a(SDLMain.o)
"_CFBundleGetMainBundle", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
_main in libSDLmain.a(SDLMain.o)
"_CFRelease", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_CFURLCreateCopyDeletingLastPathComponent", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_CFURLGetFileSystemRepresentation", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_CPSEnableForegroundOperation", referenced from:
_main in libSDLmain.a(SDLMain.o)
"_CPSGetCurrentProcess", referenced from:
_main in libSDLmain.a(SDLMain.o)
"_CPSSetFrontProcess", referenced from:
_main in libSDLmain.a(SDLMain.o)
"_NSAllocateMemoryPages", referenced from:
-[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
"_NSApp", referenced from:
_main in libSDLmain.a(SDLMain.o)
"_NSDeallocateMemoryPages", referenced from:
-[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSApplication", referenced from:
l_OBJC_$_CATEGORY_NSApplication_$_SDLApplication in libSDLmain.a(SDLMain.o)
objc-class-ref in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSAutoreleasePool", referenced from:
objc-class-ref in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSMenu", referenced from:
objc-class-ref in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSMenuItem", referenced from:
objc-class-ref in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSObject", referenced from:
_OBJC_CLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSProcessInfo", referenced from:
objc-class-ref in libSDLmain.a(SDLMain.o)
"_OBJC_CLASS_$_NSString", referenced from:
l_OBJC_$_CATEGORY_NSString_$_ReplaceSubString in libSDLmain.a(SDLMain.o)
objc-class-ref in libSDLmain.a(SDLMain.o)
"_OBJC_METACLASS_$_NSObject", referenced from:
_OBJC_METACLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
"___CFConstantStringClassReference", referenced from:
CFString in libSDLmain.a(SDLMain.o)
CFString in libSDLmain.a(SDLMain.o)
CFString in libSDLmain.a(SDLMain.o)
CFString in libSDLmain.a(SDLMain.o)
CFString in libSDLmain.a(SDLMain.o)
CFString in libSDLmain.a(SDLMain.o)
CFString in libSDLmain.a(SDLMain.o)
...
"__objc_empty_cache", referenced from:
_OBJC_METACLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
_OBJC_CLASS_$_SDLMain in libSDLmain.a(SDLMain.o)
"_objc_msgSend", referenced from:
-[SDLMain application:openFile:] in libSDLmain.a(SDLMain.o)
-[SDLMain applicationDidFinishLaunching:] in libSDLmain.a(SDLMain.o)
-[NSString(ReplaceSubString) stringByReplacingRange:with:] in libSDLmain.a(SDLMain.o)
_main in libSDLmain.a(SDLMain.o)
ld: symbol(s) not found for architecture x86_64
GLEW,GLUT,SDL已安装 brew
我错过了什么吗?
答案 0 :(得分:1)
将-framework Cocoa
添加到CMAKE_CXX_FLAGS
。
答案 1 :(得分:0)
不要手动设置变量<div style="text-align:center;">
<img src="https://gsamaras.files.wordpress.com/2016/04/satou.jpg" style="height:100%;" alt="satou" />
Match for the newborn son of Marialena Satou, 3/4/2016. Wish him health! :)
</div>
,SDL_VER
,SDL_INC
。使用SDL_LIB
。如果这不能自动找到SDL,请使用find_package(SDL)
将SDL_ROOT
传递给CMake,但对于brew安装的软件包,CMake可以找到它们。
FindSDL的文档:https://cmake.org/cmake/help/v3.5/module/FindSDL.html
GLEW和GLUT相同。