Chr*_*ert 5 c++ linker visual-c++
我正在尝试使用测试 C++ OpenGL/SDL 项目设置名为 Waf 的构建系统,但在链接过程中遇到了一些问题。据我所知,所有库都已正确找到,并添加到链接命令中,但链接过程似乎就像库未链接一样。
为了尝试调试该过程,我尝试手动运行编译/链接过程,以便准确了解它如何与 MSVC 配合使用,但我仍然遇到问题。当我运行以下 LINK.exe 命令时:
PS C:\Users\covertcj\Documents\projects\test> & "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\BIN\amd64\LINK.exe"
/NOLOGO /MANIFEST /SUBSYSTEM:CONSOLE /MACHINE:x64 /VERBOSE
.\build\src\main.cpp.1.o
/OUT:.\build\test.exe
/LIBPATH:C:\Users\covertcj\Documents\projects\test\lib /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib" /LIBPATH:"C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x64"
opengl32.lib sdl.lib sdlmain.lib
Run Code Online (Sandbox Code Playgroud)
我得到和平常一样的错误:
main.cpp.1.o : error LNK2019: unresolved external symbol SDL_CreateWindow referenced in function SDL_main
main.cpp.1.o : error LNK2019: unresolved external symbol SDL_DestroyWindow referenced in function SDL_main
main.cpp.1.o : error LNK2019: unresolved external symbol SDL_GL_CreateContext referenced in function SDL_main
main.cpp.1.o : error LNK2019: unresolved external symbol SDL_GL_SwapWindow referenced in function SDL_main
main.cpp.1.o : error LNK2019: unresolved external symbol SDL_GL_DeleteContext referenced in function SDL_main
main.cpp.1.o : error LNK2019: unresolved external symbol SDL_PollEvent referenced in function SDL_main
main.cpp.1.o : error LNK2019: unresolved external symbol SDL_Delay referenced in function SDL_main
main.cpp.1.o : error LNK2019: unresolved external symbol SDL_Init referenced in function SDL_main
main.cpp.1.o : error LNK2019: unresolved external symbol SDL_Quit referenced in function SDL_main
LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup
Run Code Online (Sandbox Code Playgroud)
然而,我也得到了一些有趣的详细输出:
Searching libraries
Searching C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x64\opengl32.lib:
Searching C:\Users\covertcj\Documents\projects\dungeonhg\lib\sdl.lib:
Searching C:\Users\covertcj\Documents\projects\dungeonhg\lib\sdlmain.lib:
Searching C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64\LIBCMT.lib:
Found _load_config_used
Loaded LIBCMT.lib(loadcfg.obj)
Searching C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64\OLDNAMES.lib:
Searching C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x64\kernel32.lib:
Finished searching libraries
Unused libraries:
C:\Users\covertcj\Documents\projects\dungeonhg\lib\sdl.lib
C:\Users\covertcj\Documents\projects\dungeonhg\lib\sdlmain.lib
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64\OLDNAMES.lib
Run Code Online (Sandbox Code Playgroud)
但是,我的代码肯定使用 SDL 和 SDLmain:
主程序
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
int main(int argc, char *argv[]) {
SDL_Init(SDL_INIT_VIDEO); // Init SDL2
// Create a window. Window mode MUST include SDL_WINDOW_OPENGL for use with OpenGL.
SDL_Window *window = SDL_CreateWindow(
"SDL2/OpenGL Demo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE
);
...
Run Code Online (Sandbox Code Playgroud)
有人知道我在这里做错了什么吗?
编辑:我还验证了相同的 waf 脚本可以在 linux 和 osx 上运行,所以它似乎是 Windows 特定的。
我认为你的主要问题是
error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup
Run Code Online (Sandbox Code Playgroud)
这可能是影响其他一切的一个错误。如果我不得不猜测,我必须假设您忘记添加“主要”功能......尽管显然您没有,因为我可以在您的帖子中清楚地看到它。
| 归档时间: |
|
| 查看次数: |
7093 次 |
| 最近记录: |