Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Codelite and SFML  (Read 15769 times)

0 Members and 1 Guest are viewing this topic.

lane

  • Newbie
  • *
  • Posts: 29
    • View Profile
Codelite and SFML
« on: March 08, 2016, 05:45:55 am »
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

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Codelite and SFML
« Reply #1 on: March 08, 2016, 07:16:44 am »

lane

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Codelite and SFML
« Reply #2 on: March 09, 2016, 01:53:30 am »
Thank you for that! :)

but I must ask, can I still use my compiler or will I need a new one? (or which download package should I use)

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Codelite and SFML
« Reply #3 on: March 09, 2016, 04:58:27 am »
If there isn't an SFML package compiled for your version of GCC in the download list, then you'll have to compile SFML by yourself. (it's not very hard)
You don't need to change your compiler.

lane

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Codelite and SFML
« Reply #4 on: March 10, 2016, 12:12:11 am »
Once again thank you for your help! Maybe I'm flat out dumb, but I am not understanding this tutorial for the cmake http://www.sfml-dev.org/tutorials/2.3/compile-with-cmake.php. Are there any other resources for this??? It 'sort of' tells you what to do, but when I try it, it doesn't work. :(
Quote
On Windows, if you want to use GCC (MinGW), you can temporarily add the MinGW\bin directory to the PATH and then run CMake from the command shell:

> set PATH=%PATH%;your_mingw_folder\bin
> cmake -G"MinGW Makefiles" ./build

I have already set my Path environment variable to TDM-GCC-32\bin, no problem. Then it says run this cmake.. that is where I am lost, I have no clue, not to mention that my MinGW cmd prompt does understand the command cmake.. Any help with this would be absolutely awesome!

Thanks,
lane

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Codelite and SFML
« Reply #5 on: March 10, 2016, 12:20:31 am »
Maybe if you install CMake it will work a bit better...

lane

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Codelite and SFML
« Reply #6 on: March 10, 2016, 01:04:56 am »
ahhhh... ;)

lane

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Codelite and SFML
« Reply #7 on: March 10, 2016, 01:40:16 am »
I'm usually not one to give up, but I've been trying to get a simple graphics api for a few weeks or so and there has been no luck for me. I have been reading tutorials that make no sense or are outdated. When I can't accomplish simple tasks, I think it's time to just stop. Thank you for the help I have received with this, but I am just done with trying to make things work, when they never do..

Thanks,
lane

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Codelite and SFML
« Reply #8 on: March 10, 2016, 02:11:09 am »
Don't give up. SFML's worth it ;)

How set are you on your exact compiler? :P

Just so you know, this is CMake's website.

I actually had trouble with compiling SFML. It's disheartening (I think CMake hates me for no reason) but don't give up. Maybe your compiler is in this list? Click "Compilers" to see the compiler names more clearly. The builds are newer than latest release build but are not - currently - the latest master (on GitHub).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

lane

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Codelite and SFML
« Reply #9 on: March 10, 2016, 11:46:23 pm »
my compiler is this one http://tdm-gcc.tdragon.net/download.

I have no idea if this helps...

...

yup..
I am using Codelite 9.1.0  8)
TDM-GCC-32 v. 5.1.0

Thanks for the support all..

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Codelite and SFML
« Reply #10 on: March 11, 2016, 05:24:40 pm »
I am using ... TDM-GCC-32 v. 5.1.0
Then, you can download pre-built binaries for v.2.3.2+ (+ is because it's slightly newer than the 2.3.2 release) - as well as some other libraries - from:
https://www.nightlybuilds.ch/compiler/show/17/MinGW-Builds-510r0-32/

Only other options would be to build SFML yourself or downgrade your compiler to match (identically) to a release version  :-\
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

lane

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Codelite and SFML
« Reply #11 on: March 12, 2016, 05:37:27 am »
Okay, I appreciate your help Hapax! :)

Let me ask this, I went to the link (https://www.nightlybuilds.ch/compiler/show/17/MinGW-Builds-510r0-32/). Do I need to download the compiler at the top of the screen, then download the SFML choice in the table?  :-\

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Codelite and SFML
« Reply #12 on: March 12, 2016, 06:28:50 am »
I was guessing that it matched the compiler that you're using (because it is GCC and version 5.1.0).
Looking at it again, I've realised that I made an error. You're using TDM, right? (there isn't a pre-built version for TDM after version 481).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

lane

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Codelite and SFML
« Reply #13 on: March 12, 2016, 09:20:47 pm »
Okay,

One more question. Let me just restart (compiler wise).

When I go to get a compiler to compile SFML with Codelite, I need to go to the SFML Downloads page download the GCC 4.8.1 TDM (SJLJ) - 32-bit one, then go and get that compiler? If I do this, will I be able to use SFML to create a window and add a picture, etc.?

For all that I want at this point, is something to work.

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Codelite and SFML
« Reply #14 on: March 12, 2016, 10:10:30 pm »
If you want to compile SFML, you simply get the SFML's source code and build it with whatever compiler you want.

If you don't want to compile SFML, you need to get a version that was built with the same compiler you want to use.

 

anything