Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 months ago.
Improve this question
I use mingW for compiling c++ code. I want to make graphics using openGL. I use notepad++ for writing code. So how can I use the libraries of openGL?
In MinGW you don't have to setup OpenGL. Already there is OpenGL library in a directory C:\~\MinGW\include\GL.Just include the GL/gl.h and GL/glu.h and write code for your OpenGL project.But if you are looking GLUT,GLFW,glew or other library then using the IDE is better soluton like code::blocks or visual studio then do google to setup these library for your IDE.
Once you've got your OpenGL projects compiling and are maybe wondering what do do next, NeHe has a series of great OpenGL tutorials: http://nehe.gamedev.net/
From memory, they are all related to immediate mode (pre v3.0), but a good place to start - especially if you'd rather not use other libraries like GLUT for licensing reasons.
There is a also good list of tutorials here:
http://www.opengl.org/wiki/Getting_Started#Tutorials_and_How_To_Guides
By the way, you can download the Express edition of Visual C++, which is free. Just in case you're only avoiding the Microsoft compiler because of cost: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express
It's just a cut-back version of the professional edition. Basically it doesn't have OpenMP, MFC or ATL, some more advanced debugging tools, and won't compile 64-bit apps. But otherwise it's great. The only thing I'd be upset about not having is 64-bit and OpenMP. But it's free! Feature comparison is here: http://msdn.microsoft.com/en-us/library/hs24szh9.aspx
OpenGL Text Editor/No IDE Friendly
After you write a .cpp files in Notepad,Notepad++,VS Code,Vim,Etc.
You can compile the .cpp file and generate a executable using MinGW on command line with the following command.
g++ ./main.cpp -o./main
Linking all the Opengl Project's files and libraries can quickly turn command line into looking like this
g++ /path/main.cpp /path/another.cpp... -I/path/includedlibirary... -L/path/headers... -lglfw3 -lopengl32 -lglu32 -lgdi32 -o/path/output_executable
IMG:What it what eventually looks like in command line
Instead of typing a similar monstrosity before every compile
I would use a Makefile and add it in the same directory as your project.Then compile the Makefile with following command.
mingw32-make
A Makefile
Acts like a Batch script
Acts like a linker in Codeblocks or Visual Studio: linking files and libraries to compiler
Can tell the compiler where to output the executable .exe
IMG:Example of OpenGL Project Directory
Note: File paths are based on my setup and project's setup
Example Makefile:
# Created Libraries directory in C: to store downloaded libraries
glfw_include = C:\Libraries\GLFW\include
glfw_lib = C:\Libraries\GLFW\lib
glad_include = C:\Libraries\GLAD\include
glad_src = C:\Libraries\GLAD\src\glad.c
stb_include = C:\Libraries\STB\include
stb_src = C:\Libraries\STB\src\stb.cpp
glm_include = C:\Libraries\GLM\include
json_include = C:\Libraries\JSON\include
# Project's local header files
local_include = ./Header
# Project's local cpp files
local_src = ./Source/shaders_class.cpp ./Source/textures_class.cpp ./Source/camera_class.cpp ./Source/meshes_class.cpp ./Source/model_class.cpp ./Source/shaders_EBO.cpp ./Source/shaders_VAO.cpp ./Source/shaders_VBO.cpp
################################################################################################################################################################################################################################
CXX = g++
CPP = ./Source/main.cpp
TARGET = ./Bin/main
OBJECTS = $(CPP) $(glad_src) $(stb_src) $(local_src)
INCLUDES = -I$(glfw_include) -I$(glad_include) -I$(stb_include) -I$(glm_include) -I$(json_include) -I$(local_include)
LIBRARIES = -L$(glfw_lib)
C_FLAGS = $(INCLUDES)
LD_FLAGS = $(LIBRARIES) -lglfw3 -lopengl32 -lglu32 -lgdi32
$(TARGET): $(CPP) # Final Output
# Puts everything together in string that auto runs on command line
# '''Ex: g++ <cpp files> -I<included> -L<header_files> -lglfw3 -lopengl32 -lglu32 -lgdi32 -o<output executable>'''
$(CXX) $(OBJECTS) $(C_FLAGS) $(LD_FLAGS) -o$(TARGET)
Example output from Makefile
g++ ./Source/main.cpp C:\Libraries\GLAD\src\glad.c C:\Libraries\STB\src\stb.cpp ./Source/shaders_class.cpp ./Source/textures_class.cpp ./Source/camera_class.cpp ./Source/meshes_class.cpp ./Source/model_class.cpp ./Source/shaders_EBO.cpp ./Source/shaders_VAO.cpp ./Source/shaders_VBO.cpp -IC:\Libraries\GLFW\include -IC:\Libraries\GLAD\include -IC:\Libraries\STB\include -IC:\Libraries\GLM\include -IC:\Libraries\JSON\include -I./Header -LC:\Libraries\GLFW\lib -lglfw3 -lopengl32 -lglu32 -lgdi32 -o./Bin/main
Credit To:
Recommend for linking files to MinGW / Creating Makefile
Sonars Systems: SDL 2 Tutorial 1c [SETUP] Windows and MinGW Setup
https://www.youtube.com/watch?v=ybYMOKEW9IY&t=15s
Recommend OpenGL Intro
Victor Gordan: OpenGL Tutorials
https://www.youtube.com/playlist?list=PLPaoO-vpZnumdcb4tZc4x5Q-v7CkrQ6M-
Related
I am trying to link a compiled research experiment project, built in C/C++.
The project is dependant on HyperNEAT and robot simulation software WeBots.
I have cloned and built the HyperNEAT project successfully (in that project there are other dependancies such as Boost, TinyXML, JGTL (custom library) and other unrelated subprojects).
I have made a makefile including all neccesary header search paths and library paths, and compiling the two main .cpp files:
/ModHyperNEAT/mod_ctrler7.cpp
/ModSupervisor/mod_supervisor.cpp
works, giving me 2 .o files.
However, in the make link step, when I want to create (separate) executables of both files, I am getting the 'undefined symbols for architecture x86_64' error (see pastebin here: http://pastebin.com/kiwwCcUf). It seems that C++ standard datatypes and functions such as
std::string::end() const cannot be found.
I have googled and searched SO for answers regarding this, and it seems that either libraries are missing or binary incompatible if i understand correctly, but the libraries are there and both projects have been compiled with the -lstdc++ flag.
This is the make link step (and the used macro's from the makefile) :
CC = gcc
CFLAGS = -v -g -lstdc++ -Wall -Wno-error -ferror-limit=100 -fmessage-length=0
DEFINES = -DHCUBE_NOGUI -DTIXML_USE_STL
FLAGS = $(CFLAGS) $(DEFINES)
LIB_TINYXML = -L/Users/michahell/Documents/projects_c++/HyperNEAT/tinyxmldll/out
LIB_HYPERNEAT = -L/Users/michahell/Documents/projects_c++/HyperNEAT/NE/HyperNEAT/out
LIB_BOOST = -L/usr/local/Cellar/boost/1.57.0/lib
LIB_WEBOTS = -I/Applications/Webots/lib
LIBS = $(LIB_TINYXML) $(LIB_HYPERNEAT) $(LIB_BOOST) $(LIB_WEBOTS)
LIBFLAGS = -ltinyxmlpluslib -lboost_filesystem-mt -lboost_random-mt -lboost_system-mt -lNEATLib_d -lHypercube_NEAT_Base_d
WEBOTS_DYLIB = -dylib_file /Applications/Webots/lib/libController.dylib:/Applications/Webots/lib/libController.dylib
$(CC) $(FLAGS) $(LIBS) ./mod_ctrler7.o $(WEBOTS_DYLIB) $(LIBFLAGS)
I found out that to link to .dylib's I had to use a specific flag and specify the full path, hence the $(WEBOTS_DYLIB) macro.
I am using the -lstdc++ flag because in the HyperNEAT project that flag was also used for building that library. If i exclude this flag, i get a lot of errors during compilation (libc++ and libstdc++ incompatibility as I now understand). All of the library paths check out, and .a and/or .dylib files are present.
My knowledge of C/C++ and GCC tooling is very limited, as I have never had to use it before.
I think it might have to do with the fact that the HyperNEAT project contains a Boost 1.57.0 distribution which is used for their build, and that i have a separate (using homebrew) Boost version installed on my system, which is the same version:
$ brew info boost
boost: stable 1.57.0 (bottled), HEAD
http://www.boost.org
/usr/local/Cellar/boost/1.57.0 (10572 files, 439M) *
What could be the cause of this error failing my link step? Anyone should be able to reproduce my linker errors if both HyperNEAT and my project are cloned and put their root dirs in the same location. WeBots should be downloaded but only for the header includes and libraries. And of course my makefile paths should be modified.
If anyone can give me tips on how to solve this problem, i would GREATLY appreciate it!
It turns out that, for some reason, I had to include the lstdc++ flag to the library link flags and not as a compiler flag, AND the stdlib=libstdc++ as compiler flag.
Based on this question I was able to make one default cmake compilation for GLFW libraries, compile my GLFW App and run; everything works and was made through the terminal since I'm using Ubuntu 14.04 64 bits.
I was using this line to compile:
g++ -std=c++11 -c main.cpp
And this to link:
g++ main.o -o main.exec -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi
After use those commands I only needed to execute main.exec. However, I would like to setup eclipse to compile and run this GLFW application. Include files are already settled on the project but I'm having trouble with my linkers. I was trying to track my libraries (GL, GLU, glfw3....) manually to set the folders but I couldn't find all of them. Does anyone know how could I track the libraries to set them on my linker(Project - Properties - C/C++ Build - Settings - GCC C++ Linker) or could give me some guidelines to solve this situation, please?
Thanks in advance
After try and research for some hours, I found the solution which is pretty easy:
Instead of add paths to libraries, just add their names as it is in the command line. I still don't know from where the path reference for those libraries are coming (and would be great if someone could explain) but what is most important is that works. After build just run (CTRL + F11) like any other application.
Got a predicament with using Code Blocks. I finally have got round to learning OpenGL and I want to use it with OpenGL. I know there is Visual Studio but I like Code Blocks because it is basic and without complexities for me.
Until today. I have absolutely no idea how to get OpenGL to work. Not looking for prize programming at the moment. What I want to achieve is just a black window. The basic of the basics. I have done a good Google search and I can't find an article on installing/activating/utilizing OpenGL.
So what I need is a step-by-step procedure to go from no graphics to a black window. After that, I can at least start playing around to start learning. Can anyone give me a hand? I would really appreciate any help.
I also had some problems recently when I started using OpenGL with C::B.
Download and install SDL from here: http://libsdl.org/. This library can open window, work with keyboard and mouse input, work with TCP/UDP, etc.
To work with opengl, you need GLEW. It have precompiled version only for VS, so you need to build it by yourself. You can get source code here: http://glew.sourceforge.net/.
Then, use these commans to compile it:
1: gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.c
2: gcc -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a -o lib/glew32.dll src/glew.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32
3: ar cr lib/libglew32.a src/glew.o
Copy .a files into MinGW/lib and headers into MinGW/include.
For any project that uses SDL & GLEW & OpenGl, you need to set linker settings:
Project -> Build options... -> Click on project name in build configurations list -> Linker settings -> Add.
You need to add these libs in the exact same order:
mingw32, SDL2main, SDL2, opengl32, glew32, glu32.
(You probably need GLU functions. If not, you can omit the last lib.)
Headers to include:
#include <SDL2/SDL.h>
#include <glew.h>
Because of SDL, your main() must always look like int main(int argc, char **argv).
Minimum calls to open a window:
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
SDL_CreateWindow(/*...*/);
SDL_GL_CreateContext(/*...*/);
glewInit();
You can find descriptions of SDL functions here: http://wiki.libsdl.org/CategoryAPI.
I am using Windows 7, Code::Blocks and MinGW. I have little to no experience when it comes to compiling/building anything, especially when Code::Blocks doesn't use makefiles.
I downloaded SDL2-devel-2.0.0-mingw.tar.gz (SDL Development Libraries) from http://www.libsdl.org/tmp/download-2.0.php, and I'd like to create a standalone executable using SDL2 libraries, but so far I've always had to bundle the SDL2.dll file with the executable to make it work.
I've heard that I can not static-link dynamic libraries, so my only option seems to be doing something with the source files using the file SDL2-2.0.0.tar.gz (Source Code) from the link I mentioned above. However, I do not know what I should do with those.
What I managed to try with the source files is importing the Visual Studio project to Code::Blocks and building it, but it tells me "sdl-config No such file or directory" (I do not know what triggered that). I'm also not sure if building merely gives me an executable, with which I do not know what I can do to link it to my own executable.
A fool proof idiot's step by step guide would be the best bet to solve this case.
EDIT:
I managed to compile the SDL libraries with the guide Jonas provided, and got a libSDL2.a file.
At first I only added the path of libSDL2.a to "Link libraries:" -section of Code::Blocks, but I got a bunch of errors such as "SDL_Init() not declared in this scope".
In addition to the libSDL2.a path, I also added the path of SDL2-2.0.0\include to the Compiler's search directory as well as the path of SDL2-2.0.0\build.libs to the Linker's search directory. I also wrote this to my test file: #include "SDL.h". My test file now looks like this:
#include "SDL.h"
int main( int argc, char* args[] ) {
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Quit SDL
SDL_Quit();
return 0;
}
It appears it did fix the declaration problem, but now Code::Blocks opened a SDL_mmjoystick.c file and gave me even more errors: "undefined reference to 'waveInClose#4'", "undefined reference to 'waveOutClose#4'", "undefined reference to 'joyGetNumDevs#0'" and tons of other ones.
Here's a screenshot of what's happening, note the different color of #include texts, I'm not sure why that happens: http://gyazo.com/00656a9c1e57a2bd0db1414fa7d68ced.png
I am not sure how to correctly take this library into use. Any help in this case, or should I make another question for it?
EDIT:
I added -lSDL2 to the linker options and deleted the other parameters. Now it builds fine:
mingw32-g++.exe -Wall -fexceptions -g -IC:\Users\User\Desktop\SDL2-2.0.0\include -c "C:\Users\User\Desktop\CppProjects\SDL project\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe -Wall -fexceptions -g -IC:\Users\User\Desktop\SDL2-2.0.0\include -c "C:\Users\User\Desktop\CppProjects\SDL project\thetestfile.cpp" -o obj\Debug\thetestfile.o
mingw32-g++.exe -LC:\Users\User\Desktop\SDL2-2.0.0\build\.libs -o "bin\Debug\SDL project.exe" obj\Debug\main.o obj\Debug\thetestfile.o -lSDL2 ..\..\SDL2-2.0.0\build\.libs\libSDL2.a C:\Users\User\Desktop\SDL2-2.0.0\build\.libs\libSDL2.a -mwindows
Output size is 945.80 KB
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 0 warnings (0 minutes, 1 seconds)
But when I try to run it, it says my computer lacks SDL2.dll, while the whole point was to static-link.
So currently I have the path to build/.libs in my Link libraries -settings, -lSDL2 in the Other linker options, and for search directories I have the path to SDL2-2.0.0/include for the compiler and SDL2-2.0.0/build/.libs for the linker.
In the build/.libs directory I can also see libSDL2.a, libSDL2.dll.a, libSDL2.la and libSDL2.lai files, which I don't know what they are.
It's not necessary to recompile the library,
SDL2 is given with static-link library named "libSDL2.a"
on the folder "SDL2-2.0.0\i686-w64-mingw32\lib\".
Just be sure to add these options to the linker :
"-lmingw32 -lSDL2main -lSDL2 -mwindows -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc"
on Code:Blocks at "Project / Build Options... / Linket settings / Other linker options"
These options allow you to link with what SDL2.dll was using.
You can retreive them on the file "SDL2-2.0.0\i686-w64-mingw32\bin\sdl2-config"
The magical trick is to delete or rename the file "libSDL2.dll.a"
on the folder "SDL2-2.0.0\i686-w64-mingw32\lib\".
I added a "-" before to keep it in case I need it.
I don't know why this librairy overcomes the other and a clue would be appreciated.
I tried with Code::Blocks 12.11 MinGW32 and it worked.
If you run with some projects that use dynamic-link
and some other which use static-link, you will have to
keep your librairies in two different folders knowing that
"libSDL2main.a" will be in those two.
Sorry for my writing, I'm not used to write in english.
Mike
There is a small project C++ (it has win32 code) that I need to build. It already has its Makefile. I was told to use MinGW. I have never used it before. I downloaded and installed the latest MinGW installer.
Then, I opened the MinGW shell and did make. The exe file was created. But when I try to run it I get libgcc_s_dw2-1.dll is missing! Why do I get this error? Shouldn't the exe be self-contained and run anywhere?
UPDATE
Here's more information, from the Makefile:
CC = g++
CCOPTIONS=-DWINDOWS -DFORCEINLINE -DMINGW -DSRTP_SUPPORT -D__EXPORT= -D_WIN32_WINNT=0x0501 -DNOMVS
setup.exe: setup.o common.o
$(CC) -ggdb -g -O0 -o $# setup.o common.o -mno-cygwin -mwindows -lwsock32 -lws2_32 -lwinmm -lgdi32 -lcomctl32 -lmapi32 -lVfw32
Whether or not the exe should be self-contained depends on how you built it. We need to see the commands that were executed, or post the makefile. But that DLL does not seem to be part of the current version of MinGW. Also, please clarify if you are actually doing this under cygwin, or if you added the tag by mistake.
Edit: A bit of googling seems like it has to do with the horrible "official" MinGW installation. Remove it, and download the Twilight Dragon build from http://tdm-gcc.tdragon.net and then rebuild completely. The "official" build is cr*p anyway - I don't know why anyone uses it.
If what you want to do is a stand alone application with MinGW, you should add -static to the linking options.
On a side note, if you're making a Win32 application, add the -mwindows option to the C++ compiler so it doesn't open a console together with your main window.