天天看點

SDL在vc6下的編譯

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");

    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");

    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");

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");

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?

繼續閱讀