Reputation: 293
I created a project using freeglut and glew and am attempting to statically link them. Currently when I build the project, I get an exe and two dlls(freeglut32.dll and glew32.dll). I'd like to make it so that I only get the exe.
To install the libraries I used NuGet. (Install-Package freeglut) and (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. I assume they are the .lib files I wanted because they are both over 1 MB.
In Visual Studio, I went to Linker -> Input -> Additional Dependencies and added the paths of freeglut.lib and glew.lib. I also added #define GLEW_STATIC
and #define FREEGLUT_STATIC
to my code. 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. How can I make sure it so that glew32.dll and freeglut.dll do not exist and I am just given the single executable?
Edit: Due to suggestions: I went to Properties -> Referenced Packages and set freeglut and glew to Static.
Upvotes: 4
Views: 2925
Reputation: 5156
You need to build static libraries for glew and freeglut that are compatible with your project settings
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. Later vcpkg will use these settings as the default or intrinsic values.
Step 2) Open PowerShell in administrative mode and go the vcpkg directory
Step 3) Type .\vcpkg install glew:x64-windows-static
This tells the packager to build a static library of the project for x64 machine. Repeat for 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.
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
.\vcpkg integrate install
Many open source windows projects can be auto build using this tool, enjoy.
Upvotes: 3