2017-08-08 36 views
0

我試圖讓SDL工作。我目前在我的電腦上安裝了Microsoft Visual Studio,我試圖運行這個簡單的代碼。SDL在Visual Studio中無法正常工作

#include "SDL.h" 
int main(int argc, char* argv) { 
SDL_Init(SDL_INIT_EVERYTHING); 
SDL_Quit(); 
return 0; 
} 

使用這種方法,我得到一個奇異的錯誤消息:

LNK1561 entry point must be defined 
+0

奇怪的空項目模板開始。 LNK1561通常意味着'main'丟失。確保您選擇了一個應用程序項目,而不是將構建DLL的項目類型。 – user4581301

+0

您可以編輯您正在使用的Windows,Visual Studio和SDL版本?您是否抓住了[預構建的SDL開發二進制文件](https://www.libsdl.org/download-2.0.php),還是您自己創建了?你在爲32位或64位構建你的程序嗎? – genpfault

+1

Visual Studio Express 2017,Windows 10,Windows'SDL-devel-2.05-VC.zip'這有幫助嗎? –

回答

2
int main(int argc, char* argv) 
        ^not quite right... 

the docs爲SDL2的魔法main宏:

/** 
* \file SDL_main.h 
* 
* The application's main() function must be called with C linkage, 
* and should be declared like this: 
* \code 
* #ifdef __cplusplus 
* extern "C" 
* #endif 
* int main(int argc, char *argv[]) 
* { 
* } 
* \endcode 
*/ 

#if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE) 
#define main SDL_main 
#endif 

/** 
* The prototype for the application's main() function 
*/ 
extern C_LINKAGE int SDL_main(int argc, char *argv[]); 

所以,你想改變

int main(int argc, char** argv) 

int main(int argc, char* argv[]) 

既然你從你可能還需要選擇一個/SUBSYSTEM: usually CONSOLE or WINDOWS

+0

@EyesightTechnology:是的,要麼'main()'應該工作。 – genpfault

+0

@EyesightTechnology:你*鏈接到'SDLmain.lib',對吧? – genpfault

+0

@gempfault:是的,我有。但我對此很新,而且我可能做得不正確。你會如何建議我做鏈接? (你如何正確使用它?) –

相關問題