c - 如何使用介子构建 sdl2?

标签 c sdl sdl-2 meson-build

使用这个介子文件,

project('mytest', 'c')
cc = meson.get_compiler('c')

deps = []
deps += dependency('sdl2',
  required: true,
  static: true,
  method: 'pkg-config')


executable('demo', 
           'src/main.c', 
           dependencies : deps,
           gui_app: true)

我收到以下错误

 error LNK2019: unresolved external symbol WinMain referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

这似乎与 SDLmain.lib 有关(我确信它存在)。
您将如何强制链接器链接到该库?

我使用的是 Windows 10,使用 MSVC 编译器。

最佳答案

您正在构建一个 GUI 应用程序,而不是一个终端应用程序。使用 MSVC,当您设置 gui_app : true (或在更新版本的 meson win_subsystem : 'windows' 中)时,您不提供 main 函数,您可以提供 WinMain 函数来代替。

See the MSDN documentation

在底层,此选项将 /SUBSYSTEM:WINDOWS 传递给编译器

关于c - 如何使用介子构建 sdl2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69783286/

相关文章:

c++ - 尝试使用 C++ 使纹理在 OpenGL 中工作时访问冲突

c++ - 为什么 OpenGL 着色器无法正确编译?

c++ - TTF_RenderText_Solid() 崩溃游戏和 Visual Studio [c++][sdl ttf]

C pthreads 和信号

c - 我是否必须对 SQLITE 中的 argv 回调中的每个参数进行深度复制?

opengl - 尝试使用 SDL + GLEW 时出现段错误

c++ - 为什么 SDL 在 Mac 上比 Linux 上慢很多?

c++ - 如何在 Windows 上修复 cmake find_package "Could NOT find SDL2"?

c - 由于指针 (C),流水线理念不起作用

c - 尝试复制共享内存地址时出现段错误