compiled program cannot find freeglut.dll - c++

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;
}

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.

#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:
Add the following subdirectory structure to your solution folder:
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:
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
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.

Related

SDL2_Image is throwing "The procedure entry point inflateReset2 could not be located" whenever i try to initialize SDL2_Image for png images

The file included in the error message is "libpng16-16.dll", I am using SDL2_Image version 2.0.4 with Visual C++ on Windows. No matter what I do, the message stays. i tried swapping out all libpng16-16.dll files with my version i got. I also tried including it into the system32 folder. Nothing works. I can initialize SDL2_Image for other formats, but as soon as i try to initialize it for png, it throws this message. all the time. Found few cases of this happening to others, but their way of fixing it doesn't work for me. at all. i am upset pls help. Here's my current code real quick:
#include "SDL.h"
#include "SDL_image.h"
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
IMG_Init(IMG_INIT_PNG);
SDL_Quit();
return 0;
}

C++ strange "undefined reference"

I'm relatively new to c++, so bear with a little.
I have a class with the constructor:
Window(int width, int height, const std::string& title);
As defined in the header file.
I then have the code:
#include "window.h"
int main(int argc, char** argv) {
new Window(800, 600, "Elysian Engine");
}
in Main.
When building, I am getting the error "undefined reference to 'Window(int, int, std::string const&)'" Which I do not understand, as I thought I am correctly importing it and everything. I understand this to be a linking error, but I'm not sure why.
Thanks!
--- EDIT ---
The code for window.cpp:
#include "window.h"
#include <SDL2/SDL.h>
#include <SDL/SDL.h>
#include <GL/glew.h>
Window::Window(int width, int height, const std::string& title) :
width(width),
height(height),
title(title),
isCloseRequested(false) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
context = SDL_GL_CreateContext(window);
SDL_GL_SetSwapInterval(1);
GLenum res = glewInit();
if (res != GLEW_OK) {
fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
}
}
Window::~Window() {
SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window);
SDL_Quit();
}
Because your code does not appear to be causing the issue, I will address the IDE.
When I first started using Code::Blocks, I ran into the "undefined reference" problem quite a bit. There are multiple ways that I solved this.
Exit Code::Blocks and re-open it. This solved my issues more times than I would care to count. It's similar to finally realizing that an executable is acting strangely because you needed to run make clean before compiling; sometimes, you are compiling an old version of code without realizing it.
Delete window.h and window.cpp from the project and re-add them. This is similar to the solution above. Although this has worked for me before, I couldn't figure out exactly why it worked.
Include the full path of window.h. Instead of #include "window.h", try #include "/path/goes/here/window.h". It is possible that your current location (as specified in your #include statement) is incorrect.
Check the compiler that is selected for the project. When I used Code::Blocks, I typically used gcc. However, there was a case where I was receiving all sorts of errors (upon attempting compilation) that I either did not understand or could not resolve, only to learn that I had accidentally selected some gcc variant from the compiler selection list that I did not even have installed.
Create a new project. Move your source files out of the project folder that is created by Code::Blocks, and then remove that project folder. Launch Code::Blocks, create a new project, and add your source files to the new project.
When all else fails and you absolutely must use Code::Blocks, reinstall the full package. I had to do this my first time using Code::Blocks (which was also my first time using an IDE). I realized that I had a bare-bones installation of the IDE, which was limiting what I could do (including compiling). Naturally, I cannot access the Code::Blocks website right now, otherwise I would offer a link here as well. In this case, I think it is safe to say that the full-featured stable version will be the largest (in MB) you can find on Code::Blocks' Downloads page. After you have reinstalled, create a new project and add your files back to it.
I eventually moved to using writing code in an IDE (for the linting!), and taking care of a makefile on my own. It has been awhile since I've used Code::Blocks, but each of the above bullets represents solutions/work-arounds that have helped me for your specific problem (or, in general) while I was using Code::Blocks.

OpenGL project is requiring DirectX lib files

I have glut version 3.7 installed, running Windows 7 and using VS 2010:
I seem unable to run any C++ programs without it saying it requires Direct X libraries and includes in the VC++ Directories properties tab.
Under propertes>input>additional dependencies it shows dxerr.lib and a few other dx libraries under inherited values which I believe is the cause of this error. How can I remove these values? Unless anyone believes the error originates elsewhere...
#include <stdlib.h>
#include <GL\glut.h>
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(720, 480);
glutCreateWindow("First OpenGL Project");
return 1;
}
Error 1 error LNK1104: cannot open file 'dxerr.lib' c:\Users\mallaboro\documents\visual studio 2010\Projects\First OpenGL Project2\First OpenGL Project2\LINK First OpenGL Project2
Try a maintained GLUT implementation instead of nearly twenty-year-old software.

Undefined reference to 'SDL_main'

I've recently decided to try working with SDL with CodeBlocks 10.05. I started with the tutorial on http://www.sdltutorials.com/sdl-tutorial-basics and did my best to follow it. Unfortunately, I'm encountering:
..\..\..\..\..\..\SDL\SDL-1.2.15\lib\libSDLmain.a(SDL_win32_main.o):SDL_win32_main.c|| undefined reference to `SDL_main'|
when I try to compile it.
I've searched through many of the questions on this website and other tutorials (mainly the tutorial on LazyFoo and the CodeBlocks wiki) and can't seem to find a solution.
C:\SDL\SDL-1.2.15\include has been added in the Compiler tab (Search Directories)
C:\SDL\SDL-1.2.15\lib has been added in the Linker tab
The libraries libmingw32.a, libSDLmain.a, libSDL.dll.a are linked in that order
libmingw32.a from the MinGW\lib folder in the CodeBlocks installation directory
SDL.dll is in both the System32 folder and in the project folder
When attempting to follow the tutorial on the CodeBlocks wiki, I was told that SDL.h could not be found in the given directory (when making a new SDL project).
CApp.cpp
#include "CApp.h"
#include "SDL\SDL.h"
CApp::CApp(){
Surf_Display=NULL;
Running=true;
}
int CApp::OnExecute(){
if (OnInit()==false){
return -1;
}
SDL_Event Event;
while (Running){
while (SDL_PollEvent(&Event)){
OnEvent(&Event);
}
OnLoop();
OnRender();
}
OnCleanup();
return 0;
}
int main(int argc, char* argv[]){
CApp theApp;
return theApp.OnExecute();
}
CApp.h
#ifndef CAPP_H_INCLUDED
#define CAPP_H_INCLUDED
#include "SDL\SDL.h"
class CApp{
private:
bool Running;
SDL_Surface* Surf_Display;
public:
CApp();
int OnExecute();
public:
bool OnInit();
void OnEvent(SDL_Event* Event);
void OnLoop();
void OnRender();
void OnCleanup();
};
#endif // CAPP_H_INCLUDED
put these arguments to the main function. I had this problem too, and I fixed it few seconds ago.
int main(int argv, char** args)
{
}
Try #undef main after all SDL related headers.
Update. This is not a valid solution!
As pointed out by HolyBlackCat, this is a pretty sloppy fix. SDL replaces the main function in order to perform some initialization and/or cleanup that is otherwise not possible, and then calls back to the actual user function.
The interception works by replacing the name of user's main function to SDL_main, with a simple macro
#define main SDL_main
The user's function then ceases to be the entry point for the application, and an entry point provided by SDL is used. The proposed #undef disables the interception recklessly and one should argue that it is not supposed to work at all. For those who successfully compiled and ran an SDL application after this "fix", it must have simply been a platform-dependent coincidence.
The proper solution to the OP's error is making sure that the file containing main gets compiled and linked, and that the function has correct signature. As already posted by others.
The only plausible reason for your problem I can think of is that when you created the file with main in it, you forgot to add it to build targets.
You should see CApp.cpp in the list where my main.cpp is. Right click on it and click Properties. Click on Build tab in the window that pops up. You should see this:
Click OK, hit Ctrl+F11 (Rebuild).
Good luck.
Recently, I had this problem, watched some YouTube videos and also followed the installation guide by LazyFoo and I kept getting the "Undefined reference to SDL_main" error.
I followed everything said here after successfully linking the minGw files to my project properties, but it didn't work until I added to my main function int main (int argv, char** args) and voila, it worked.
using namespace std;
int main(int argv, char** args) { if(SDL_Init(SDL_INIT_VIDEO)<0) {
cout<<"Endl Init Failed."<<endl;
return 1; }
cout<<"SDL Init succeeded."<<endl;
SDL_Quit(); return 0; }
Why it worked is still not clear to me but it worked anyway.
Define SDL_MAIN_HANDLED before you include the SDL libs:
#define SDL_MAIN_HANDLED
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
More info: I'm using the SDL functions without the SDL_main be defined. Is that fine?
This was the first question that pop out to my search.
None of the solutions worked for me.
Eventually I figured it what worked for me. Will post the my answer here to "any fellow wanderer".
My problem was that I tried to compile some old C game not a C++ one.
One part of the solution for me was to rename the main.c to main.cpp
And then to signal to CMake to use CPP compiler for all C files.
Eventually here is a portion of my CMakeLists.txt:
# set minimum cmake version
cmake_minimum_required(VERSION 3.19 FATAL_ERROR)
# project name and language
project(FootballManager LANGUAGES CXX)
# This is mandatory too, because otherwise they are not compiled an linked.
file(GLOB_RECURSE CFILES "${CMAKE_SOURCE_DIR}/*.c")
SET_SOURCE_FILES_PROPERTIES(${CFILES} PROPERTIES LANGUAGE CXX)
# list sources
list(APPEND _sources config.h)
# ... removed some of the other sources for brevity ...
list(APPEND _sources misc.c)
# Link SDL, yes this is SDL1.2
find_package(SDL REQUIRED)
include_directories(FootballManager ${SDL_INCLUDE_DIRS})
add_executable(fm main.cpp ${_sources})
target_link_libraries(fm ${SDL_LIBRARIES})

what SDL and OpenGL version and implementation I'm using

I downloaded SDL 1.2.14
on Windows 7
and I have Mobility Radeon X1800 driver installed.
I'm using Microsoft Visual C++ 2010 Express.
I added the SDL include and library directories in the "VC++ Directories"
I added the following Additional Dependencies:
opengl32.lib;
glu32.lib;
SDL.lib;
SDLmain.lib;
I added the SDL.dll to my program folder
I didn't add any opengl directories!
#include "SDL.h"
#include "SDL_opengl.h"
bool running = true;
int main(int argc, char* args[]) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* screen = SDL_SetVideoMode(640,480,32,SDL_OPENGL);
glViewport(0,0,640,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 640/480, 1.0, 200.0);
while(running) {
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); // Swich to the drawing perspective
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5f, 0.5f, 0.0f);
glVertex3f(-1.0f, 1.5f, 0.0f);
glVertex3f(-1.5f, 0.5f, 0.0f);
glEnd();
SDL_GL_SwapBuffers();
}
SDL_Quit();
return 0;
}
This program draws a simple triangle.
I include 2 header files above and my Opengl code just works!
I don't know if my triangle is done on a the GPU or CPU. And what openGL version I'm using?
I mean i heard that Microsoft don't update there opengl files any longer and that they use CPU implementation of OpenGL 1.1 or something.
How do I know what version of OpenGL I'm using? And can I check at run time?
How do I know if I'm using a CPU or GPU implementation? And can I check at run time?
Thanks for look at my problem.
call glGetString
Here is Microsoft's documentation for glGetString. It just repeats the SGI doc and tells you the function is found in gl.h and opengl32.lib.
Actually when you install your video card driver it "replaces" the opengl existing in your machine, so you will be using that version.
Multiple versions of OpenGL are present at the same time, and which one is used depends on the HDC used to initialize OpenGL. For example, applications running in the local login session can get hardware-accelerated GL while those running in a remote desktop session get the CPU-based implementation ( Ben Voigt )
The currently header and lib that comes with Visual Studio only has OpenGL 1.1 in it, so to access more modern stuff you need to call the wglGetProcAddress to get pointers to the new functions.
Here you can find more information: http://www.opengl.org/wiki/Getting_started