SDL在vc6下的编译
1,复制sdl.dll动态链接文件至你的工程目录文件下,如debug或release下.
2,在VC工具目录下面找到选项,设置其include和lib目录为其你所下载的相关目录;
3,在工程的设置中,找到link,在对象/库模块中添加sdl.lib及sdlmain.lib
4,在工程的设置中,找到c/c++中,设置Use run_time library为multithread dll
5,还有一点非常重要的是:在建立工程的时候,一般建立基于win32或win控制台项目时,最后设置为空项目,然后自己添加源文件.不要使用mfc等.
6,一般我们从main函数开始,但是里面一定要有参数,例如int main(int argc,char **argv);
摘录两则出错的错误及解决的办法:
1,问:I am using MS Visual C++ 6.0 Standard Edition for this game I'm working on. It's going to be done in 2D with SDL. When I try to compile, it says:
Linking...
msvcrt.lib(MSVCRT.dll) : error LNK2005: _exit already defined in LIBCD.lib(crt0dat.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strncpy already defined in LIBCD.lib(strncpy.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _fclose already defined in LIBCD.lib(fclose.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: __isctype already defined in LIBCD.lib(isctype.obj)
LIBCD.lib(crt0init.obj) : warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/M TQB_2D.exe : fatal error LNK1169: one or more multiply defined symbols found
I tried to do /NODEFAULTLIB:library, but it doesn't do anything, or does /NODEFAULTLIB:library mean /NODEFAULTLIBRARY:msvcrt.lib?
答:Hit alt + F7. Go to code generation (I think it's under the linker tab, but I am not sure and running Linux now, so I can't fire it up and check), and set the built to multithreaded DLL. It should fix the problem.
2,问The source code:
#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif
#i nclude "SDL.h"
#i nclude <stdio.h>
int main()
{
printf("Initializing SDL.\n");
/* Initialize defaults, Video and Audio */
if(SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
printf("Could not initialize SDL: %s.\n", SDL_GetError());
SDL_Quit();
}
printf("SDL initialized.\n");
printf("Quiting SDL.\n");
/* Shutdown all subsystems */
SDL_Quit();
printf("Quiting....\n");
return(0);
}
'SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_main'
'Debug/test.exe : fatal error LNK1120: 1 unresolved externals'
these are error display under vc6.0
but the programme can run under linux.
when i chang 'int main()' to 'int main(int argc, char **argv)',that is ok under vc6.0
what is the problem?
The source code:
#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif
#i nclude "SDL.h"
#i nclude <stdio.h>
int main()
{
printf("Initializing SDL.\n");
/* Initialize defaults, Video and Audio */
if(SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
printf("Could not initialize SDL: %s.\n", SDL_GetError());
SDL_Quit();
}
printf("SDL initialized.\n");
printf("Quiting SDL.\n");
/* Shutdown all subsystems */
SDL_Quit();
printf("Quiting....\n");
return(0);
}
'SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_main'
'Debug/test.exe : fatal error LNK1120: 1 unresolved externals'
these are error display under vc6.0
but the programme can run under linux.
答:when i chang 'int main()' to 'int main(int argc, char **argv)',that is ok under vc6.0
what is the problem?