SFML community forums

Help => General => Topic started by: foxhunter12 on March 24, 2016, 02:30:44 am

Title: Weird linking error on Fedora [not on any other linux I've tried] (Solved)
Post by: foxhunter12 on March 24, 2016, 02:30:44 am
On Fedora 23 when I try to use the native SFML libraries for my game I get the error while compiling:

Quote
[hunter@localhost Winter Wasteland]$ make
** Building the game
g++ -o WinterWasteland src/main.o src/Knife.o src/Player.o src/Snowpile.o src/Tree.o src/Weapon.o src/Snowflake.o -std=c++11 -lsfml-graphics -lsfml-window -lsfml-system
src/main.o: In function `main':
main.cpp:(.text+0x945): undefined reference to `sf::Texture::loadFromFile(std::string const&, sf::Rect<int> const&)'
src/Player.o: In function `Player::Player(sf::Vector2<float>, PlayerDirection, PlayerAimDirection, float, int, int)':
Player.cpp:(.text+0xea): undefined reference to `sf::Texture::loadFromFile(std::string const&, sf::Rect<int> const&)'
src/Snowpile.o: In function `Snowpile::Snowpile(sf::Vector2<float>, int)':
Snowpile.cpp:(.text+0x91): undefined reference to `sf::Texture::loadFromFile(std::string const&, sf::Rect<int> const&)'
src/Tree.o: In function `Tree::Tree(sf::Vector2<float>, int)':
Tree.cpp:(.text+0xfd): undefined reference to `sf::Texture::loadFromFile(std::string const&, sf::Rect<int> const&)'
Tree.cpp:(.text+0x185): undefined reference to `sf::Texture::loadFromFile(std::string const&, sf::Rect<int> const&)'
src/Weapon.o:Weapon.cpp:(.text+0x5d3): more undefined references to `sf::Texture::loadFromFile(std::string const&, sf::Rect<int> const&)' follow
src/Weapon.o: In function `Enemy::~Enemy()':
Weapon.cpp:(.text._ZN5EnemyD2Ev[_ZN5EnemyD5Ev]+0x13): undefined reference to `vtable for Enemy'
src/Snowflake.o: In function `Snowflake::Snowflake(sf::Vector2<float>, int, int, sf::Vector2<float>)':
Snowflake.cpp:(.text+0xd5): undefined reference to `sf::Texture::loadFromFile(std::string const&, sf::Rect<int> const&)'
collect2: error: ld returned 1 exit status
makefile:31: recipe for target 'winterwasteland' failed
make: *** [winterwasteland] Error 1

I am not using Codeblocks or Eclipse, just editing files and compiling through console. This worked on LInux Mint and Ubuntu but Fedora is having issues. Even if I link to a CMake build of SFML I did recently to try to fix this problem, I get the same exact error. Not sure why. Here is how I compile [Makefile]:

Quote
CXX := g++

CXXFLAGS:=-std=c++11

LIBS= -lsfml-graphics -lsfml-window -lsfml-system

all: winterwasteland

main.o: src/main.cpp
   $(CXX) -c $(CXXFLAGS) "src/main.cpp" -o src/main.o

Knife.o: src/Knife.cpp src/Knife.h
   $(CXX) -c $(CXXFLAGS) "src/Knife.cpp" -o src/Knife.o

Player.o: src/Player.cpp src/Player.h
   $(CXX) -c $(CXXFLAGS) "src/Player.cpp" -o src/Player.o

Snowpile.o: src/Snowpile.cpp src/Snowpile.h
   $(CXX) -c $(CXXFLAGS) "src/Snowpile.cpp" -o src/Snowpile.o

Tree.o: src/Tree.cpp src/Tree.h
   $(CXX) -c $(CXXFLAGS) "src/Tree.cpp" -o src/Tree.o

Weapon.o: src/Weapon.cpp src/Weapon.h
   $(CXX) -c $(CXXFLAGS) "src/Weapon.cpp" -o src/Weapon.o

winterwasteland: src/main.o src/Knife.o src/Player.o src/Snowpile.o src/Tree.o src/Weapon.o src/Snowflake.o
   @echo "** Building the game"
   $(CXX) -o WinterWasteland src/main.o src/Knife.o src/Player.o src/Snowpile.o src/Tree.o src/Weapon.o src/Snowflake.o $(CXXFLAGS) $(LIBS)

Thanks. Will provide more info if needed.
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: Mörkö on March 24, 2016, 03:16:01 pm
Does it make a difference if you change the order of the linking?

ie system, then window, then graphics
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: foxhunter12 on March 24, 2016, 03:18:42 pm
Nope, I tried all 6 combinations (3 * 2 * 1) but nothing changed.
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: FRex on March 24, 2016, 06:09:42 pm
If you run ldconfig -p do SFML libs appear in the list?
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: foxhunter12 on March 24, 2016, 08:34:19 pm
Quote
[hunter@localhost ~]$ ldconfig -p | grep sfml
   libsfml-window.so.2.3 (libc6,x86-64) => /lib64/libsfml-window.so.2.3
   libsfml-window.so.2.3 (libc6) => /lib/libsfml-window.so.2.3
   libsfml-window.so (libc6,x86-64) => /lib64/libsfml-window.so
   libsfml-window.so (libc6) => /lib/libsfml-window.so
   libsfml-system.so.2.3 (libc6,x86-64) => /lib64/libsfml-system.so.2.3
   libsfml-system.so.2.3 (libc6) => /lib/libsfml-system.so.2.3
   libsfml-system.so (libc6,x86-64) => /lib64/libsfml-system.so
   libsfml-system.so (libc6) => /lib/libsfml-system.so
   libsfml-network.so.2.3 (libc6,x86-64) => /lib64/libsfml-network.so.2.3
   libsfml-network.so.2.3 (libc6) => /lib/libsfml-network.so.2.3
   libsfml-network.so (libc6,x86-64) => /lib64/libsfml-network.so
   libsfml-network.so (libc6) => /lib/libsfml-network.so
   libsfml-graphics.so.2.3 (libc6,x86-64) => /lib64/libsfml-graphics.so.2.3
   libsfml-graphics.so.2.3 (libc6) => /lib/libsfml-graphics.so.2.3
   libsfml-graphics.so (libc6,x86-64) => /lib64/libsfml-graphics.so
   libsfml-graphics.so (libc6) => /lib/libsfml-graphics.so
   libsfml-audio.so.2.3 (libc6,x86-64) => /lib64/libsfml-audio.so.2.3
   libsfml-audio.so.2.3 (libc6) => /lib/libsfml-audio.so.2.3
   libsfml-audio.so (libc6,x86-64) => /lib64/libsfml-audio.so
   libsfml-audio.so (libc6) => /lib/libsfml-audio.so

-- yes
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: FRex on March 24, 2016, 09:15:14 pm
Okay.
Since only linking failed (and only on Texture::loadFromFile which is interesting) then let's see lists of symbols from one of your .o files that require that function (Tree.o will do) and the SFML graphics lib .so file (with nm and nm --demangle).
Clearly there must be a discrepancy between what .o requires and what .so provides.
Maybe it's some std::string type mismatch due to compilers, versions, C++11 vs. 98 or whatever.
Title: AW: Weird linking error on Fedora [not on any other linux I've tried]
Post by: eXpl0it3r on March 24, 2016, 09:31:47 pm
Did you compile SFML yourself? If not, where did you get it from? What's your compiler?
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: foxhunter12 on March 24, 2016, 10:02:39 pm
@eXpl0it43r I used 3 packages of SFML: 1st was the Fedora 23 built in repo, then I tried the SFML 2.3.2 that I used [exact files] in Linux Mint which worked in Mint but not Fedora, then I tried to build it my self. None worked. And my compiler is gcc-c++, I just typed "sudo dnf install gcc-c++" just to get the newest version that Fedora provides. I did that in mint too (sudo apt-get install gcc-c++) so the compilers are the same.
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: FRex on March 24, 2016, 10:14:21 pm
Symbols lists..?
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: foxhunter12 on March 24, 2016, 10:15:46 pm
http://pastebin.com/yqnjNbBb

Those are the nm --demangle's, I didnt want to put them on the forum due to the massive length of the graphics.so.
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: FRex on March 24, 2016, 10:21:05 pm
Show the ones without demangle too.
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: foxhunter12 on March 24, 2016, 10:23:57 pm
Show the ones without demangle too.

http://pastebin.com/5DEkaMh9
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: FRex on March 24, 2016, 10:29:54 pm
There is same symbol in .so as in the .o . It's strange this happens. Does a single file that just loads a Texture link?
You also have an error in your code BTW, one of these cryptic linker ones where you miss a destructor or virtual keyword or something:
Quote
Weapon.cpp:(.text._ZN5EnemyD2Ev[_ZN5EnemyD5Ev]+0x13): undefined reference to `vtable for Enemy'
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: foxhunter12 on March 25, 2016, 02:14:33 am
There is same symbol in .so as in the .o . It's strange this happens. Does a single file that just loads a Texture link?
You also have an error in your code BTW, one of these cryptic linker ones where you miss a destructor or virtual keyword or something:
Quote
Weapon.cpp:(.text._ZN5EnemyD2Ev[_ZN5EnemyD5Ev]+0x13): undefined reference to `vtable for Enemy'

Thanks for the error, I fixed that. What do you mean by "Does a single file that just loads a Texture link?"
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: FRex on March 25, 2016, 02:30:45 am
#include <SFML/Graphics.hpp>

int main()
{
    sf::Texture tex;
    tex.loadFromFile("some-image.png");
}
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: foxhunter12 on March 25, 2016, 02:45:52 am
#include <SFML/Graphics.hpp>

int main()
{
    sf::Texture tex;
    tex.loadFromFile("some-image.png");
}

That's what it looks like in all files; here's it from Tree.cpp

if(!texture.loadFromFile("src/assets/images/entities/tree1.png")){
    cout << "Failed to load src/assets/images/entities/tree1.png" << endl;
}
if(!shadowTexture.loadFromFile("src/assets/images/entities/treetop1.png")){
    cout << "Failed to load src/assets/images/entities/treetop1.png" << endl;
}
Title: Re: Weird linking error on Fedora [not on any other linux I've tried]
Post by: foxhunter12 on March 25, 2016, 06:32:09 pm
Fixed!! After I fixed the bug from Weapon.cpp, I just had to delete the .o files and compiling and running worked. Weird how it gave me the error with sf::Texture::LoadFromFile. Thanks for all the help @FRex
Title: Re: Weird linking error on Fedora [not on any other linux I've tried] (Solved)
Post by: FRex on March 26, 2016, 01:18:36 am
There is something wrong with your makefile then. You shouldn't need to delete outdated files yourself. You rely on .o files for linking, not on the targets that build these .o files so these targets can't replace outdated .o files to link the app. Maybe you should have src/ in names of the .o targets too?
Title: Re: Weird linking error on Fedora [not on any other linux I've tried] (Solved)
Post by: foxhunter12 on March 26, 2016, 01:40:48 am
There is something wrong with your makefile then. You shouldn't need to delete outdated files yourself. You rely on .o files for linking, not on the targets that build these .o files so these targets can't replace outdated .o files to link the app. Maybe you should have src/ in names of the .o targets too?

I actually made my makefile a lot better and yes, i added src/ in the .o targets as well. It seems to work everytime without fail now since I have updated my game a little since fixing. Thanks for the help! If there's anything else bugging out I'll post on another forum post.