MSVC: Using link.exe manually

限于喜欢 提交于 2019-12-23 21:05:58

问题


I'm attempting to set up a build system named Waf with a test C++ OpenGL/SDL project, and am running into a few issues with the linking process. As far as I can tell, all of the libraries are being found properly, and being added into the linking command, and yet the linking process seems to be acting as if the libraries aren't linked.

In order to attempt to debug the process, I was trying to run the compilation/link process manually in order to understand exactly how it works with MSVC, but I'm still getting issues. When I run the following LINK.exe command:

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

I get the same error as usual:

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

However, I also get some interesting verbose output:

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

However, my code most definitely uses SDL and 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
  );

...

Anybody know what I'm doing wrong here?

EDIT: I have also verified that the same waf script works on both linux and osx, so it seems to be windows specific.


回答1:


I think your main problem is

error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup

which might be the one error where everything else hinges. If I had to guess, I would have to assume that you forgot to add a "main" function... although apparently you didn't, as I can clearly see it in your posting.



来源:https://stackoverflow.com/questions/12125613/msvc-using-link-exe-manually

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!