MSVC:手动使用LINK.EXE(MSVC: Using link.exe manually)

2019-09-21 16:45发布

我试图建立一个名为WAF与测试C ++的OpenGL / SDL的项目构建系统,并正在运行与链接过程中的几个问题。 据我所知,所有的库都被正确地发现,并添加到链接命令,但该链接过程似乎是充当如果库没有链接。

为了尝试调试过程中,我试图以了解它是如何工作与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

我得到同样的错误像往常一样:

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

不过,我也得到了一些有趣的详细输出:

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

然而,我的代码最肯定使用SDL和SDLmain:

main.cpp中

#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
  );

...

任何人都知道我在做什么错在这里?

编辑:我也验证了同样的WAF脚本适用于Linux和OSX,所以它似乎是特定的窗口。

Answer 1:

我认为你的主要问题是

error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup

这可能是一个错误的一切铰链。 如果我猜的话,我会假设你忘了添加一个“主”的功能......虽然表面上你没有,我可以清楚地看到它在你的帖子。



文章来源: MSVC: Using link.exe manually