Hello,
I am new to SFML and I am trying to learn to load and draw a .png to a window. I am using the Codelite IDE with TDM-GCC-32 compiler. here is my code:
#include <SFML/Graphics.hpp>
#include "Game.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
sf::Texture texture;
if(!texture.loadFromFile("texture.png"))
return 1;
sf::Sprite sprite;
sprite.setTexture(texture);
sf::RenderWindow window(sf::VideoMode(500, 500), "SFML works!");
while (window.isOpen()) { //Game Loop
sf::Event event; //Process Events
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) { //Close Window: exit
window.close();
}
if(event.type == sf::Event::KeyPressed){ //Gets WSAD key strokes
if(event.key.code == sf::Keyboard::W){
cout<<"you hit the W key" << endl;
window.draw(sprite);
}
if(event.key.code == sf::Keyboard::A){
cout<<"you hit the A key" << endl;
}
if(event.key.code == sf::Keyboard::S){
cout<<"you hit the S key" << endl;
}
if(event.key.code == sf::Keyboard::D){
cout<<"you hit the D key" << endl;
}
}
}
}//End of Game Loop
return 0;
}
My Error message tells of an undefined reference to my 'loadfromfile' line.
build log:
C:\WINDOWS\system32\cmd.exe /C C:/TDM-GCC-32/bin/mingw32-make.exe -j4 SHELL=cmd.exe -e -f Makefile
"----------Building project:[ SFML - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Projects/SFML'
C:/TDM-GCC-32/bin/g++.exe -o ./Debug/SFML @"SFML.txt" -L. -LC:/SFML-2.3.2-windows-gcc-4.8.1-tdm-32-bit/SFML-2.3.2/lib -lsfml-graphics -lsfml-window -lsfml-system
./Debug/main.cpp.o: In function `main':
C:/Projects/SFML/main.cpp:12: undefined reference to `sf::Texture::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, sf::Rect<int> const&)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/SFML] Error 1
SFML.mk:78: recipe for target 'Debug/SFML' failed
mingw32-make.exe[1]: Leaving directory 'C:/Projects/SFML'
mingw32-make.exe: *** [All] Error 2
Makefile:4: recipe for target 'All' failed
====2 errors, 0 warnings====
Any help with this issue would be awesome!
Thanks,
lane
Well, I decided to build SFML in Cmake for Code::Blocks (I have that IDE but would rather use Codelite). I got everything to work, I built the files I compiled it, I got the lib files. But now when I try out a project from the examples folder, I get all of these errors...
Build log:
-------------- Build: Debug in TrophyHunter (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -L"C:\sfml build\lib" -o bin\Debug\TrophyHunter.exe obj\Debug\main.o -lsfml-window-s -lsfml-graphics-s -lsfml-audio-s -lsfml-main -lsfml-system-s
obj\Debug\main.o: In function `main':
C:/Projects/TrophyHunter/main.cpp:27: undefined reference to `glClearDepth@8'
C:/Projects/TrophyHunter/main.cpp:28: undefined reference to `glClearColor@16'
C:/Projects/TrophyHunter/main.cpp:31: undefined reference to `glEnable@4'
C:/Projects/TrophyHunter/main.cpp:32: undefined reference to `glDepthMask@4'
C:/Projects/TrophyHunter/main.cpp:35: undefined reference to `glDisable@4'
C:/Projects/TrophyHunter/main.cpp:36: undefined reference to `glDisable@4'
C:/Projects/TrophyHunter/main.cpp:39: undefined reference to `glViewport@16'
C:/Projects/TrophyHunter/main.cpp:42: undefined reference to `glMatrixMode@4'
C:/Projects/TrophyHunter/main.cpp:43: undefined reference to `glLoadIdentity@0'
C:/Projects/TrophyHunter/main.cpp:45: undefined reference to `glFrustum@48'
C:/Projects/TrophyHunter/main.cpp:95: undefined reference to `glEnableClientState@4'
C:/Projects/TrophyHunter/main.cpp:96: undefined reference to `glEnableClientState@4'
C:/Projects/TrophyHunter/main.cpp:97: undefined reference to `glVertexPointer@16'
C:/Projects/TrophyHunter/main.cpp:98: undefined reference to `glColorPointer@16'
C:/Projects/TrophyHunter/main.cpp:101: undefined reference to `glDisableClientState@4'
C:/Projects/TrophyHunter/main.cpp:102: undefined reference to `glDisableClientState@4'
C:/Projects/TrophyHunter/main.cpp:124: undefined reference to `glViewport@16'
C:/Projects/TrophyHunter/main.cpp:128: undefined reference to `glClear@4'
C:/Projects/TrophyHunter/main.cpp:131: undefined reference to `glMatrixMode@4'
C:/Projects/TrophyHunter/main.cpp:132: undefined reference to `glLoadIdentity@0'
C:/Projects/TrophyHunter/main.cpp:133: undefined reference to `glTranslatef@12'
C:/Projects/TrophyHunter/main.cpp:134: undefined reference to `glRotatef@16'
C:/Projects/TrophyHunter/main.cpp:135: undefined reference to `glRotatef@16'
C:/Projects/TrophyHunter/main.cpp:136: undefined reference to `glRotatef@16'
C:/Projects/TrophyHunter/main.cpp:139: undefined reference to `glDrawArrays@12'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x205): undefined reference to `glGetString@4'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x216): undefined reference to `glGetString@4'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0xf33): undefined reference to `glGetIntegerv@8'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0xf49): undefined reference to `glGetIntegerv@8'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0xf51): undefined reference to `glGetError@0'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0xf96): undefined reference to `glEnable@4'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0xfcd): undefined reference to `glGetIntegerv@8'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x100e): undefined reference to `glGetIntegerv@8'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x104f): undefined reference to `glGetString@4'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x10fe): undefined reference to `glGetIntegerv@8'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x19d3): undefined reference to `glGetIntegerv@8'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x19f0): undefined reference to `glGetIntegerv@8'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x19f8): undefined reference to `glGetError@0'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x1a5f): undefined reference to `glEnable@4'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x1a8d): undefined reference to `glGetIntegerv@8'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x1ad2): undefined reference to `glGetIntegerv@8'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x1b0f): undefined reference to `glGetString@4'
C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj):GlContext.cpp:(.text+0x1bb9): undefined reference to `glGetIntegerv@8'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../../mingw32/bin/ld.exe: C:\sfml build\lib/libsfml-window-s.a(GlContext.cpp.obj): bad reloc address 0x5d in section `.text$_ZNSt8_Rb_treeIPN2sf4priv9GlContextES3_St9_IdentityIS3_ESt4lessIS3_ESaIS3_EE16_M_insert_uniqueERKS3_[__ZNSt8_Rb_treeIPN2sf4priv9GlContextES3_St9_IdentityIS3_ESt4lessIS3_ESaIS3_EE16_M_insert_uniqueERKS3_]'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 3 second(s))
44 error(s), 0 warning(s) (0 minute(s), 3 second(s))
I "think" it has to do with the opengl due to the undefined references starting with gl..
If any of you out there know how to fix this I would be very, very happy!