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've been working on a game using SFML for a while now and it's been going great working on it on my Linux and Mac machines. Recently, I tried compiling the game on Windows and ran into many issues.
I'm using g++ and a makefile.
g++ -std=c++17 -g -O2 -Wall -Wno-reorder -LSFML-2.5.1/lib -ISFML-2.5.1/include -o dungy Animation.o Camera.o Dust.o DustParticle.o Entity.o Game.o main.o Player.o PlayerTrail.o Room.o Textures.o Tile.o -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system
I get tons of undefined references like this when I run make (link to full ouput below):
Animation.o: In function `Animation::Animation(sf::Sprite*, int, bool)':
C:\Users\foxhu\Documents\Programming\C++\dungy/Animation.cpp:9: undefined reference to `__imp__ZNK2sf6Sprite15getGlobalBoundsEv'
C:\Users\foxhu\Documents\Programming\C++\dungy/SFML-2.5.1/include/SFML/Graphics/RectangleShape.hpp:41: undefined reference to `__imp__ZN2sf5ShapeD2Ev'
A similar error is outputted when using Visual Studio [following the SFML website's tutorial exactly] but it's mostly made up of random characters.
Here's a link to the full output including the g++ command
I'm using the newest SFML version and have used g++ in the past to compile a game using almost the exact same makefile, so I'm dumbfounded as to why this isn't working and can find nothing online to help me after hours of looking and trying to solve this issue. The game works perfectly on both Mac and Linux using g++ and the same makefile
One final thing is that the website for SFML says to make sure compiler versions 100% match, I downloaded the one they provided for MinGW 7.3.0 (32-bit) and downloaded the proper SFML version to match that.
Edit:
Here's the full makefile if for some reason it's needed
Apparently, I had to use the debug libraries, which I don't have to use on any other platform.
The makefile I now use has the following flags:
LDFLAGS = -lsfml-graphics-d -lsfml-audio-d -lsfml-window-d -lsfml-system-d
Before, I had these LDFLAGS without the -d on the end.
Not sure why this is different on Windows than Mac or Linux, but it continues my disdain for using Windows when programming.
I was creating program on windows with SDL2 and the program worked fine, but when I changed my os to linux mint (and install code::blocks, gcc, g++, SDL2), I run into troubles with compiling my code.
I have one error:
- ld||cannot find -lmingw32|
I guess that I don't have mingw32 library, where can I get it? Or is the problem diferent?
BTW: I also tryed to google it.
Thank for response.
Read the manual.
On linux you don't need -lmingw32. Instead, use
`sdl2-config --libs`
to get the list of all needed linker flags.
Example usage:
gcc -o myprogram myprogram.o `sdl2-config --libs`
Problem was solved by removing linker on mingw32 and lib rotozoom.h.
I am trying to compile a simple tutorial program utilising glfw with minimal opengl. My issue appears to be that the glfw library is stubbornly refusing to be dynamically linked. The relevant make command is:
"C:\Program Files\mingw-w64\mingw64\bin\g++" -Wall -m64 -D GLFW_DLL -l opengl32 -l glfw3 main.o -o triangle <br />
The main.o file is compiled from a c++ file, main.cpp by:
"C:\Program Files\mingw-w64\mingw64\bin\g++" -c -Wall -m64 -D GLFW_DLL main.cpp -o main.o
Every reference to the glfw functions made inside the code is causing an undefined reference to the relevant implementation functions (eg. __imp_glfwInit for glfwInit => undefined reference to '__imp_glfwInit')
Build system is mingw-w64 [windows] using make via the command line, with glfw 3.0.4. The glfw lib is 64 bit and the latest stable build avaliable. It consists of the files:
glfw3.dll
glfw3dll.a
libglfw3.a
Which are the 'WIN-64' 'lib-mingw'
After extensive searches (GLFW help pages useless[deal either with 2.7.2 which doesn't apply or doesn't have useful information in the case of 3.0.4], most of stackoverflow deals with static linking, ect) I have been unable to find a solution which works.
Is there something I am missing dealing with the linker that is not making me able to dynamically link?
Clarification on any errors I am making or a solution of some form that would still allow me to use the dynamic libraries would be greatly appreciated
It appears that the provided files do not work with mingw-w64, and are only compatible with 64bit mingw.
Thus the only option left is linking against the dll (with thanks to greatwolf: https://stackoverflow.com/a/17734362/2396393). The code to compile to objects thus became:
"C:\Program Files\mingw-w64\mingw64\bin\g++" -Wall -m64 -D GLFW_DLL main.o -o triangle ./lib/glfw3.dll -l opengl32
Where the dll glfw3 is located in the lib folder
I have recently installed SFML 2.1 and am trying to compile and run from the terminal, NOT Xcode, the sample program that they have on their website at http://www.sfml-dev.org/tutorials/2.0/start-linux.php.
Path to where I installed SFML:
/Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal
However, I keep getting the error of:
Undefined symbols for architecture x86_64:
"sf::String::String(char const*, std::__1::locale const&)", referenced from:
_main in window-48cb4a.o
After googling it, I came across this question: SFML 2.1 RenderWindow linking error
In the accepted answer, the person said that if I wanted to use g++, I had to download the "GCC" version. So, I proceeded to download the GCC - universal 32+64 bits (OS X 10.5+) version and then followed the instructions for installing and compiling SFML on linux, since there were none for mac (http://www.sfml-dev.org/tutorials/2.0/start-linux.php) by doing the following:
Since I had installed SFML in a non-standard location, I told my compiler where to find the header files like so:
-I /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/Frameworks/SFML.framework/Headers
I also had to tell my compiler where to find the SMFL libraries:
-L /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/lib
I needed to also tell the library loader where to find the SFML libraries from:
export LD_LIBRARY_PATH=/Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/lib
Then, I put the sfml-audio.framework, sfml-window.framework, sfml-graphics.framework, sfml-network.framework, and sfml-system.framework in my Frameworks directory (/Library/Frameworks).
Finally, I tried to compile my program in the following ways:
g++ window.cpp -I /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/Frameworks/SFML.framework/Headers/SFML -L /users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/lib -framework sfml-graphics -framework sfml-window -framework sfml-system
g++ window.cpp -framework sfml-graphics -framework sfml-window -framework sfml-system
But, I keep getting the same error. I have continued to google the error, but all I keep getting are questions where people are using Xcode and not the terminal. Any help would be greatly appreciated!
I figured it out at last! First off, as Joachim Pileborg pointed out, I need to install the clang version of SFML for mac since I was using g++ to compile which is clang++ in disguise, as Joachim Pileborg also pointed out. Next, I had to go through the instructions again for setting up SFML with Linux (http://www.sfml-dev.org/tutorials/2.0/start-linux.php).
However, the icing on the cake was when I read this question:
OSX GCC how to specify sfml library source?
...and this question:
FreeType error when building in XCode
...which got me thinking: maybe I should try moving my freetype.framework folder (which can be found in the extlibs directory) into my /Library/Frameworks directory. Once I did this and compiled using
g++ window.cpp -framework sfml-graphics -framework sfml-window -framework sfml-system
It compiled and ran successfully!!! I am very happy now!
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