-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
移除对 SDL2main 库的链接 #53
Conversation
On MSVC v141+: ``` SDL2main.lib(SDL_windows_main.obj) : error LNK2005: _main already defined in main.obj MSVCRTD.lib(initializers.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library LINK : warning LNK4217: symbol '_fprintf' defined in 'mp3Editor.obj' is imported by 'SDL2main.lib(SDL_windows_main.obj)' in function '_ShowError' SDL2main.lib(SDL_windows_main.obj) : error LNK2019: unresolved external symbol _SDL_main referenced in function _main SDL2main.lib(SDL_windows_main.obj) : error LNK2019: unresolved external symbol __imp____iob_func referenced in function _ShowError debug\Beslyric-for-X.exe : fatal error LNK1120: 2 unresolved externals ```
e68c645
to
4f19144
Compare
对于 Windows 上的 Qt 开发,这个 PR 所做的修改并不完整,做出的解释也是有问题的,所以在此重新说明。 另外, SDL 2.0.3 过于陈旧,我将参考 2.0.14 (此时最新的发行版)的代码。
|
在使用 MSVC v141 及以上版本时,链接报错:
分析后得出:Beslyric-for-X (以下简称 B4X )使用
SDL_Init(Uint32 flags)
方法初始化 SDL ,同时也不在入口int main(int argc, char* argv[])
初始化 SDL ,不需要SDL_main
的相关功能。如果 B4X 引入
SDL_main
,简略地说,有三件事情要发生:SDL_MAIN_HANDLED
是否存在,如果没有,就定义宏SDL_MAIN_NEEDED
或宏SDL_MAIN_AVAILABLE
(根据平台类型);SDL_MAIN_NEEDED
或宏SDL_MAIN_AVAILABLE
存在,则使用宏定义#define main SDL_main
将 B4X 的入口重命名为int SDL_main(int argc, char *argv[])
;int main(int argc, char* argv[])
,待 SDL 初始化后,再调用int SDL_main(int argc, char* argv[])
启动 B4X 。源码:
#define main SDL_main
:https://github.com/spurious/SDL-mirror/blob/release-2.0.3/include/SDL_main.h#L94-L96
int main(int argc, char* argv[])
的原型:https://github.com/spurious/SDL-mirror/blob/release-2.0.3/src/main/dummy/SDL_dummy_main.c#L11-L15
int main(int argc, char* argv[])
:https://github.com/spurious/SDL-mirror/blob/release-2.0.3/src/main/windows/SDL_windows_main.c#L131-L147
参考:
本 PR 在 Ubuntu 18.04 、 Windows 7 / 10 、 macOS 10.14 / 10.15 测试通过。