2011-11-15 246 views
2

我想在我的Mac上編譯一個cmake項目,但它取決於SDL框架。我安裝這個框架之後的cmake然後向我報告libSDL沒有找到我設置以下導出變量自己(由CMake的的建議):libSDL,CMake和Mac OS X Lion

export SDL_INCLUDE_DIR=/Library/Frameworks/SDL.framework/ 
export SDLIMAGE_LIBRARY=/Library/Frameworks/SDL_image.framework/ 
export SDLIMAGE_INCLUDE_DIR=/Library/Frameworks/SDL_image.framework/Headers 

現在cmake的做它的工作,但是當我運行make,我得到的以下消息:

Mats-MBP:build mats$ make 
Linking CXX executable SDLExample 
Undefined symbols for architecture i386: 
"_main", referenced from: 
    start in crt1.10.6.o 
    (maybe you meant: _SDL_main) 
ld: symbol(s) not found for architecture i386 
collect2: ld returned 1 exit status 
make[2]: *** [src/SDLExample] Error 1 
make[1]: *** [src/CMakeFiles/SDLExample.dir/all] Error 2 
make: *** [all] Error 2 

我得到這對於i386和x86_64。我忘了什麼?

編輯:這些文件的內容:

Mats-MBP:build mats$ cat ../src/main.cpp 
/** 
* @file main.cpp 
* 
* A simple example-program to help you out with using SDL for 2D graphics. 
* 
* @author przemek 
*/ 

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

using namespace std; 

int main(int argc, char* argv[]) { 
    try { 
     // Try to initialize SDL (for video) 
     if (SDL_Init(SDL_INIT_VIDEO) != 0) { 
      throw runtime_error("Couldn't init SDL video!"); 
     } 
     // Create a double-buffered screen surface: 
     SDL_Surface* screen = SDL_SetVideoMode(800, 600, 24, SDL_DOUBLEBUF/* |  SDL_FULLSCREEN*/); 
     if (!screen) { 
      throw runtime_error("Couldn't set SDL video mode!"); 
     } 

     // Use SDL_image library to load an image: 
     SDL_Surface* image = IMG_Load("image.png"); 
//  SDL_Surface* image = IMG_Load("image.tga"); 
     if (!image) { 
      throw runtime_error(SDL_GetError()); 
     } 

     // "Pump" SDL events like keyboard presses and get the keystate: 
     SDL_PumpEvents(); 
     Uint8* keyState = SDL_GetKeyState(0); 

     // loop until user presses escape: 
     while (!keyState[SDLK_ESCAPE]) { 
      // Display a game background: 
     SDL_Rect src, dst;   // Source and destination rectangles 
     src.x = 0; 
     src.y = 0; 
     src.w = image->w; 
     src.h = image->h; 
     dst.x = 100; 
     dst.y = 50; 
     dst.w = image->w; 
     dst.h = image->h; 
     // Copy the image from 'image' to 'screen' surface 
     SDL_BlitSurface(image, &src, SDL_GetVideoSurface(), &dst); 

     // Flip surfaces (remember: double-buffering!) and clear the back buffer: 
     SDL_Flip(screen); 
     SDL_FillRect(screen, 0, 0); 

     // Get new keyboard state: 
     SDL_PumpEvents(); 
     keyState = SDL_GetKeyState(0); 
    } 

    // Free the screen surface & quit SDL 
    SDL_FreeSurface(screen); 
    SDL_Quit(); 
} catch (runtime_error& e) { 
    cout << e.what() << endl; 
    SDL_Quit(); 
} 

return 0; 
} 
+1

你想建立什麼樣的事情?一個應用程序或命令行工具或其他東西? CMake抱怨缺少一個'main'函數。 –

+0

這是做抱怨,但那是關於同樣的事情。我試圖編譯一個SDL示例程序,所以我想這將是一個命令行工具。 (爲了記錄,我確實有一個主要功能,並且我看不到任何其他主要功能的調用。) – Mats

+0

查看該示例代碼,看看是否定義了任何「主要」功能。如果沒有,創建一個(並確保它分支/跳轉到示例代碼的真正入口點)。 –

回答

1

我解決它通過消除.framework並取消我的出口變量這個框架,我用源的./configure,make,進行安裝。我刪除了所有的cmake構建文件,並重新創建了我的項目,一切都解決了。

(有關OS X Lion中編譯SDL需要./configure --disable-assembly

0

正如雷蒙說,你需要鏈接到SDLmain.lib許多平臺。所以在你的CMakeLists.txt文件中有這樣的東西。

link_libraries (
    ${SDL_LIBRARY} 
    ${SDLIMAGE_LIBRARY} # if using SDL_image, obviously 
    SDLmain # Sadly not included in SDL_LIBRARY variable 
) 

下面是詳細信息的簡單頁面:http://content.gpwiki.org/index.php/SDL:Tutorials:Setup