VS2005下SDL的编译链接问题
来源:互联网 发布:淘宝摄影服务 编辑:程序博客网 时间:2024/04/27 17:59
http://blog.csdn.net/whygosofar/article/details/4548259
当下载SDL for win32 搭建好编译环境后,建立个win32 控制台 编译SDL 中Demo-- loopave.c程序,有如下link erro:
1>Compiling...
1>loopwave.c
1>Linking...
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>../bin/sdlSample1.exe : fatal error LNK1120: 1 unresolved externals
win32控制台程序的入口函数为main _main 或_tmain. subsystem 已经选择为为win32 console了,所以应该不会出现
启动函数中 _main链接失败的状况。
究其原因是因为SDL有自己的入口函数SDL_main,,,也查看过loopwave.obj发现里面确实没有main _main 而是有SDL_main
_SDL_main,这说明,demo 中的main函数名已被改动了,具体在哪里被改的,应该是在你包含#include "SDL_config.h"中。
查实了下:
在SDL_main.h有下列说明
#define main SDL_main --->我们的main函数名就这边被改变了。
/* The prototype for the application's main() function */
extern C_LINKAGE int SDL_main(int argc, char *argv[]);
由于没有导出main _main在进行链接 当然出现 unresolved external symbol _main.
解决措施1:
很简单,告诉链接器,我们程序的入口函数名 已经改变了,在项目属性里,Linker-->Advanced-->Entry Point 填写SDL_main。这样
___tmainCRTStartup 就会调用入口函数SDL_main
解决措施2:
既然SDL在编译时会改变main函数的名称为SDL_main,,我们可以自己改变main函数名称为其它的名称,如main_t等,然后在项目属性里,Linker-->Advanced-->Entry Point 填写main_t等,这样
___tmainCRTStartup 就会调用入口函数main_t,使用SDL也不会有问题的。
此外当使用gcc编译器,编译SDL程序,也要注意这一点,,我们也需要告诉链接器,入口函数不是main 而是 SDL_main。
链接时只需要加个 _Dmain = SDL_main 即可.
下面是别人的解释,感觉有点问题。
"Compiling program, which uses SDL must be done this way:
g++ -o helloworld -Dmain=SDL_main helloworld.cpp -lmingw32 -lSDLmain -lSDL
That is because SDL uses its own main function,
which sets up some stuff for it,
and users main function must be named SDL_main
(which this -D... directive does - renames it automatically)."
- VS2005下SDL的编译链接问题
- VS2005下SDL的编译链接问题
- Visual C++ 2008下,SDL的编译链接问题!
- winxp下sdl程序的编译链接
- SDL在MACOS下的编译
- SDL在vc6下的编译
- Android下ffmpeg、SDL的编译
- win7下VS2005编译chrome所遇到的问题!!
- Windows下编译SDL
- Windows下编译SDL
- 编译SDL问题
- SDL编译安装问题
- 代码从VS2003升级到VS2005的编译链接问题及解决方法
- sdl编译问题 sdl printf没有输出 sdl编译错误
- windows下SDL使用ndk-build编译失败问题
- 编译链接的问题
- VC下编译和链接常出现的问题汇总
- VC下编译和链接常出现的问题汇总
- WINCE TOC解析
- 基于 Android NDK 的学习之旅-----数据传输(引用数据类型)
- ExtJS4中GridPanel组件简单例子
- TOMCAT内存溢出及大小调整
- oracle中substr函数的用法
- VS2005下SDL的编译链接问题
- uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
- LINUX USB 系统(1)
- solr查询不使用query analyzer中文分词的问题解决
- 嵌入式开发资料集锦
- MinSdkVersion, targetSdkVersion, target API level的区别
- 产生时间字符串组
- 六、矩阵按键(4*4)
- TCP/IP详解学习笔记(1)-基本概念