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

Author Topic: Build fails; 'undefined reference to..'  (Read 60370 times)

0 Members and 3 Guests are viewing this topic.

Seven

  • Newbie
  • *
  • Posts: 5
    • View Profile
Build fails; 'undefined reference to..'
« on: October 20, 2013, 11:25:27 pm »
Hello!
I've just finished installing SFML using the tutorial on the Wiki, and I've tried to run the code posted at the end of the tutorial. After clicking build, the error log throws this in my face;

obj\Debug\main.o||In function `main':|
N:\Programming\C++\Projects\test-sfml\main.cpp|5|undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'|
N:\Programming\C++\Projects\test-sfml\main.cpp|5|undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'|
N:\Programming\C++\Projects\test-sfml\main.cpp|5|undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'|
N:\Programming\C++\Projects\test-sfml\main.cpp|6|undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'|
N:\Programming\C++\Projects\test-sfml\main.cpp|7|undefined reference to `_imp___ZN2sf5Color5GreenE'|
N:\Programming\C++\Projects\test-sfml\main.cpp|7|undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'|
N:\Programming\C++\Projects\test-sfml\main.cpp|15|undefined reference to `_imp___ZN2sf6Window5closeEv'|
N:\Programming\C++\Projects\test-sfml\main.cpp|12|undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'|
N:\Programming\C++\Projects\test-sfml\main.cpp|18|undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'|
N:\Programming\C++\Projects\test-sfml\main.cpp|18|undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'|
N:\Programming\C++\Projects\test-sfml\main.cpp|19|undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'|
N:\Programming\C++\Projects\test-sfml\main.cpp|19|undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'|
N:\Programming\C++\Projects\test-sfml\main.cpp|20|undefined reference to `_imp___ZN2sf6Window7displayEv'|
N:\Programming\C++\Projects\test-sfml\main.cpp|9|undefined reference to `_imp___ZNK2sf6Window6isOpenEv'|
N:\Programming\C++\Projects\test-sfml\main.cpp|23|undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'|
N:\Programming\C++\Projects\test-sfml\main.cpp|5|undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'|
N:\Programming\C++\Projects\test-sfml\main.cpp|23|undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'|
obj\Debug\main.o||In function `ZN2sf11CircleShapeD1Ev':|
C:\SFML\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `_imp___ZTVN2sf11CircleShapeE'|
C:\SFML\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `_imp___ZTVN2sf11CircleShapeE'|
C:\SFML\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `_imp___ZN2sf5ShapeD2Ev'|
||=== Build finished: 20 errors, 0 warnings (0 minutes, 1 seconds) ===|
 

I have no idea what to do, a Google search appears with next to no results and I tried searching these forums but got a database error (just my luck!)
Information; running SFML 2.1 on Code::Blocks, and I'm using Windows 7. I've tried changing from the Code::Blocks MinGW to a full MinGW install directory but still nothing.

Any help?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Build fails; 'undefined reference to..'
« Reply #1 on: October 20, 2013, 11:43:04 pm »
Those errors mean you aren't linking to the libraries correctly.  Reread the tutorial carefully.

Arch_Shift

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Build fails; 'undefined reference to..'
« Reply #2 on: October 21, 2013, 04:02:33 am »
Can you post the command that it's using to compile?

Example:
Code: [Select]
g++ main.o -o main -ilib/sfml/include -Llib/sfml/lib -lsfml-graphics -lsfml-window -lsfml-system
A lot of the time, the order of the build command is very important, especially when linking. All linking flags should go after the rest of the command.

Seven

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Build fails; 'undefined reference to..'
« Reply #3 on: October 21, 2013, 05:42:30 pm »
Those errors mean you aren't linking to the libraries correctly.  Reread the tutorial carefully.
I've just reread the tutorial twice and reconfigured everything, and I still have no luck.
Could you please expand if possible? If you need any information from me I'll post code/screenshots.



Thanks for your help and quick replies!

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Build fails; 'undefined reference to..'
« Reply #4 on: October 21, 2013, 10:06:13 pm »
Follow this: http://en.sfml-dev.org/forums/index.php?topic=12552.0

Rebuild your project (not just build) and paste the complete output here.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Build fails; 'undefined reference to..'
« Reply #5 on: October 21, 2013, 10:27:15 pm »
I can't believe how many people ask about project settings here, I hope more than one profits from my effort of writing this.

1. set up code::blocks to remember the dir so you dont need to change all project files if you decide on putting SFML somewhere else
- open c::b
- go to "settings" menu -> "global variables"
- click the lower "new" button
- type in "sfml" (without "")
- click the base field
- type in "C:\SFML"  (without "") or whatever directory you put it
- click close

2. set up your project search directories
- have the project open
- rightclick the project name
- click "Build options"
- click your project name in the treeview at left to select options for all builds in the project
- click "Search directories" tab
- click "Compiler" subtab if not already choosen
- click "add" button
- type in "$(#sfml.include)" (without "")
- click "ok"
- click "Linker" subtab
- click "add" button
- type in "$(#sfml.lib)" (without "")
- click "ok"
3. set up the names of the actual library files
- you still need to be in the "Build options" dialog
- click the "Linker settings" tab
- click on "Release" in the treeview at the left
- click "add" button, type in "sfml-network" (without ""), click ok
- repeat last step several times and add "sfml-audio", "sfml-graphics", "sfml-window", "sfml-system", "opengl32" (without "") in the same order as written here
- click on "Debug" in the treeview at the left
- use the "add" button like above to fill in "sfml-network-d","sfml-audio-d", "sfml-graphics-d", "sfml-window-d", "sfml-system-d", "opengl32" (without "")
- click "OK" to close the "Build options" dialog
4. save your updated project
- click "File" menu
- click "Save project"
5. done 8)
- if it is still not working check that you actually put the SFML-version compatible to the version of MinGW you are currently using in the directory you set up and :-[
« Last Edit: October 21, 2013, 10:32:54 pm by wintertime »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Build fails; 'undefined reference to..'
« Reply #6 on: October 21, 2013, 10:34:09 pm »
Is there anything that is not actually explained in the tutorial? If so I'd be glad to add it.
Laurent Gomila - SFML developer

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Build fails; 'undefined reference to..'
« Reply #7 on: October 21, 2013, 10:43:41 pm »
I just felt like there was a need for the click by click DAU guide, who knows on which tiny detail new people make a mistake. Maybe someone isn'n clicking the treeview at the right moment and sets only Release mode up and then compiles in Debug mode, maybe they add one of the libraries too high/low on the list, maybe someone forgets to set up the library search path. :)

Seven

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Build fails; 'undefined reference to..'
« Reply #8 on: October 21, 2013, 10:50:49 pm »
Follow this: http://en.sfml-dev.org/forums/index.php?topic=12552.0

Rebuild your project (not just build) and paste the complete output here.

-------------- Clean: Debug in test-sfml (compiler: GNU GCC Compiler)---------------

Cleaned "test-sfml - Debug"

-------------- Build: Debug in test-sfml (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall  -g    -IC:\SFML-2.1\include  -c N:\Programming\C++\Projects\test-sfml\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LC:\SFML-2.1\lib  -o bin\Debug\test-sfml.exe obj\Debug\main.o    -lsfml-network-d -lsfml-audio-d -lsfml-graphics-d -lsfml-window-d -lsfml-system-d -lopengl32
obj\Debug\main.o: In function `main':
N:/Programming/C++/Projects/test-sfml/main.cpp:5: undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
N:/Programming/C++/Projects/test-sfml/main.cpp:5: undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
N:/Programming/C++/Projects/test-sfml/main.cpp:5: undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
N:/Programming/C++/Projects/test-sfml/main.cpp:6: undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'
N:/Programming/C++/Projects/test-sfml/main.cpp:7: undefined reference to `_imp___ZN2sf5Color5GreenE'
N:/Programming/C++/Projects/test-sfml/main.cpp:7: undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'
N:/Programming/C++/Projects/test-sfml/main.cpp:15: undefined reference to `_imp___ZN2sf6Window5closeEv'
N:/Programming/C++/Projects/test-sfml/main.cpp:12: undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
N:/Programming/C++/Projects/test-sfml/main.cpp:18: undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'
N:/Programming/C++/Projects/test-sfml/main.cpp:18: undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
N:/Programming/C++/Projects/test-sfml/main.cpp:19: undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'
N:/Programming/C++/Projects/test-sfml/main.cpp:19: undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
N:/Programming/C++/Projects/test-sfml/main.cpp:20: undefined reference to `_imp___ZN2sf6Window7displayEv'
N:/Programming/C++/Projects/test-sfml/main.cpp:9: undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
N:/Programming/C++/Projects/test-sfml/main.cpp:23: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
N:/Programming/C++/Projects/test-sfml/main.cpp:23: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
N:/Programming/C++/Projects/test-sfml/main.cpp:23: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
obj\Debug\main.o: In function `ZN2sf11CircleShapeD1Ev':
C:/SFML-2.1/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `_imp___ZTVN2sf11CircleShapeE'
C:/SFML-2.1/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `_imp___ZTVN2sf11CircleShapeE'
C:/SFML-2.1/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `_imp___ZN2sf5ShapeD2Ev'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 2 seconds)
20 errors, 0 warnings (0 minutes, 2 seconds)
 

-SNIP-
I tried this, resulted in the same error messages. Thanks anyway.

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Build fails; 'undefined reference to..'
« Reply #9 on: October 21, 2013, 11:06:26 pm »
Can you tell the exact version of MinGW you are using atm and where/which SFML package you downloaded?

Seven

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Build fails; 'undefined reference to..'
« Reply #10 on: October 21, 2013, 11:11:37 pm »
MinGW; 4.8.1
SFML; 2.1
(Also, libgcc_s_dw2-1.dll if that helps)

Edit: 2.1, not 1.2
« Last Edit: October 21, 2013, 11:29:24 pm by Seven »

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Build fails; 'undefined reference to..'
« Reply #11 on: October 21, 2013, 11:24:19 pm »
I guess you mean 2.1, but did you get it from the SFML website? I think the SFML there is for gcc 4.7 and that could be a problem. The thread with the nightly builds is also for that version, but may get an update soon. http://en.sfml-dev.org/forums/index.php?topic=9513.0
I would try with the TDM MinGW 4.7.1 again and get the corresponding other SFML package from the nightly thread.
(Or try downgrading with the MinGW downloader thingy if you feel adventurous.)
(Or you could compile SFML yourself from the git version, but that needs cmake.)
« Last Edit: October 21, 2013, 11:26:11 pm by wintertime »

Seven

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Build fails; 'undefined reference to..'
« Reply #12 on: October 21, 2013, 11:39:10 pm »
YYYYYYYYYYYEEEEEEEEEEEEEEEEEEEEEEESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS!  ;D
I just re-downloaded SFML, and switched from the installed MinGW to the version supplied by CodeBlocks, and it works!
Thank you everyone, sorry for troubling you, and may I commend you on your excellent support.

Thanks a million,
Seven

Anagstrema

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Build fails; 'undefined reference to..'
« Reply #13 on: July 17, 2017, 10:06:57 am »
I can't believe how many people ask about project settings here, I hope more than one profits from my effort of writing this.

Hi, I would like to say really big thaks to you. You save my life. I was trying to run sfml in c::b for 2 days and yours tutorial is first which actually works for me.  :) :) :) :) :) :) :) :)

big_foot2010

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Build fails; 'undefined reference to..'
« Reply #14 on: December 10, 2021, 11:05:41 pm »
Hello! I have exactly the same error, and was wondering exactly how you managed to fix it in the end. I am trying to use Codeblocks 20.03, and believe I have a 64 bit version of MinGW, GCC ver 7.3.0. I have so far tried the sfml (2.5.1) download GCC 5.1.0 TDM (SJLJ) - Code::Blocks - 32-bit and GCC 7.3.0 MinGW (DW2) - 32-bit. Is there a different version I should be downloading? I do not feel I understand the 'the compilers must match 100%' rule :/

Edit, I've solved this now. For anyone finding this sub in the future, you cant run the 32-bit sfml if you are using the 64 bit codeblocks
« Last Edit: December 10, 2021, 11:17:31 pm by big_foot2010 »

 

anything