简体   繁体   English

Visual Studio静态链接(freeglut,glew)

[英]Visual Studio Static Link (freeglut, glew)

I created a project using freeglut and glew and am attempting to statically link them. 我使用freeglut和glew创建了一个项目,并尝试静态链接它们。 Currently when I build the project, I get an exe and two dlls(freeglut32.dll and glew32.dll). 目前,当我构建项目时,我得到一个exe和两个dll(freeglut32.dll和glew32.dll)。 I'd like to make it so that I only get the exe. 我想这样做,以便我只得到exe。

To install the libraries I used NuGet. 要安装我使用NuGet的库。 (Install-Package freeglut) and (Install-Package glew). (Install-package freeglut)和(Install-Package glew)。 NuGet downloads glew.lib to .\\packages\\glew.1.9.0.1\\build\\native\\lib\\v110\\x64\\Release\\static\\glew.lib and freeglut to .\\packages\\freeglut.2.8.1.15\\build\\native\\lib\\v110\\x64\\Release\\static\\freeglut.lib. NuGet将glew.lib下载到。\\ packages \\ glew.1.9.0.1 \\ build \\ native \\ lib \\ v110 \\ x64 \\ Release \\ static \\ glew.lib和freeglut to。\\ packages \\ freeglut.2.8.1.15 \\ build \\ native \\ LIB \\ V110 \\ 64 \\发布\\静\\ freeglut.lib。 I assume they are the .lib files I wanted because they are both over 1 MB. 我假设它们是我想要的.lib文件,因为它们都超过1 MB。

In Visual Studio, I went to Linker -> Input -> Additional Dependencies and added the paths of freeglut.lib and glew.lib. 在Visual Studio中,我转到了Linker - > Input - > Additional Dependencies并添加了freeglut.lib和glew.lib的路径。 I also added #define GLEW_STATIC and #define FREEGLUT_STATIC to my code. 我还在代码中添加了#define GLEW_STATIC#define FREEGLUT_STATIC Link Library Dependencies is turned on. 链接库依赖关系已打开。

Even still, building the project gives me my 654 KB exe along with 224 kb of freeglut.dll and 356 kb of glew32.dll. 即便如此,构建项目还是给了我654 KB的exe以及224 kb的freeglut.dll和356 kb的glew32.dll。 How can I make sure it so that glew32.dll and freeglut.dll do not exist and I am just given the single executable? 我怎样才能确保它不存在glew32.dll和freeglut.dll并且我只给出了单个可执行文件?

Edit: Due to suggestions: I went to Properties -> Referenced Packages and set freeglut and glew to Static. 编辑:由于建议:我去了属性 - >引用包并设置freeglut和glew为静态。

You need to build static libraries for glew and freeglut that are compatible with your project settings 您需要为glew和freeglut构建与您的项目设置兼容的静态库

Step 1) Download and build vcpkg.exe ( a open source auto packaging tools from Microsoft) and make sure to keep built settings similar to your current project. 步骤1)下载并构建vcpkg.exe(Microsoft的开源自动打包工具),并确保保持与当前项目类似的构建设置。 Later vcpkg will use these settings as the default or intrinsic values. 以后vcpkg将使用这些设置作为默认值或内在值。

Step 2) Open PowerShell in administrative mode and go the vcpkg directory 步骤2)在管理模式下打开PowerShell并转到vcpkg目录

Step 3) Type .\\vcpkg install glew:x64-windows-static This tells the packager to build a static library of the project for x64 machine. 步骤3)输入.\\vcpkg install glew:x64-windows-static这告诉包装程序为x64机器构建项目的静态库。 Repeat for freeglut. 重复freeglut。 Your static libraries are ready for manual linking. 您的静态库已准备好进行手动链接。 Under the vcpkg\\ installed\\x64-windows-static\\ , you can find subdirectories viz lib ( your lib are here), and include directory contains your glew include files. 在vcpkg \\ installed \\ x64-windows-static \\下,您可以找到子目录viz lib(您的lib在这里),include目录包含您的glew包含文件。

Step 4) [Optional] If you want to auto link the installed packages to your visual studio C++ projects (available in VS 2015 or later only), type 步骤4)[可选]如果要将已安装的软件包自动链接到Visual Studio C ++项目(仅在VS 2015或更高版本中可用),请键入

.\vcpkg integrate install

Many open source windows projects can be auto build using this tool, enjoy. 许多开源窗口项目都可以使用这个工具自动构建,享受。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM