Visual Studio Static Linking for Standalone Exe

Visual Studio Static Linking for Standalone Exe

本文关键字:Standalone Exe for Linking Studio Static Visual      更新时间:2023-10-16

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

在我的发布配置 (x64( 中,我有以下内容:

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(。

构建项目并自己运行 exe 后,我收到错误"代码执行无法继续,因为找不到 glfw3.dll...">等。

使用依赖沃克,我可以看到它需要与库关联的 dll,它当然找不到。

我是否误解了如何做到这一点,或者还有其他可能出错的地方?

(我正在使用Visual Studio 2017(

是的,看来你有一个轻微的误解。

如果某些内容作为 DLL 提供,则它应该用作 DLL。 可能有某种方法可以将DLL合并到可执行文件中,但这将是一个黑客。 这不是事情应该如何运作的。

您链接的lib 文件的存在只是为了向您提供可以链接的函数,而这些函数除了委托给动态加载的 DLL 中的相应函数外,什么也不做。 没有它,您必须自己找到DLL的每个入口点,这是完全可行的,但有点麻烦。

所以:你必须找到一个打包为静态可链接库的glfw3版本(我不知道是否存在(,或者接受你的.exe需要与glfw3.dll一起发布的事实。