MSVC:手动使用link.exe [英] MSVC: Using link.exe manually

查看:1403
本文介绍了MSVC:手动使用link.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一个测试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文件(x86)\Microsoft Visual Studio 11.0 \VC\lib/ LIBPATH:C:\Program文件(x86)\Windows Kits\8.0\Lib\win8\um\x64
opengl32.lib sdl.lib sdlmain.lib

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

  main.cpp.1.o:error LNK2019:未解析的外部符号SDL_CreateWindow在函数SDL_main中引用
main.cpp .1.o:error LNK2019:未解析的外部符号SDL_DestroyWindow在函数SDL_main中引用
main.cpp.1.o:错误LNK2019:未解析的外部符号SDL_GL_CreateContext在函数SDL_main中引用
main.cpp.1.o :error LNK2019:未解析的外部符号SDL_GL_SwapWindow在函数SDL_main中引用
main.cpp.1.o:error LNK2019:未解析的外部符号SDL_GL_DeleteContext在函数SDL_main中引用
main.cpp.1.o:error LNK2019:未解析的外部符号SDL_PollEvent在函数SDL_main中引用
main.cpp.1.o:error LNK2019:未解析的外部符号SDL_Delay在函数SDL_main中引用
main.cpp.1.o:error LNK2019:未解析的外部符号SDL_Init在函数SDL_main中引用
main.cpp.1.o:error LNK2019:未解析的外部符号SDL_Quit在函数SDL_main中引用
LIBCMT.lib(crt0.obj):error LNK2019:未解析的外部符号然而,我还得到了一些有趣的详细输出:


$ b $ p






$ b

 搜索库
搜索C:\Program文件(x86)\Windows Kits\8.0\Lib\win8\um\x64\\ \\opengl32.lib:
搜索C:\Users\covertcj\Documents\projects\dungeonhg\lib\sdl.lib:
搜索C:\Users\covertcj\\ \\Documents\projects\dungeonhg\lib\sdlmain.lib:
搜索C:\Program文件(x86)\ Microsoft Visual Studio 11.0 \VC\lib \amd64\LIBCMT。 lib:
发现_load_config_used
加载LIBCMT.lib(loadcfg.obj)
搜索C:\Program文件(x86)\Microsoft Visual Studio 11.0 \VC\lib\amd64 \OLDNAMES.lib:
搜索C:\Program文件(x86)\Windows Kits\8.0\Lib\win8\um\x64\kernel32.lib:

完成搜索库

未使用的库:
C:\Users\covertcj\Documents\projects\dungeonhg\lib\sdl.lib
C:\Users\covertcj\Documents\projects\dungeonhg\lib\sdlmain.lib
C:\Program文件(x86)\Microsoft Visual Studio 11.0 \VC\lib \amd64\OLDNAMES.lib

但是,我的代码绝对使用SDL和SDLmain: p>

main.cpp

  #include< SDL2 / SDL.h> 
#include< SDL2 / SDL_opengl.h>

int main(int argc,char * argv []){

SDL_Init(SDL_INIT_VIDEO); // Init SDL2

//创建一个窗口。窗口模式必须包含用于OpenGL的SDL_WINDOW_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特定的。

解决方案

我认为你的主要问题是

 错误LNK2019:unresolved外部符号主要在函数__tmainCRTStartup 
中引用

这可能是一切错误。如果我不得不猜测,我会假设你忘了添加一个主功能...虽然显然你没有,因为我可以清楚地看到你的发布。


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.

解决方案

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.

这篇关于MSVC:手动使用link.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆