2017-02-01 4 views
1

그래서 CLOL과 함께 작동하도록 SDL2를 얻으려고합니다 (실험/학습 할 수 있도록).OS X에서 CLION과 함께 SDL2 사용

#include <iostream> 
#include <SDL.h> 

const int SCREEN_WIDTH = 640; 
const int SCREEN_HEIGHT = 480; 

bool init(); 

SDL_Window* gWindow = NULL; 

SDL_Surface* gScreenSurface = NULL; 

SDL_Surface* gHelloWorld = NULL; 

bool init(){ 
    bool success = true; 
    /*if(SDL_Init(SDL_INIT_VIDEO)<0){ 
     success = false; 
    } 
    else{ 
    }*/ 

    return success; 
} 

int main() { 
    std::cout << "Hello, World!" << std::endl; 
    return 0; 
} 

그리고 내 CMake 파일 I 프로젝트 내의 폴더 cmake에 here에서 파일 FindSDL2.cmake을 가지고, 또한이

cmake_minimum_required(VERSION 3.6) 
project(SDL2_Lesson_1) 

set(CMAKE_CXX_STANDARD 11) 

# includes cmake/FindSDL2.cmake 
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) 

find_package(SDL2 REQUIRED) 
include_directories(${SDL2_INCLUDE_DIR}) 

set(SOURCE_FILES Lesson_1.cpp) 

add_executable(SDL2_App ${SOURCE_FILES}) 
target_link_libraries(SDL2_App ${SDL2_LIBRARY}) 

set(SOURCE_FILES Lesson_1.cpp) 
add_executable(SDL2_Lesson_1 ${SOURCE_FILES}) 

과 같습니다

내 주요 코드는 다음과 같은 것입니다 폴더. 이제 파일을 게시하면 모든 것이 컴파일되고 제대로 실행됩니다. 내가 초기화() 내에서 주석 부분의 주석을 때, 컴파일이 고장 나에게 다음과 같은 오류 제공 :

Undefined symbols for architecture x86_64: 
    "_SDL_Init", referenced from: 
     init() in Lesson_1.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) 
make[3]: *** [SDL2_Lesson_1] Error 1 
make[2]: *** [CMakeFiles/SDL2_Lesson_1.dir/all] Error 2 
make[1]: *** [CMakeFiles/SDL2_Lesson_1.dir/rule] Error 2 
make: *** [SDL2_Lesson_1] Error 2 

참고 : Lesson_1.cpp 메인 코드 파일입니다. 또한 이는 오류의 일부일뿐입니다. 보조 노트로

+0

, 당신은 쉽게 사용하여 자원을 관리하는 찾을 수 있습니다 [RAII (http://stackoverflow.com/questions/2321511/) 그래서 돈 수동으로 무엇이 초기화되어 있는지 확인하고, 예외를 처리 할 때 클린업을 명시 적으로 처리해야합니다. RAII [매우 쉽게] (http://stackoverflow.com/questions/39176805/) 용 SDL과 같은 C 스타일 인터페이스를 래핑 할 수 있으며 문제 해결을 위해 리소스 누출이 적습니다. – jaggedSpire

+0

얼마나 더 많은 오류가 있습니까? 합리적으로 나머지 부분을 게시 할 수 있습니까? – jaggedSpire

+0

@jaggedSpire 물론, 나머지 오류는 게시했습니다. –

답변

0

사용 find_library() 대신 find_package()

find_library(SDL2_LIBRARY SDL2 "path/to/your/library_bundle") 
find_library(SDL2_App ${SDL2_LIBRARY}) 
+0

답변보다는 댓글에 더 가깝습니다. – usr1234567