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

Author Topic: sfml 2 static linking confusion  (Read 4556 times)

0 Members and 1 Guest are viewing this topic.

blueeyedlion

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
sfml 2 static linking confusion
« on: April 09, 2012, 04:40:44 am »
I downloaded SFML 2 precompiled from sfml coder (the mingw one), I've copied the stuff in the include folder to my path, but what do I do to statically link sfml?  From guesswork, I have a makefile that looks like this:
Code: [Select]
all: sfml_testing.o
g++ -o sfml_testing.exe sfml_testing.o -l libsfml-graphics-s.a -l libsfml-window-s.a -l libsfml-system-s.a

sfml_testing.o:
g++ -c sfml_testing.cpp

This provides this error message:

Code: [Select]
mingw32-make -k
g++ -o sfml_testing.exe sfml_testing.o -l libsfml-graphics-s.a -l libsfml-window-s.a -l libsfml-system-s.a
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -llibsfml-graphics-s.a
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -llibsfml-window-s.a
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -llibsfml-system-s.a
collect2: ld returned 1 exit status
mingw32-make: *** [all] Error 1

I gather that I am either not naming the libraries correctly or not putting them in the right place, probably both. 
So what exactly am I doing wrong?

by the way, my cpp file is this:
#include <SFML/Window.hpp>
#include <iostream>

int main ()
{
    sf::Window App (sf::VideoMode (800, 600, 32), "SFML_Testing");

    int x;
    std::cin >> x;

    return 0;
}
 
« Last Edit: April 09, 2012, 10:12:21 am by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sfml 2 static linking confusion
« Reply #1 on: April 09, 2012, 10:13:46 am »
Quote
-l libsfml-graphics-s.a
You can't link a library like this. The correct syntax is:
Code: [Select]
-lsfml-graphics-sThen, you must define the SFML_STATIC macro.
Code: [Select]
-DSFML_STATIC
Laurent Gomila - SFML developer

blueeyedlion

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: sfml 2 static linking confusion
« Reply #2 on: April 09, 2012, 06:47:39 pm »
Thanks, and where am I supposed to put the library files?  In with my project files?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sfml 2 static linking confusion
« Reply #3 on: April 09, 2012, 07:32:05 pm »
Have you read the "getting started" tutorial? It's for SFML 1.6, but the installation and IDE/compiler setup is the same.
Laurent Gomila - SFML developer

blueeyedlion

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: sfml 2 static linking confusion
« Reply #4 on: April 09, 2012, 08:30:28 pm »
After following the instructions in the code::blocks tutorial, I now have this:
Code: [Select]
mingw32-make -k
g++ -o sfml_testing.exe sfml_testing.o -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -DSFML_STATIC
sfml_testing.o:sfml_testing.cpp:(.text+0x8d): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
sfml_testing.o:sfml_testing.cpp:(.text+0xc8): undefined reference to `_imp___ZN2sf6WindowC1ENS_9VideoModeERKSsjRKNS_15ContextSettingsE'
sfml_testing.o:sfml_testing.cpp:(.text+0x107): undefined reference to `_imp___ZN2sf6WindowD1Ev'
sfml_testing.o:sfml_testing.cpp:(.text+0x135): undefined reference to `_imp___ZN2sf6WindowD1Ev'
sfml_testing.o:sfml_testing.cpp:(.text+0x15f): undefined reference to `_imp___ZN2sf6WindowD1Ev'
collect2: ld returned 1 exit status
mingw32-make: *** [all] Error 1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sfml 2 static linking confusion
« Reply #5 on: April 09, 2012, 08:37:50 pm »
Have you tried mingw32-make clean first?
Laurent Gomila - SFML developer

blueeyedlion

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: sfml 2 static linking confusion
« Reply #6 on: April 09, 2012, 10:02:30 pm »
That didn't fix it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sfml 2 static linking confusion
« Reply #7 on: April 09, 2012, 10:44:04 pm »
Can you try with a slightly more complicated source code? Something that calls at least one function other than a constructor.
Laurent Gomila - SFML developer

blueeyedlion

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: sfml 2 static linking confusion
« Reply #8 on: April 09, 2012, 11:45:58 pm »
I get the exact same errors with this:

Code: [Select]
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

int main ()
{
    sf::Window App (sf::VideoMode (800, 600, 32), "SFML_Testing");

    sf::RectangleShape rect (sf::Vector2f (50, 50));

    char c;
    int x = 0;
    int y = 0;
    while (App.isOpen ())
    {
        std::cin >> c;
        if (c == 'a')
            x = -10;
        if (c == 'd')
            x = 10;
        if (c == 'w')
            y = 10;
        if (c == 's')
            y = -10;
        rect.move (x, y);
        x = 0;
        y = 0;
        App.draw (rect);
    }
               

    return 0;
}

EDIT:

wait, after cleaning twice, this happened instead:

Code: [Select]
g++ -c sfml_testing.cpp
sfml_testing.cpp: In function 'int main()':
sfml_testing.cpp:14:16: error: 'class sf::Window' has no member named 'isOpen'
sfml_testing.cpp:25:14: error: 'class sf::RectangleShape' has no member named 'move'
sfml_testing.cpp:28:13: error: 'class sf::Window' has no member named 'draw'
mingw32-make: *** [sfml_testing.o] Error 1
mingw32-make: Target `all' not remade because of errors.
« Last Edit: April 10, 2012, 01:01:44 am by blueeyedlion »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sfml 2 static linking confusion
« Reply #9 on: April 10, 2012, 08:17:21 am »
Nice, just what I expected :)

You're using an old version of SFML, make sure that you don't have multiple versions of SFML installed. Or at least, make sure that you force the right one to be used.
Laurent Gomila - SFML developer