VS 自动链接到在 Windows 上使用 vcpkg 安装的 SDL2 库 [英] VS auto-linking against SDL2 libraries installed with vcpkg on Windows
问题描述
据我所知,这不是现有问题的重复.这个问题专门针对 Visual Studio 的自动链接 SDL2 库.
我已经使用 vcpkgx64-windows 变体)>:
I've installed SDL2 (x64-windows
variant) with vcpkg:
vcpkg install sdl2 --triplet x64-windows
我已经为 Visual Studio 提供了 vpkg 库:
And I've made vpkg libraries available to Visual Studio:
vcpkg integrate install
我的 VS 2019 项目配置为使用 Console
子系统,我的主程序如下所示:
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*[])
{
}
为什么我需要指定SDL_MAIN_HANDLED
?与 SDLmain2.lib
的自动链接似乎由于某种原因没有发生?
Why do I need to specify SDL_MAIN_HANDLED
? It seems that auto-linking with SDLmain2.lib
doesn't happen for some reason?
如果我不指定SDL_MAIN_HANDLED
,链接将失败:
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)
我也尝试在 main()
声明中添加 extern "C"
但无济于事.
I've also tried adding extern "C"
on main()
declaration but to no avail.
我用 SDL2 编写了很多应用程序,但这是我第一次使用 vcpkg 来定位它.
I've written many apps with SDL2 but this is the first time I'm using vcpkg to locate it.
推荐答案
这似乎是创建包的人深思熟虑的决定.
It appears to be a deliberate decision made by those who created the package.
如果你查看包描述文件,您可以看到 SDL2main.lib
正在移动到 manual-link
目录中.我不熟悉 vcpkg
,所以我不知道您究竟如何手动链接"?反对,但我认为这是可能的.
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.
这篇关于VS 自动链接到在 Windows 上使用 vcpkg 安装的 SDL2 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!