我试图在我的mac上编译一个cmake项目,但它依赖于SDL框架。我安装了这个框架,在cmake向我报告之后,没有找到libSDL,我自己设置了以下导出变量(如cmake所建议的):
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;
}发布于 2011-11-16 10:38:50
我通过删除.framework并将导出变量取消到这个框架来解决这个问题,并且我使用这个源代码来./configure、make、make。我删除了所有的cmake构建文件和cmake,并再次完成了我的项目,一切都解决了。
(要在on上编译SDL,您需要./configure --disable-assembly)
发布于 2011-11-15 17:13:11
正如Ramon所说,许多平台都需要链接到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
https://stackoverflow.com/questions/8136857
复制相似问题