I'm using G++ to link my project to glew32, glfw, opengl32, glu32, etc, everything compiles fine - however at the link stage everything but glViewport links and I get this error:
undefined reference to '_glViewport'.
I find this... odd since everything else was fine and I'm kinda at a loss for what to do. I look forward to any advice on what to try and or do.
As per my comment, you need to link with the OpenGL libraries, when you compile do (Linux/cygwin)
g++ -o target source.c -lGL
To link against the the OpenGL libs on Mac OSX it is
g++ -o target source.c -framework OpenGL
Related
I'm using G++ to link my project to glew32, glfw, opengl32, glu32, etc, everything compiles fine - however at the link stage everything but glViewport links and I get this error:
undefined reference to '_glViewport'.
I find this... odd since everything else was fine and I'm kinda at a loss for what to do. I look forward to any advice on what to try and or do.
As per my comment, you need to link with the OpenGL libraries, when you compile do (Linux/cygwin)
g++ -o target source.c -lGL
To link against the the OpenGL libs on Mac OSX it is
g++ -o target source.c -framework OpenGL
I'm trying to compile a program i made using SDL2 to work on others computers (or testing VM in this case).
I've been compiling it with what i think are the correct flags, e.g. g++ main.cpp -o main -lSDL2, however when i try executing it on another Ubuntu installation i get this error.
error while loading shared libraries: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory
From my understanding it's not a problem in my compiling but with how i expect it to work on another Linux installation; I've cross-compiled (using mingw32) and tested it (using a freshly installed VM) on Windows adding the correct dlls with the exe (seems to work fine) and I was expecting for it to work in a similar fashion.
What's the standard in this cases? Should i write a setup scripts to install the library dependencies on the target machine? Is there another way I'm not aware of? I've never released an application for Linux (nor Windows) and I'm struggling to find the resources to do things "the right way".
Thanks for everyone suggestions, I ended up settling for the easy way, compiling the "easy to install" libraries dynamically e.g.-lSDL2 and the others statically (checked the licenses and it should be fine) like so:
g++ main.cpp -o main -Wl,-Bdynamic -lSDL2 -lSDL2_image -lSDL2_ttf -Wl,-Bstatic -lSDL2_gfx -static-libgcc -static-libstdc++
I'll put in my documentation how to install the required SDL2 libraries.
I am not sure how familiar you are with pkg-config, but the output for sdl2 is this:
-D_REENTRANT -I/usr/include/SDL2 -lSDL2
This was found from running this:
pkg-config --cflags --libs sdl2
Basically, you need to point to where SDL2 is located BEFORE you actually link to it.
The tool pkg-config is designed to tell you the information you need when you want to link to a package in Linux. You were linking with the library, but you forgot to tell GCC where the library is located.
If you want to compile you code, try this:
g++ main.cpp -o runme `pkg-config --cflags --libs sdl2`
This will automatically grab all of the flags that you need to compile with SDL2 included.
Oh, and you should note, ORDER MATTERS WHEN ADDING FLAGS AND LIBRARIES!!!
There are many questions on SO where the order of compiler options caused all of the problems. Do not be like those people. I suggest you search SO for more info on that.
I am trying to wite OpenGL on MSYS2. I installed mingw-w64 packages like SDL2, glew, glm, mesa etc. But when I try to compile something like;
gcc main.c -o main -lSDL2 -lGLEW -lGLU -lGL
This is how I compiled things on Linux so i thought it would be similar. but -lGL is giving me problems. I can't find any OpenGL library for MSYS2. I installed mesa as i said but no luck. Should I use Windows version coming with driver and link to that? I don't know how can I do this though.
I copied OpenGL32.dll and lib files from my Windows to mingw64/lib folder and renamed them to libGL but of course this did not work.
If I remember correctly, on Windows these libraries are called differently.
Try -lglew32 -lglu32 -lopengl32.
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
I'm trying to compile code using SDL, I can't really post much of the code here but I can do my best to answer questions about it. The problem occurs when compiling the view code and trying to link the SDL libraries.
g++ -o test test.c -lSDL2main -lSDL2
gives me an error /usr/bin/ld: cannot find -lSDL2main
I know my SDL install is okay because if I leave out the link to SDL2main it compiles fine and runs fine. The problem is there is other code that needs SDL2main. I've poured through my file system and I can't find it and I've searched online pretty exhaustively. I was just hoping someone could help me either resolve the dependency or fix my sdl install if its broken.
If you are using some distro there's probably some tool to search files, even in packages not installed.
For example (I'm using Debian/unstable) apt-file search SDL2main
libsdl2-dev: /usr/lib/i386-linux-gnu/libSDL2main.a
libsdl2-2.0-0:i386 2.0.2+dfsg1-4
libsdl2-dev 2.0.2+dfsg1-4
Once you've verified that the lib exist if it doesn't link there still something to check and try
Check the lib is installed in one of the search path (see How to print the ld(linker) search path)
Or explicit the path
g++ -o test test.c -L/usr/lib/i386-linux-gnu -lSDL2main -lSDL2
Being a static library with some gcc/g++/ld version maybe you need to link the archive as an object, without -l
g++ -o test test.c /usr/lib/i386-linux-gnu/libSDL2main.a -lSDL2