独立Studio的Visual Studio静态链接 [英] Visual Studio Static Linking for Standalone Exe

查看:217
本文介绍了独立Studio的Visual Studio静态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关该主题的多篇文章,但没有一篇文章使我能够构建一个静态链接的exe.

I've read multiple posts with regards to this topic, but none of them have enabled me to build a statically linked exe.

在我的版本配置(x64)中,我具有以下内容:

In my release configuration (x64) I have the following:

Configuration Properties -> General : Use of MFC - Use MFC in a Static Library

Configuration Properties -> C/C++ -> Code Generation : Runtime Library - Multi-threaded (/MT)

Configuration Properties -> Linker -> Command Line : Additional Options - I have all the required Windows libs "kernel32.lib", etc. (as use of MFC removed them from the "All Options" window above)

Configuration Properties -> Manifest Tool -> Input and Output : Embed Manifest - No

请注意,在Configuration Properties -> Linker -> Input中,我在项目中使用了5个lib文件,例如glfw3.lib,而我正在使用完全优化(/Ox).

Note that in Configuration Properties -> Linker -> Input there are 5 lib files that I'm using in my project, eg glfw3.lib and I'm using Full optimisation (/Ox).

构建项目并自己运行exe后,我收到错误消息由于找不到glfw3.dll,代码执行无法继续..." 等.

After building the project and running the exe myself I receive errors "The code execution cannot proceed because glfw3.dll was not found..." etc.

使用dependencywalker,我可以看到它需要与库相关联的dll,而它当然找不到.

Using dependencywalker I can see that it needs the dlls associated with the libs, which it of course cannot find.

我误解了如何执行此操作,还是还有其他可能出错的地方?

Am I misunderstanding how to do this or is there something else that might be wrong?

(我正在使用Visual Studio 2017)

(I'm using Visual Studio 2017)

推荐答案

是的,看来您有点误会.

Yes, it appears you have a slight misunderstanding.

如果将某些东西作为DLL提供,则意味着它被用作DLL.可能有一些方法可以将DLL合并到可执行文件中,但这将是一种hack.那不是应该的事情.

If something is offered as a DLL, then it is meant to be used as a DLL. There may be some way to incorporate a DLL into an executable, but it would be a hack. That's not how things are supposed to work.

您要链接的lib文件仅是为了向您提供可以链接的功能而存在,这些功能除了委托给动态加载的DLL中的相应功能外,什么也没有做.没有它,您将不得不自己定位DLL的每个入口点,这是完全可行的,但是有点麻烦.

The lib file that you are linking against exists simply in order to provide you with functions that you can link against, and these do nothing but delegate to the corresponding functions in the dynamically loaded DLL. Without it you would have to locate each entrypoint of the DLL yourself, which would be perfectly doable, but a bit cumbersome.

所以:您必须找到打包为静态可链接库的glfw3版本(我不知道是否存在),或者必须将自己的.exe与glfw3.dll一起提供.

So: you must either find a version of glfw3 which is packaged as a statically linkable library (I have no idea whether one exists) or live with the fact that your .exe will need to be shipped together with glfw3.dll.

这篇关于独立Studio的Visual Studio静态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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