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

Author Topic: Includes and using-namespaces trouble  (Read 1980 times)

0 Members and 1 Guest are viewing this topic.

Law

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Includes and using-namespaces trouble
« on: July 16, 2014, 10:25:31 pm »
Hello,

I cannot compile my project because g++ seems to have a problem with my includes and using-namespaces.

My main file starts like this:

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <deque>
#include <array>
#include <vector>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

using namespace std;
using namespace sf;

class Card;
class Motion;
class Player;

#include "GS.hpp"
#include "Card.hpp"
#include "Player.hpp"
#include "Motion.hpp"
#include "Functions.hpp"
#include "Card.cpp"
#include "Player.cpp"
#include "Motion.cpp"
#include "Functions.cpp"

When I compile my file, I get a bunch of

Code: [Select]
Babel.cpp:(.text+0x1a5): undefined reference to `sf::Sprite::setTexture(sf::Texture const&, bool)'
Babel.cpp:(.text+0x1ca): undefined reference to `sf::Transformable::setRotation(float)'
/tmp/ccWFVqF0.o: In function `Card::SleeveSet(sf::Texture*)':
Babel.cpp:(.text+0x28e): undefined reference to `sf::Sprite::setTexture(sf::Texture const&, bool)'
/tmp/ccWFVqF0.o: In function `Card::SetRotation(double)':
Babel.cpp:(.text+0x2ea): undefined reference to `sf::Transformable::setRotation(float)'
/tmp/ccWFVqF0.o: In function `Card::Blit()':
Babel.cpp:(.text+0x305): undefined reference to `sf::RenderStates::Default'
Babel.cpp:(.text+0x312): undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
/tmp/ccWFVqF0.o: In function `Card::Scale(double)':
Babel.cpp:(.text+0x36f): undefined reference to `sf::Transformable::setScale(float, float)'
Babel.cpp:(.text+0x38e): undefined reference to `sf::Sprite::setTexture(sf::Texture const&, bool)'
Babel.cpp:(.text+0x3b3): undefined reference to `sf::Transformable::setScale(float, float)'
Babel.cpp:(.text+0x3f0): undefined reference to `sf::Transformable::setScale(float, float)'
Babel.cpp:(.text+0x40c): undefined reference to `sf::Sprite::setTexture(sf::Texture const&, bool)'
Babel.cpp:(.text+0x431): undefined reference to `sf::Transformable::setScale(float, float)'
[...]

Someone knows how to handle this? Thanks.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Includes and using-namespaces trouble
« Reply #1 on: July 16, 2014, 10:36:04 pm »
"undefined reference to ...foo..." Is a linker error. Most probable cause is you didn't link the object file or library containing the symbol in question. Or you linked files/libraries in the wrong order.
Could also be that you do link the object file/library but you have explicitly made the symbol not-visible.

Not related, but try to avoid "using <foo>" - you defeat the entire purpose of namespaces when you just pull everything into the global namespace.
« Last Edit: July 16, 2014, 10:44:14 pm by Jesper Juhl »

Law

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: Includes and using-namespaces trouble
« Reply #2 on: July 16, 2014, 10:52:30 pm »
Not sure I got your point. I have the same errors, whether I put "sf::" or not.  :(

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: Includes and using-namespaces trouble
« Reply #3 on: July 16, 2014, 11:46:35 pm »
Add -lsfml-graphics and its dependencies to the compiler's command
P.s. also -lsfml-window -lsfml-system I think
« Last Edit: July 16, 2014, 11:48:13 pm by Strelok »

Law

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: Includes and using-namespaces trouble
« Reply #4 on: July 16, 2014, 11:47:13 pm »
Don't worry about it... I forgot the usual

-Wall -lsfml-graphics -lsfml-window -lsfml-system

at the end of my compile command.

Sorry for wasting your time.  :)

 

anything