Linking GLEW libraries when compiling with MinGW - c++

I'm trying to write an OpenGL program which I'm compiling through MinGW. I've managed to successfully link OpenGL, GLUT, GLFW and GLM to my main.cpp file. Given the following headers:
#include "GL/glut.h"
#include "GLFW/glfw3.h"
#include "GL/glew.h"
#include "glm/vec3.hpp"
And the following cmd line:
g++ -o leaf.exe -Wall physics.cpp -mwindows lib/glut32.lib -lopengl32 -lglu32 -lglfw3dll -lglew32 -IC:/MinGW/include/GL
I manage to get it to compile successfully. However, when placing the .a files in MinGW/lib, the .dll file in source folder and the .h file in C:\MinGW\include and adding
#include "GL/glew.h"
With the following command line
g++ -o leaf.exe -Wall physics.cpp -mwindows lib/glut32.lib -lopengl32 -lglu32 -lglfw3dll -lglew32 -IC:/MinGW/include/GL
Then I get a long list of errors including:
In file included from physics.cpp:6:0:
c:\mingw\include\gl\glew.h:85:2: error: #error gl.h included before glew.h
#error gl.h included before glew.h
In file included from physics.cpp:6:0:
c:\mingw\include\gl\glew.h:1814:94: error: 'GLchar' does not name a type
typedef void (GLAPIENTRY * PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar* name);
My first time trying to make something without using Visual Studio or Eclipse. Been trying lots of fixes for it I've found here but nothing concrete.
Thanks for reading this far!

You need to reorder your includes:
#include "GL/glew.h"
#include "GL/glut.h"
#include "GLFW/glfw3.h"
#include "glm/vec3.hpp"
GLFW (and GLUT?) automatically include GL.h, which is what GLEW is complaining about. Not sure why you're using GLUT and GLFW in the same build, they don't exactly go together...

Related

Can't include SDL_ttf.h using MinGW

I'm trying to make a cookie clicker clone and when I include the SDL_ttf header file, I get an error. How do I resolve this error?
#include <iostream>
#include <SDL2\SDL.h>
#include "..\SDL2_ttf-2.0.15\i686-w64-mingw32\include\SDL2\SDL_ttf.h"
I compile with:
g++ -o test test.cpp -I../SDL2-2.0.16/i686-w64-mingw32/include -L../SDL2-2.0.16/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2
I got this error message:
In file included from test.cpp:3:0:
..\SDL2_ttf-2.0.15\i686-w64-mingw32\include\SDL2\SDL_ttf.h:34:17: fatal error: SDL.h: No such file or directory
#include "SDL.h"
I'm on a windows machine (windows 10) and using sublime.
Put the -lSDL2_ttf flag in the compile line

'wx/wx.h' file not found when compiling hello world wxWidget program on mac

I have just installed the latest stable version of wxWidget on my mac and tried to compile the code from the hello world tutorial. This is the code that is causing the error:
#include <wx/wxprec.h>'
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
My compiler throws the following warning:
hello_world.cpp:4:10: fatal error: 'wx/wxprec.h' file not found
#include <wx/wxprec.h>
^~~~~~~~~~~~~
1 error generated.
I have checked the directory where I installed wxMac and the file wxprec.h exists in the "include" sub-directory.
If anyone knows why the file cannot be found even though it exists please let me know.
I found out the answer to this problem. To fix it I used the following line to compile/build the hello world app:
g++ `wx-config --cxxflags` -o out *.cpp `wx-config --libs`
after doing this it was only a matter of sorting out the linking, adding header guards and adding in
IMPLEMENT_APP(MyApp)
and
DECLARE_APP(MyApp)
in MyApp.h and MyApp.cpp respectively which functions as the main function.
I got this information from https://wiki.wxwidgets.org/Hello_World

How would I link external libraries to a cpp file through Emacs

I use the Emacs text editor for editing my files, and have been looking into using OpenGL in my programs. However, I have had trouble including the GLFW header into my program.
Here is my code for the #include statements and essentially test if the files linked properly, which comes from the hyperlink later on.
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
using namespace std;
int main()
{
glewExperimental = true;
if(!glfwInit())
{
cout << "Failed to initialize" << endl;
return -1;
}
return 0;
}
I hit M-x compile then g++ file.cpp -lglut -lGL -lGLEW -lGLU -o file.out and get the following error
g++ anotherGL.cpp -lglut -lGL -lGLEW -lGLU -o anotherGL.out
anotherGL.cpp:5:10: fatal error: GLFW/glfw3.h: No such file or directory
#include <GLFW/glfw3.h>
^~~~~~~~~~~~~~
I followed the instructions for downloading the OpenGL tutorial page, under the section Building on Linux, but the instructions diverge after it moves on to the section where the packages are linked to the IDE.
(http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/)
Is there a M-x command I can use in place of what I have to perform the link?
On "debian" and "red hat" systems, the include file GLFW/glfw3.h is under /usr/include a la /usr/include/GLFW/glfw3.h. Your include statement is correct as /usr/include is implicitly searched by gcc/g++. You've just missed installing the glfw development package. On "debian" or apt-based systems this is in libglfw3-dev. On "red hat" or rpm based systems this is glfw-devel. You may also need to add the flag -lglfw to your compile command.

SDL2_image not found

I am trying to compile the following code which has the headers:
#include <SDL2/SDL.h>
#include <SDL2_image/SDL_image.h>
However after running the following makefile:
g++ -std=c++11 src/main.cpp -lSDL2 -lSDL2_image
I get the following error:
fatal error: SDL2_image/SDL_image.h: No such file or directory
#include <SDL2_image/SDL_image.h>
Any suggestions? Not entirely sure about my installation of SDL_image. I am running this on Ubuntu.
This problem can be solved through installing libsdl2-image-dev package:
apt install libsdl2-image-dev
Run apt-file search SDL_image.h
The result will tell you the location of the include file.
For instance, /usr/include/SDL2/SDL_image.h was returned.
So, when you want to include SDL_image.h, write everything after the include/ in between < >.
Thus, includes should look like the following:
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
See the question's comments for the original discussion regarding this solution.
From SDL documentation, it says that add 'lSDL_image' to the end of the compile line.
cc -o myprogram mysource.o `sdl-config --libs` -lSDL_image
or
gcc -o myprogram mysource.c `sdl-config --libs` -lSDL_image
Here is the reference -> https://www.libsdl.org/projects/docs/SDL_image/SDL_image.html
Section 2.2 Compiling.
So for SDL2, you just need to change 'lSDL_image' to 'lSDL2_image'.
For Windows + SDL2-2.0.8 + SDL_image-2.0.4 + Codeblocks you've got the add both Runtime Binaries and Development Libraries to the compiler and linker. Or else, you'll get the error SDL2_image not found, even with having the dll in your program's directory, this occurs. Hopefully others find this helpful; I had to figure it out myself. Example: If your resources are separate, you'll be adding the two plus your standard SDL2 paths to your compiler and linker. Warning: SDL2_image.h has it's headers assuming that the headers are in the same folder as the SDL2 framework. If you get errors about the image header, include the sub-folder SDL2 from SDL framework in the path and then you should be including SDL2 in the program as: include <SDL.h> rather than include <SDL2/SDL.h>.

C++ OpenGL, errors when linking, compiling

Witam,
nie potrafię sobie poradzić z błędami linkera chyba że kompilatora(i raczej to jest kompilator). Chciałem swoje stare projekty skompilować na nowo i poprawić programy, jednak nie potrafię przejść przez proces linkowania.
w folderze z source.cpp posiadam dodatkowo
Hello,
i cant move on with errors from linker, or compiler. I want to compile my old projects, but i cant cope with errors.
in folder with source.cpp i have also
open32.dll
glu32.dll
glut32.dll (i download it)
glut.h (si download it)
glut.lib (i download it)
glut.def (i think its not nessesery)
bach looks like
path %pathC:\MinGW\bin
g++ -o program.exe main.cpp glut32.lib
and i get errors in every line where i use function from glut32.dll/opengl.dll, all errors are similar
C:\Users\Przemko\AppData\Local\Temp\cc4n2CuY.o:main.cpp:(.text+0xe5): undefined reference to `glClearColor#16'
In MinGW\Include i have folder GL with headers:
glu.h
gl.h
glext.h
"i get it while installing MingW"
my source include
#include <time.h>
#include <iostream>
#include <math.h>
#include <windows.h>
#include "glut.h"
I need help, i dont remember how to link every item, i wish i have my old bash and libary, but i dont.
You don't link with the actual OpenGL library, you need to add -lGL to your command:
$ g++ -o program.exe main.cpp glut32.lib -lGL
You might want to keep your dll files in SysWOW64 folder instead of System32 folder in case you have x64 libraries.