VS auto-linking against SDL2 libraries installed with vcpkg on Windows

北慕城南 提交于 2021-01-29 07:31:29

问题


To the best of my knowledge, this isn't a duplicate of an existing question. This question is specifically about Visual Studio's auto-linking SDL2 libraries.

I've installed SDL2 (x64-windows variant) with vcpkg:

vcpkg install sdl2 --triplet x64-windows

And I've made vpkg libraries available to Visual Studio:

vcpkg integrate install

My VS 2019 project is configured to use the Console subsystem, and my main program looks like that:

#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>

int main(int, char*[])
{
}

Why do I need to specify SDL_MAIN_HANDLED? It seems that auto-linking with SDLmain2.lib doesn't happen for some reason?

If I don't specify SDL_MAIN_HANDLED, linking fails:

unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

I've also tried adding extern "C" on main() declaration but to no avail.

I've written many apps with SDL2 but this is the first time I'm using vcpkg to locate it.


回答1:


It appears to be a deliberate decision made by those who created the package.

If you look at the package description file, you can see that SDL2main.lib is being moved into the manual-link directory. I'm not familiar with vcpkg, so I don't know how exactly you can "manually link" against it, but I assume it's possible.



来源:https://stackoverflow.com/questions/64079180/vs-auto-linking-against-sdl2-libraries-installed-with-vcpkg-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!