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

Author Topic: Problem with undefined references  (Read 1351 times)

0 Members and 1 Guest are viewing this topic.

Zenarii

  • Newbie
  • *
  • Posts: 2
    • View Profile
Problem with undefined references
« on: March 31, 2018, 03:49:20 pm »
Hi,
I recently set up Codeblocks and sfml and have been getting this error:
Code: [Select]
mingw32-g++.exe -Wall -std=c++14 -fexceptions -std=c++14 -g -std=c++14 -IC:\Users\Zenarii\Documents\Libraries\CPP\SFML-2.4.2\include -IC:\Users\Zenarii\Documents\Libraries\CPP\SFML-2.4.2\include -c C:\Users\Zenarii\Documents\CPP\BlockBreak\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LC:\Users\Zenarii\Documents\Libraries\CPP\SFML-2.4.2\lib -LC:\Users\Zenarii\Documents\Libraries\CPP\SFML-2.4.2\lib -o bin\Debug\BlockBreak.exe obj\Debug\main.o   -lsfml-graphics -lsfml-audio -lsfml-network -lsfml-window -lsfml-system -lsfml-graphics-d -lsfml-audio-d -lsfml-network-d -lsfml-window-d -lsfml-system-d
obj\Debug\main.o: In function `main':
C:/Users/Zenarii/Documents/CPP/BlockBreak/main.cpp:14: undefined reference to `_imp___ZN2sf7Texture12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_4RectIiEE'
C:/Users/Zenarii/Documents/CPP/BlockBreak/main.cpp:15: undefined reference to `_imp___ZN2sf7Texture12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_4RectIiEE'
C:/Users/Zenarii/Documents/CPP/BlockBreak/main.cpp:16: undefined reference to `_imp___ZN2sf7Texture12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_4RectIiEE'
C:/Users/Zenarii/Documents/CPP/BlockBreak/main.cpp:17: undefined reference to `_imp___ZN2sf7Texture12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_4RectIiEE'
collect2.exe: error: ld returned 1 exit status
when trying to build this code (there is more this is just the part creating the error)
Code: [Select]
#include <SFML/Graphics.hpp>

int main() {

  sf::RenderWindow app(sf::VideoMode(800,600), "Break Out!");

  //load textures
  sf::Texture block, paddle, background, ball;
  block.loadFromFile("images/block.png");
  paddle.loadFromFile("images/paddle.png");
  background.loadFromFile("images/background.png");
  ball.loadFromFile("images/background.png");
When searching the issue I found resources that said to reinstall SFML but that didn't work for me. Additionally the tutorial i followed also supplied this code: https://pastebin.com/DdeQ6vQw which worked fine.

Thanks for any help

Zenarii

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Problem with undefined references
« Reply #1 on: March 31, 2018, 04:07:18 pm »
I figured it out so here is the solution if others have the same issue:
The problem was that codeblocks 17 is uncompatible with parts of sfml, so i had to download codeblocks 16 from sourceforge and it worked.

Codeblocks link:
https://sourceforge.net/projects/codeblocks/files/Binaries/16.01/Windows/codeblocks-16.01mingw-setup.exe/download

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Problem with undefined references
« Reply #2 on: March 31, 2018, 04:48:56 pm »
It's not code::blocks, it's the compiler they ship per default.

Compilers need to match version.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/