C++ OpenGL, errors when linking, compiling - c++

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.

Related

Chilkat sample, linkSample.cpp program, could not be compiled

I have downloaded "Chilkat C/C++ Library Downloads for Qt, CodeBlocks, MinGW, TDM-GCC, and MinGW-w64" version of Chilkat library in order to run above ftp c++ code.
#include <stdio.h>
#include "include/CkZip.h"
#include "include/CkFtp2.h"
#include "include/CkMailMan.h"
#include "include/CkXml.h"
#include "include/CkPrivateKey.h"
#include "include/CkRsa.h"
#include "include/CkHttp.h"
#include "include/CkMime.h"
#include "include/CkMht.h"
#include "include/CkSsh.h"
#include "include/CkSFtp.h"
void DoNothing(void)
{
// Instantiate the objects...
CkZip zip;
CkMailMan mailman;
CkFtp2 ftp2;
CkXml xml;
CkPrivateKey privKey;
CkRsa rsa;
CkHttp http;
CkMime mime;
CkMht mht;
CkSsh ssh;
CkSFtp sftp;
printf("Zip version: %s\n",zip.version());
}
int main(int argc, const char* argv[])
{
DoNothing();
return 0;
}
I have read the README fille and tried to run sample C++ sample linkSample.cpp.
for that reason I have read the linkSample.sh file which places in the Chilkat for Mingw folder.
I have worked in windows and loaded mingw and the path of g++ added to the cmd.
When I directly run the .sh folder command to the cmd I have received following error!
C:\Users\emma\Desktop\chilkat-9.5.0-x86_64-8.1.0-posix-seh-rt_v6-rev0>g++ -Wl,--enable-auto-import linkSample.cpp -o"linkSample.exe" -L. -lchilkat-9.5.0 -L/c/MinGW/lib -lcrypt32 -lws2_32 -ldnsapi
C:\Users\emma\AppData\Local\Temp\cciL4ofa.o:linkSample.cpp:(.text+0x10): undefined reference to `CkZip::CkZip()'
C:\Users\emma\AppData\Local\Temp\cciL4ofa.o:linkSample.cpp:(.text+0x1d): undefined reference to `CkMailMan::CkMailMan()'
C:\Users\emma\AppData\Local\Temp\cciL4ofa.o:linkSample.cpp:(.text+0x2a): undefined reference to `CkFtp2::CkFtp2()'
Could you guide me about compileing and running sample chilkat cpp program?
Thanks
I have change the workspace to linux and Also downloaded Chilkat "C/C++ Libraries for Linux" and copy the linkSample.cpp code to inside of it and run the following code:
g++ linkSample.cpp -Llib -lchilkat-9.5.0 -o linkSample -ldl
and the bin file have been appeared without error message. BUt, when I have tried to run executable bin file the following error message appears:
./linkSample: error while loading shared libraries: libchilkat-9.5.0.so: cannot open shared object file: No such file or directory
I want to keep my workspace in windows but I have just tried to see what happend in linux, and finally it does not work properly.
Any suggestion do you have?
Thanks

SDL2 headers not being found when compiling os x

I can't seem to compile this program. I have other people in my class that are having no problem compiling this code. I'm using the same command to try to compile the program and installed the frameworks in the same directory as them. /Library/Frameworks. I also installed eclipse and followed the zamma.co.uk tutorial to setup sdl2 and that didn't work either. Here is the command i'm running when compiling
g++ -std=c++11 -o Gravity main.cpp Game.cpp Particle.cpp Point.cpp -I/Library/Frameworks/SDL2.framework/Headers -framework SDL2 -framework Cocoa
Note: I have tried both
#include <SDL.h>
and
#include <SDL2/SDL.h>
and neither work
The ld linker error you mention in your comments suggests you may need to pass the -F option or -L in case your features/library search path is not finding your SDL2 installation.
Your problem sounds similar to:
linker command failed, sdl
How do you include files in C++ from the /Library/Framework folder in MAC

Linking GLEW libraries when compiling with MinGW

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...

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>.

Installed freetype through homebrew, can't seem to include headers correctly

On my xcode project, I added the dylib of freetype to the project Link Binary phase.
I ensure /usr/local/include and /usr/local/lib are in search paths in the build settings.
I then include:
#include <freetype2/ft2build.h>
#include FT_FREETYPE_H
But i get an error that freetype.h was not found. Any ideas? I tried including <freetype2/freetype.h> directly, but that leads to more compile problems with include paths in other freetype files.
Looking at the demo programs in "freetype2-demos", I see:
#include <ft2build.h>
#include FT_FREETYPE_H
Also, I think you need your compiler command-line to include -I (path to freetype includes).
For example...
g++ -I (...)/freetype2 myfile.cpp
Here are the instructions. The suggestion there is to compile with something like...
g++ $(freetype-config --cflags) myfile.cpp
...which, if you system is configured correctly, will incorporate the -I option that I previously mentioned.