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

Author Topic: Static linking, getting undefined references  (Read 10343 times)

0 Members and 1 Guest are viewing this topic.

joshua1984

  • Newbie
  • *
  • Posts: 13
    • View Profile
Static linking, getting undefined references
« on: July 18, 2013, 09:58:49 pm »
I'm getting undefined references to practically everything I typed. Im using MinGW an im pretty sure it doesn't have to do with the linker because my IDE is making suggestions on functions. I've followed the tutorial to a tee and im still getting undefined references to sf::String, sf::VideoMode, RenderWindow, ect. What am I doing wrong??

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Static linking, getting undefined references
« Reply #1 on: July 18, 2013, 10:01:25 pm »
im pretty sure it doesn't have to do with the linker because my IDE is making suggestions on functions.
The linker and the auto-completion are totally unrelated. The former only needs to parse the header files.

Undefined references are linker errors -- make sure you link the libraries as specified, with the correct debug/release and dynamic/static configuration. What is your configuration and what are the linker entries?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

joshua1984

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Static linking, getting undefined references
« Reply #2 on: July 18, 2013, 10:21:57 pm »
The search directory is valid an a relative path for sfml lib. I'm trying to link SFML statically

Debug:
sfml-graphics-s-d
sfml-window-s-d
sfml-system-s-d

Release
sfml-graphics-s
sfml-window-s
sfml-system-s
« Last Edit: July 18, 2013, 10:31:01 pm by joshua1984 »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

joshua1984

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Static linking, getting undefined references
« Reply #4 on: July 19, 2013, 12:27:47 am »
I reversed the order, still didn't solve my problem

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Static linking, getting undefined references
« Reply #5 on: July 19, 2013, 12:52:34 am »
It's not the order, it was correct. Have you defined SFML_STATIC?

Can you post the exact linker errors?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

joshua1984

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Static linking, getting undefined references
« Reply #6 on: July 19, 2013, 01:01:24 am »
It's not the order, it was correct. Have you defined SFML_STATIC?

Can you post the exact linker errors?

Yeah Sure. Ill also post the code im running just to be sure.

Here is the code:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>


int main()
{
    sf::RenderWindow window(sf::VideoMode(500,500),"Sfml Works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

        while(window.isOpen())
        {

            sf::Event event;
            while (window.pollEvent(event))
            {

                if(event.type == sf::Event::Closed)
                    window.close();
            }
        }
        window.clear();
        window.draw(shape);
        window.display();
}
 

Errors:
obj\Debug\main.o||In function `main':|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|7|undefined reference to `sf::String::String(char const*, std::locale const&)'
|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|7|undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|7|undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|8|undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|7|undefined reference to `sf::RenderWindow::~RenderWindow()'
|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|9|undefined reference to `sf::Color::Green'|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|9|undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|19|undefined reference to `sf::Window::close()'|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|15|undefined reference to `sf::Window::pollEvent(sf::Event&)'
|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|11|undefined reference to `sf::Window::isOpen() const'|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|22|undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|22|undefined reference to `sf::RenderTarget::clear(sf::Color const&)'|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|23|undefined reference to `sf::RenderStates::Default'
|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|23|undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|24|undefined reference to `sf::Window::display()'
|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|24|undefined reference to `sf::RenderWindow::~RenderWindow()'|
C:\Users\Owner\Documents\New folder\SFML2Template\main.cpp|24|undefined reference to `sf::RenderWindow::~RenderWindow()'
|
obj\Debug\main.o||In function `~CircleShape':|
C:\Users\Owner\Documents\New folder\SFML2Template\..\..\..\Desktop\SFML-2.0\include\SFML\Graphics\CircleShape.hpp|42|undefined reference to `vtable for sf::CircleShape'
|
C:\Users\Owner\Documents\New folder\SFML2Template\..\..\..\Desktop\SFML-2.0\include\SFML\Graphics\CircleShape.hpp|42|undefined reference to `vtable for sf::CircleShape'|
C:\Users\Owner\Documents\New folder\SFML2Template\..\..\..\Desktop\SFML-2.0\include\SFML\Graphics\CircleShape.hpp|42|undefined reference to `sf::Shape::~Shape()'
|
||=== Build finished: 20 errors, 0 warnings ===|
 

I'm no beginner to C++, but I've just always had problems with libs for some reason and im almost positive that it's something fairly simple that I probably overlooked. And Yes I did define SFML_STATIC. I really appreciate you having the patience to help me :P

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Static linking, getting undefined references
« Reply #7 on: July 19, 2013, 01:07:40 am »
Are you using the SFML 2.0 binaries and not the SMFL 1.6?
From where did you get them?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

joshua1984

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Static linking, getting undefined references
« Reply #8 on: July 19, 2013, 01:14:26 am »
I got them from here: http://www.sfml-dev.org/download/sfml/2.0/ and I downloaded the one that said GCC 4.7 TDM (SJLJ) - 64 bits

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Static linking, getting undefined references
« Reply #9 on: July 19, 2013, 01:23:03 am »
I got them from here: http://www.sfml-dev.org/download/sfml/2.0/ and I downloaded the one that said GCC 4.7 TDM (SJLJ) - 64 bits
I bet your compiler is not 64 bit. ;)
If it's the one that shipped with Code::Blocks, then it's the 32 bit TDM version.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

joshua1984

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Static linking, getting undefined references
« Reply #10 on: July 19, 2013, 01:38:06 am »
I switched them out. Now im getting like 100 undefined refs to __chkstk_ms :(

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Static linking, getting undefined references
« Reply #11 on: July 19, 2013, 01:46:13 am »
Try downloading one of the nightly builds from eXploiters signature link.  When I first setup SFML2.0 Release with codeBlocks I had a bunch of linker undefined stuff, come to find out the default mingw compiler with codeblocks is incompatable with the Release version of SFML, but the newer nightly builds work with it.  Once i downloaded the correct one (32-bit TDM is what i needed) and linked to that it worked just fine

joshua1984

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Static linking, getting undefined references
« Reply #12 on: July 19, 2013, 01:58:56 am »
Just tried the nightly build. Still got chkstk_ms undef

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Static linking, getting undefined references
« Reply #13 on: July 19, 2013, 02:15:03 am »
When I first setup SFML2.0 Release with codeBlocks I had a bunch of linker undefined stuff, come to find out the default mingw compiler with codeblocks is incompatable with the Release version of SFML, but the newer nightly builds work with it.  Once i downloaded the correct one (32-bit TDM is what i needed) and linked to that it worked just fine
Well the problem are the TDM builds and that Code::Blocks is using them. Because the TDM builds work differently than all the other GCC compilers I've seen, instead of having to define static-libstdc++ and static-libgcc to link the runtime libraries statically, the TDM compiler always link the runtime library static and when you don't want that you'll have to issue -shared-libstdc++ and -shared-libgcc. Given that SFML's CMake doesn't take that into account (while my Nightly Build script does), I've verified that the official SFML builds are using the static runtime library as well.

Just tried the nightly build. Still got chkstk_ms undef
Are you trying to link link non-mingw libraries.
What exact compiler do you have, i.e. from where did you get it? Which Nighlty Builds have you used?
« Last Edit: July 19, 2013, 02:31:40 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

joshua1984

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Static linking, getting undefined references
« Reply #14 on: July 19, 2013, 02:27:37 am »
Posix 32 bit, TDM GCC 4.7.1 and GCC 4.7.2 And im using the compiler that came with C::B

 

anything