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

Author Topic: Trouble Linking DSFML...  (Read 9757 times)

0 Members and 1 Guest are viewing this topic.

mouse_poet

  • Newbie
  • *
  • Posts: 4
    • View Profile
Trouble Linking DSFML...
« on: February 04, 2015, 10:25:28 am »
I'm having trouble getting DSFML to link up correctly in Code::Blocks on my Linux Mint 17 x64 machine. I've tried building everything from source as per the tutorial(s) because I couldn't get the Nightlies to work, but to be honest I'm not really sure what I'm doing so I could be screwing up there without knowing it. Mainly I think I'm confused about what is referencing what in the tutorials and how I'd translate that to build options in my IDE of choice.

So, just to clarify or correct me:
  • Download or otherwise have on system:
  • Build using guide: https://github.com/Jebbs/DSFML/wiki/Building-DSFML-Libraries-From-Source%28Linux%29
    • Build SFML 2.0 static library as per these instructions http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php
      Generator: Unix Makefiles
      Compiler: Default Native
      Uncheck BUILD_SHARED_LIBS for static libs
      (I have no idea where to put -fPIC, make won't accept it, not sure where to put it in the cmake-gui?)
      Run make in the terminal at build location
    • Take file "<SFML static build directory>/cmake/Modules/FindSFML.cmake" and put it in "/usr/share/cmake-2.8/Modules"
    • Build DSFML-C shared library using same technique as for SFML 2.0
      Generator: Unix Makefiles
      Compiler: Default Native
      Quote
      Don't forget to select a static link to the Standard Libraries again!
      I'm not on Windows so SFML_USE_STATIC_STD_LIBS isn't an option so I can't turn it on... oh well...
      Quote
      CMake will say that it needs to know where the SFML include directory is, as well as the SFML static libraries. Let the system know the locations of these and you should be all set.
      cmake says none of that .___.; no errors so let's push on...
      Check BUILD_SHARED_LIBS for shared libs (we want these ones to be shared, right??)
      Run make in the terminal at build location
    • Build DFSML using Step 1 of https://github.com/Jebbs/DSFML/wiki/Building-Your-First-DSFML-Program%28Windows%29
      In terminal at <DFSML source directory> run rdmd build.d
  • Setup IDE (Code::Blocks) borrowing info from: https://github.com/Jebbs/DSFML/wiki/Building-Your-First-DSFML-Program%28Windows%29
    • File>>New>>Project>>D application
    • Project>>Build Options
      • Compiler: DMD
      • >>Linker Settings>>Link Libraries
        • dsfml-graphics
        • dsfml-system
        • dsfml-window
        • dsfml-audio
        • dsfml-network
        • dsfml-graphics-2
        • dsfml-system-2
        • dsfml-window-2
        • dsfml-audio-2
        • dsfml-network-2
      • >>Search Directories
        • >>Compiler
          • <DSFML source directory>/src
        • >>Linker
          • <DSFML source directory>/lib
          • <DSFML-C shared lib directory>/lib
    • Add main.d to project
      Add some code to file.
    • Build + Run Project
      All should work? Yes?
    • After weeks of trying and fiddling around with what links where and rebuilding everything ask internet for help...

I'm probably just missing something really simple and I've just misunderstood a part of something somewhere... If someone could show me where I'm going wrong that'd be a big help!

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Trouble Linking DSFML...
« Reply #1 on: February 04, 2015, 04:57:51 pm »
What issues did you have when building with the nightlies?

Also, the docs are written for the last stable version. The nightlies are for what is in the master branch, and until now I haven't had anyone that has mentioned a problem with them so I haven't gotten around to updating the docs. That's my fault. :(

One thing that isn't mentioned is that the back end library DSFML-C no longer required you to get sources for SFML and build that first or do any special set up. Building should work right out if the box.
DSFML - SFML for the D Programming Language.

mouse_poet

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Trouble Linking DSFML...
« Reply #2 on: February 04, 2015, 06:52:14 pm »
The problem I had with the nightlies... I've had trouble getting my compiler to find dsfml-graphics (etc) but able to locate dsfml-graphics-2 (etc), finding neither sets, undefined references, but I'm not sure which problems were with the nightlies and which were with trying other things out. I've kinda been at this a while .__.; and problems with this have been intermittent with compounding problems (I broke my PC editing fstab to run things from my usb among other things, lol). I tried getting dub to work a couple of times and it spat out a bunch of warnings about me using ~master instead of a number and I think I was getting Error 2 when I tried to build a project (I was getting Error 2 at some point at least), I tried again later with a different setup and couldn't even get it to find DSFML with the lflags path...

I'm pretty sure my problem is that I don't know enough about what I'm doing to set this up myself so anything open to interpretation in the docs is being misinterpreted by me and my complete lack of knowledge about compiling anything.

So what I should be doing is...
Do I need the above steps? Doesn't sound like I do but I'll ask just in case.
  • Grabbing the DSFML Linux 64bit Nightly from git https://github.com/Jebbs/DSFML
  • Add the DSFML Nightly folder to my Linker (and/or Compiler) directory in my D project build options
  • Add the following to my Link Libraries in my D project build options:
        dsfml-graphics
        dsfml-window
        dsfml-system
        dsfml-audio
        dsfml-network
        dsfml-graphics-2
        dsfml-window-2
        dsfml-system-2
        dsfml-audio-2
        dsfml-network-2
Boom should work, yes?

mouse_poet

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Trouble Linking DSFML...
« Reply #3 on: February 04, 2015, 09:11:39 pm »
So here are my errors right now with the nightlies...

DMD can't find anything and I'm not sure it's paying attention to the directories I've given in my IDE build options settings... manually adding them in the "Other Linker Options" section doesn't change anything.
Code: [Select]
-------------- Build: Debug in d_test_004 (compiler: Digital Mars D Compiler)---------------
dmd -ofbin/Debug/d_test_004  obj/Debug/main.o -L-ldsfml-graphics -L-ldsfml-window -L-ldsfml-system -L-ldsfml-audio -L-ldsfml-network -L-ldsfml-graphics-2 -L-ldsfml-window-2 -L-ldsfml-system-2 -L-ldsfml-audio-2 -L-ldsfml-network-2 -L-lpthread -L-lm -L-lphobos2
/usr/bin/ld: cannot find -ldsfml-graphics
/usr/bin/ld: cannot find -ldsfml-window
/usr/bin/ld: cannot find -ldsfml-system
/usr/bin/ld: cannot find -ldsfml-audio
/usr/bin/ld: cannot find -ldsfml-network
/usr/bin/ld: cannot find -ldsfml-graphics-2
/usr/bin/ld: cannot find -ldsfml-window-2
/usr/bin/ld: cannot find -ldsfml-system-2
/usr/bin/ld: cannot find -ldsfml-audio-2
/usr/bin/ld: cannot find -ldsfml-network-2
collect2: error: ld returned 1 exit status
--- errorlevel 1
GDC can't find the -2 libs.
Code: [Select]
-------------- Build: Debug in d_test_004 (compiler: GDC D Compiler)---------------
gdc -L/SFML/DSFML-nightly -L/usr/lib -o bin/Debug/d_test_004 obj/Debug/main.o   -ldsfml-graphics -ldsfml-window -ldsfml-system -ldsfml-audio -ldsfml-network -ldsfml-graphics-2 -ldsfml-window-2 -ldsfml-system-2 -ldsfml-audio-2 -ldsfml-network-2
/usr/bin/ld: cannot find -ldsfml-graphics-2
/usr/bin/ld: cannot find -ldsfml-window-2
/usr/bin/ld: cannot find -ldsfml-system-2
/usr/bin/ld: cannot find -ldsfml-audio-2
/usr/bin/ld: cannot find -ldsfml-network-2
collect2: error: ld returned 1 exit status
Even manually adding in -L-LDSFML/DIRECTORY etc to the additional options doesn't change the error:
Code: [Select]
gdc -L/SFML/DSFML-nightly -L/usr/lib -o bin/Debug/d_test_004 obj/Debug/main.o  -L-LSFML/DSFML-nightly -ISFML/DSFML-source/src -L-LSFML/DSFML-source/lib  -ldsfml-graphics -ldsfml-window -ldsfml-system -ldsfml-audio -ldsfml-network -ldsfml-graphics-2 -ldsfml-window-2 -ldsfml-system-2 -ldsfml-audio-2 -ldsfml-network-2._____.; Any clue on why it can't find the things? Am I meant to be linking to something else/somewhere else? Am I spelling the names wrong someplace? Am I missing a flag or... I don't even know...

In the terminal this will not give me an error and will create a file.
Code: [Select]
dmd main.d -I/SFML/DSFML-source/src -L-L/SFML/DSFML-source/lib -L-L/SFML/DSFML-nightly -L-ldsfml-graphics-2 -L-ldsfml-window-2 -L-ldsfml-system-2 -L-ldsfml-graphics -L-ldsfml-window -L-ldsfml-system -L-ljpeg -L-lGL -L-lGLU -L-lfreetype -L-lGLEW -L-lX11 -L-lXrandrBut trying to run the resulting file gives me "./main: error while loading shared libraries: libdsfml-graphics.so.2: cannot open shared object file: No such file or directory." Even copying and pasting the file into the directory where main.d resides gives the same message. Trying to run the same code but with GDC instead of DMD gives me a bunch of weird errors of this form:
Code: [Select]
/tmp/ccyf1hbg.o: In function `_Dmain':
main.d:(.text+0x9f): undefined reference to `_D5dsfml6window9videomode9VideoMode6__ctorMFNckkkZS5dsfml6window9videomode9VideoMode'
« Last Edit: February 04, 2015, 09:13:49 pm by mouse_poet »

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Trouble Linking DSFML...
« Reply #4 on: February 05, 2015, 07:00:58 pm »
If the compilers can't find the libraries, that means they either aren't in a standard search location or you aren't giving the right location to the linker.

You get it working in a terminal outside of the IDE, so that makes me think that Code::Blocks simply isn't searching for where they're located. Maybe you could try putting them in a standard search path? It's probably time I do some tutorials for common IDE's. I've opened up an issue on github so I don't forget.

Quote
"./main: error while loading shared libraries: libdsfml-graphics.so.2: cannot open shared object file: No such file or directory."

This is Linux saying that it doesn't know where to look for the shared libraries at run time. Try exporting the location of the libraries before running "./main"

Judging from what you posted already, this should work.

export LD_LIBRARY_PATH=/SFML/DSFML-nightly && ./main


Lastly, I don't use gdc so I can't really say much about it. If you wouldn't mind giving me your full command line that you used outside the IDE, I will look into that more and get back to you.
DSFML - SFML for the D Programming Language.

mouse_poet

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Trouble Linking DSFML...
« Reply #5 on: February 05, 2015, 11:38:00 pm »
: D that does work, thankyou!! Putting the files from the nightly into /usr/lib also works when building from the command line. DMD and GDC via Code::Blocks still can't find any of the libraries ending in -2... I messed around with both the global and project specific build options but I'm again not really sure what I'm doing and haven't stumbled across a fix for it in my IDE's settings.

Even with libs in /usr/lib GDC gives me the error below and does not output a file.
Code: [Select]
gdc main.d -I/SFML/DSFML-source/src -L-L/SFML/DSFML-source/lib -L-L/SFML/DSFML-nightly -L-ldsfml-graphics-2 -L-ldsfml-window-2 -L-ldsfml-system-2 -L-ldsfml-graphics -L-ldsfml-window -L-ldsfml-system -L-ljpeg -L-lGL -L-lGLU -L-lfreetype -L-lGLEW -L-lX11 -L-lXrandr
/tmp/ccLzt87z.o: In function `_Dmain':
main.d:(.text+0x9f): undefined reference to `_D5dsfml6window9videomode9VideoMode6__ctorMFNckkkZS5dsfml6window9videomode9VideoMode'
main.d:(.text+0xca): undefined reference to `_D5dsfml8graphics12renderwindow12RenderWindow7__ClassZ'
main.d:(.text+0xf6): undefined reference to `_D5dsfml6window15contextsettings15ContextSettings7DefaultxS5dsfml6window15contextsettings15ContextSettings'
main.d:(.text+0x109): undefined reference to `_D5dsfml8graphics12renderwindow12RenderWindow6__ctorMFS5dsfml6window9videomode9VideoModeAyaE5dsfml6window6window6Window5StyleKxS5dsfml6window15contextsettings15ContextSettingsZC5dsfml8graphics12renderwindow12RenderWindow'
main.d:(.text+0x112): undefined reference to `_D5dsfml8graphics11circleshape11CircleShape7__ClassZ'
main.d:(.text+0x12c): undefined reference to `_D5dsfml8graphics11circleshape11CircleShape6__ctorMFfkZC5dsfml8graphics11circleshape11CircleShape'
main.d:(.text+0x14a): undefined reference to `_D5dsfml8graphics5color5Color5GreenyS5dsfml8graphics5color5Color'
main.d:(.text+0x156): undefined reference to `_D5dsfml6system7vector214__T7Vector2TfZ7Vector26__initZ'
main.d:(.text+0x186): undefined reference to `_D5dsfml6system7vector214__T7Vector2TfZ7Vector26__ctorMFNaNbNcNfffZS5dsfml6system7vector214__T7Vector2TfZ7Vector2'
main.d:(.text+0x1c5): undefined reference to `_D5dsfml8graphics11circleshape11CircleShape7__ClassZ'
main.d:(.text+0x1df): undefined reference to `_D5dsfml8graphics11circleshape11CircleShape6__ctorMFfkZC5dsfml8graphics11circleshape11CircleShape'
main.d:(.text+0x1fd): undefined reference to `_D5dsfml8graphics5color5Color4BlueyS5dsfml8graphics5color5Color'
main.d:(.text+0x209): undefined reference to `_D5dsfml6system7vector214__T7Vector2TfZ7Vector26__initZ'
main.d:(.text+0x239): undefined reference to `_D5dsfml6system7vector214__T7Vector2TfZ7Vector26__ctorMFNaNbNcNfffZS5dsfml6system7vector214__T7Vector2TfZ7Vector2'
main.d:(.text+0x278): undefined reference to `_D5dsfml8graphics11circleshape11CircleShape7__ClassZ'
main.d:(.text+0x292): undefined reference to `_D5dsfml8graphics11circleshape11CircleShape6__ctorMFfkZC5dsfml8graphics11circleshape11CircleShape'
main.d:(.text+0x2b0): undefined reference to `_D5dsfml8graphics5color5Color4BlueyS5dsfml8graphics5color5Color'
main.d:(.text+0x2bc): undefined reference to `_D5dsfml6system7vector214__T7Vector2TfZ7Vector26__initZ'
main.d:(.text+0x2ec): undefined reference to `_D5dsfml6system7vector214__T7Vector2TfZ7Vector26__ctorMFNaNbNcNfffZS5dsfml6system7vector214__T7Vector2TfZ7Vector2'
main.d:(.text+0x32b): undefined reference to `_D5dsfml8graphics11circleshape11CircleShape7__ClassZ'
main.d:(.text+0x345): undefined reference to `_D5dsfml8graphics11circleshape11CircleShape6__ctorMFfkZC5dsfml8graphics11circleshape11CircleShape'
main.d:(.text+0x363): undefined reference to `_D5dsfml8graphics5color5Color3RedyS5dsfml8graphics5color5Color'
main.d:(.text+0x36f): undefined reference to `_D5dsfml6system7vector214__T7Vector2TfZ7Vector26__initZ'
main.d:(.text+0x39f): undefined reference to `_D5dsfml6system7vector214__T7Vector2TfZ7Vector26__ctorMFNaNbNcNfffZS5dsfml6system7vector214__T7Vector2TfZ7Vector2'
main.d:(.text+0x3e0): undefined reference to `_D5dsfml6system7vector214__T7Vector2TfZ7Vector26__initZ'
main.d:(.text+0x410): undefined reference to `_D5dsfml6system7vector214__T7Vector2TfZ7Vector26__ctorMFNaNbNcNfffZS5dsfml6system7vector214__T7Vector2TfZ7Vector2'
main.d:(.text+0x41f): undefined reference to `_D5dsfml8graphics14rectangleshape14RectangleShape7__ClassZ'
main.d:(.text+0x43b): undefined reference to `_D5dsfml8graphics14rectangleshape14RectangleShape6__ctorMFS5dsfml6system7vector214__T7Vector2TfZ7Vector2ZC5dsfml8graphics14rectangleshape14RectangleShape'
main.d:(.text+0x459): undefined reference to `_D5dsfml8graphics5color5Color5GreenyS5dsfml8graphics5color5Color'
main.d:(.text+0x465): undefined reference to `_D5dsfml6system7vector214__T7Vector2TfZ7Vector26__initZ'
main.d:(.text+0x495): undefined reference to `_D5dsfml6system7vector214__T7Vector2TfZ7Vector26__ctorMFNaNbNcNfffZS5dsfml6system7vector214__T7Vector2TfZ7Vector2'
main.d:(.text+0x502): undefined reference to `_D5dsfml6window5event5Event6__initZ'
main.d:(.text+0x510): undefined reference to `_D5dsfml6window5event5Event6__initZ'
main.d:(.text+0x58a): undefined reference to `_D5dsfml8graphics5color5Color5BlackyS5dsfml8graphics5color5Color'
main.d:(.text+0x59e): undefined reference to `_D5dsfml8graphics12renderstates12RenderStates7DefaultFNdZS5dsfml8graphics12renderstates12RenderStates'
main.d:(.text+0x634): undefined reference to `_D5dsfml8graphics12renderstates12RenderStates7DefaultFNdZS5dsfml8graphics12renderstates12RenderStates'
main.d:(.text+0x6ca): undefined reference to `_D5dsfml8graphics12renderstates12RenderStates7DefaultFNdZS5dsfml8graphics12renderstates12RenderStates'
main.d:(.text+0x760): undefined reference to `_D5dsfml8graphics12renderstates12RenderStates7DefaultFNdZS5dsfml8graphics12renderstates12RenderStates'
main.d:(.text+0x7f6): undefined reference to `_D5dsfml8graphics12renderstates12RenderStates7DefaultFNdZS5dsfml8graphics12renderstates12RenderStates'
/tmp/ccLzt87z.o:(.data+0x10): undefined reference to `_D5dsfml8graphics12__ModuleInfoZ'
/tmp/ccLzt87z.o:(.data._D87TypeInfo_S3std8typecons50__T10RebindableTyC5dsfml8graphics7texture7TextureZ10Rebindable6__initZ[_D87TypeInfo_S3std8typecons50__T10RebindableTyC5dsfml8graphics7texture7TextureZ10Rebindable6__initZ]+0x38): undefined reference to `_D3std8typecons50__T10RebindableTyC5dsfml8graphics7texture7TextureZ10Rebindable11__xopEqualsFKxS3std8typecons50__T10RebindableTyC5dsfml8graphics7texture7TextureZ10RebindableKxS3std8typecons50__T10RebindableTyC5dsfml8graphics7texture7TextureZ10RebindableZb'
/tmp/ccLzt87z.o:(.data._D85TypeInfo_S3std8typecons48__T10RebindableTyC5dsfml8graphics6shader6ShaderZ10Rebindable6__initZ[_D85TypeInfo_S3std8typecons48__T10RebindableTyC5dsfml8graphics6shader6ShaderZ10Rebindable6__initZ]+0x38): undefined reference to `_D3std8typecons48__T10RebindableTyC5dsfml8graphics6shader6ShaderZ10Rebindable11__xopEqualsFKxS3std8typecons48__T10RebindableTyC5dsfml8graphics6shader6ShaderZ10RebindableKxS3std8typecons48__T10RebindableTyC5dsfml8graphics6shader6ShaderZ10RebindableZb'
/tmp/ccLzt87z.o:(.data._D81TypeInfo_S3std8typecons44__T10RebindableTyC5dsfml8graphics4font4FontZ10Rebindable6__initZ[_D81TypeInfo_S3std8typecons44__T10RebindableTyC5dsfml8graphics4font4FontZ10Rebindable6__initZ]+0x38): undefined reference to `_D3std8typecons44__T10RebindableTyC5dsfml8graphics4font4FontZ10Rebindable11__xopEqualsFKxS3std8typecons44__T10RebindableTyC5dsfml8graphics4font4FontZ10RebindableKxS3std8typecons44__T10RebindableTyC5dsfml8graphics4font4FontZ10RebindableZb'
collect2: error: ld returned 1 exit status

In any case, I now have a way to get it working, so thankyou again!

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Trouble Linking DSFML...
« Reply #6 on: February 06, 2015, 01:05:49 am »
If it works with dmd but not gdc then that leads me to believe that static libraries are incompatible between the two compilers.

Creating an option for building them with gdc and ldc are on my todo list though, so it will come soon.
DSFML - SFML for the D Programming Language.

 

anything