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

Author Topic: Weird linking error on Fedora [not on any other linux I've tried] (Solved)  (Read 7156 times)

0 Members and 1 Guest are viewing this topic.

foxhunter12

  • Newbie
  • *
  • Posts: 15
    • View Profile
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.
« Last Edit: March 25, 2016, 06:32:39 pm by foxhunter12 »

Mörkö

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #1 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

foxhunter12

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #2 on: March 24, 2016, 03:18:42 pm »
Nope, I tried all 6 combinations (3 * 2 * 1) but nothing changed.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #3 on: March 24, 2016, 06:09:42 pm »
If you run ldconfig -p do SFML libs appear in the list?
Back to C++ gamedev with SFML in May 2023

foxhunter12

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #4 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

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #5 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.
« Last Edit: March 24, 2016, 09:22:17 pm by FRex »
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
AW: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #6 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

foxhunter12

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #7 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.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #8 on: March 24, 2016, 10:14:21 pm »
Symbols lists..?
Back to C++ gamedev with SFML in May 2023

foxhunter12

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #9 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.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #10 on: March 24, 2016, 10:21:05 pm »
Show the ones without demangle too.
Back to C++ gamedev with SFML in May 2023

foxhunter12

  • Newbie
  • *
  • Posts: 15
    • View Profile

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #12 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'
Back to C++ gamedev with SFML in May 2023

foxhunter12

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #13 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?"

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Weird linking error on Fedora [not on any other linux I've tried]
« Reply #14 on: March 25, 2016, 02:30:45 am »
#include <SFML/Graphics.hpp>

int main()
{
    sf::Texture tex;
    tex.loadFromFile("some-image.png");
}
Back to C++ gamedev with SFML in May 2023