compiled program cannot find freeglut.dll
Asked Answered
B

2

7

I'm new to this site, and relatively new to programming. I've been doing some C++ programming for a while using Visual Studio 2010, and I wanted to get into OpenGL, so I bought the OpenGL Superbible to get started. I've gotten stuck on the second chapter's "simple" project. After hours of research I've been able to download all the necessary files to use freeGLUT and GLtools. I've made sure that everything is in the right place for the program to work. Now, it appears as though everything has been worked out... except for one odd problem.

I was instructed that I needed to place freeglut.dll into Windows\System32, so I did. The project will build now, but when I go to run it, it tells me

"The program can't start because freeglut.dll is missing from your computer. Try reinstalling the program to fix this problem."

Now, I am certain that freeglut.dll is in Windows\System32 as it should be, so what's the problem? how do I solve it?

Here's the original code from the book:

#include "../../shared/gltools.h"  //OpenGL toolkit

//////////////////////////////////////////////
//called to draw scene

void RenderScene(void)
{
    // clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT);

 //Flush drawing commands
    glFlush();
}
////////////////////////////////////////////////////////
//set up the rendering state
void SetupRC(void)
{
    glClearColor(0.0f , 0.0f, 1.0f, 1.0f );
}
///////////////////////////////////////////////////////////
//main program entry point
void main(void)
int main(int argc, char* argv[])
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
    glutCreateWindow("Simple");
    glutDisplayFunc(RenderScene);

    SetupRC();
    glutMainLoop();
    return 0;
    }

This is the code that actually compiled, but would not run (it's a bit of a mess from all the conflicting data I got from different resources):

 #include <stdio.h>
 #include <stdlib.h>
 #include <windows.h>
 #include <GLTools.h>
 #include <gl/GLUT.h>
 //called to draw scene

 void RenderScene(void)
 {
// clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);

glFlush();
 }

 //set up the rendering state
 void SetupRC(void)
 {
glClearColor(0.0f , 0.0f, 1.0f, 1.0f );
 }

 //void main(void)
 int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);

SetupRC();
glutMainLoop();
return 0;
}
Bascule answered 29/5, 2013 at 21:52 Comment(1)
Have you tried just to see if it will work at all by placing the dll in the same folder as the exe?Patience
C
14

Try putting the DLL in the same folder as your exe file. The advice to put it in Windows\System32 predates a lot of newer Windows security restrictions.

Csc answered 29/5, 2013 at 21:56 Comment(0)
G
12

@ScottMcP-MVP 's answer solved my problem, but I thought I'd add some detail that doesn't really fit in the comment.

My solution:

  1. Add the following subdirectory structure to your solution folder:

enter image description here

In x86, put the 32-bit versions of GLut, GLew and anything else you need.

In x64, put the 64-bit versions of same.

I went ahead and put all .dll, .lib, and .h in the corresponding folders here rather than placing them in the Windows SDK (Or, in Win7+, the "Windows Kits" folder) to ensure that my projects in SVN had the correct version, and checking out on another machine would retrieve all dependencies. This required adding the include and target-specific lib folders to the project properties:

enter image description here

Set your Include Directories field to

$(SolutionDir)ThirdParty\Include\;$(IncludePath)

And your Library Directories field to

$(SolutionDir)\ThirdParty\$(PlatformTarget)\lib\;$(LibraryPath)

Note that all of these should be applied to the "All Platforms" build configuration. The $(PlatformTarget) macro will make sure that the correct lib's and dll's are used. The include folder is target-agnostic, so I've placed it in the root of my ThirdParty folder.

To get the required files into your output folder, add the following post-build event to your project configuration (under "All platforms"):

xcopy $(SolutionDir)ThirdParty\$(PlatformTarget)\*.dll $(OutputPath) /Y

enter image description here

That will copy the correct version of the DLLs to your output folder on build. This keeps you from having to manually put the DLLs in our output folder, and is more compatible with source control where you typically don't want to include your output, bin or debug folders.

Once I had all of this configured, I created a VC OpenGL project template since getting everything configured took 30 minutes of my life I'd rather have back.

Gizela answered 28/9, 2013 at 20:55 Comment(3)
You didn't get nearly enough recognition for this answer. Kudos to you.Cleek
Thanks for the solution. Spent about 1 hour looking for a solution then I found this, works perfectly in VS2017.Lowestoft
@Lowestoft responses like yours make it worthwhile. Glad I could help.Gizela

© 2022 - 2024 — McMap. All rights reserved.