c++ - MSVC : Using link. 手动执行

标签 c++ visual-c++ linker

我正在尝试使用测试 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

我得到了和往常一样的错误:

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:

主要.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 上都有效,所以它似乎是特定于 windows 的。

最佳答案

我认为你的主要问题是

error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup

这可能是影响其他一切的一个错误。如果我不得不猜测,我将不得不假设您忘记添加一个“主要”功能......虽然显然您没有,因为我可以在您的帖子中清楚地看到它。

关于c++ - MSVC : Using link. 手动执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12125613/

相关文章:

c++ - 通过常量迭代器从 STL 容器中删除

visual-studio - 使用 gcc 在 Cygwin 中编译库 (redland) 并使用 Visual Studio (c++) 中的输出

c++ - 仅在 Xcode C++ 项目中 Release模式下的链接器错误

c++ - 使用 ArrayFire 库

c++ - 即使安装了可再发行组件,MSCVP120D.dll 仍然丢失?

c++ - 初始化 SSL 和 libcurl 并获取 "out of memory"

c++ - const 正确性警告 c++

c# - 使用 C++ 包装器时如何访问 C# .dll 属性

visual-c++ - 如何在 VC++ 中的另一个测试项目中使用来自一个测试项目的类?

C++ 新类型初始化