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

Author Topic: Code Blocks and Ubuntu + Static linking  (Read 6328 times)

0 Members and 1 Guest are viewing this topic.

tillis

  • Newbie
  • *
  • Posts: 8
    • View Profile
Code Blocks and Ubuntu + Static linking
« on: April 25, 2012, 05:25:42 am »
Hi. I have two issues.

Firstly, I am trying to get SFML 1.6 to work using Code Blocks on Ubuntu. I have followed the codeblocks tutorial on the website. I've added "/home/tillis/SFML-1.6/include" in compiler directory and "/home/tillis/SFML-1.6/lib" to the linker directory. "tillis" being my actual user name. :P  In Linker settings I have added "-lsfml-system". I am trying to compile the clock sample.

Then I click build I get this message:   cannot find -lsfml-system

It does work when the sfml files are in the /usr/local/ directories. But I specifically want to link them from my own home directories.

Secondly,  even when SFML is in the /usr/local/ directories. I am trying to static link them using the "-lsfml-system-s" option, but this results in the error message "cannot find -lsfml-system-s".

What am I doing wrong here? : S
« Last Edit: April 25, 2012, 08:53:49 am by tillis »

jynks

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Code Blocks and Ubuntu + Static linking
« Reply #1 on: April 25, 2012, 06:04:57 am »
found this in search.... can you get it running at all?

Don't use static libraries on Linux, it will make things more complicated for you. Static libraries are useful only on Windows, other OSes manage shared libraries really well.

tillis

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Code Blocks and Ubuntu + Static linking
« Reply #2 on: April 25, 2012, 07:13:26 am »
I have an AMD GPU, So SFML 1.6 apps hang unless they are staticly linked. So I really need it at the moment.

I can get it running without the windows or graphics modules if the libs are in the /usr/local/ directories. But I would prefer it if they were in directories within my home folder.


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Code Blocks and Ubuntu + Static linking
« Reply #3 on: April 25, 2012, 07:59:28 am »
The ATI bug is only on Windows ;)

Quote
"/home/dean/SFML-1.6/lib"
If your home folder is "tillis", that would explain your problem :P
Laurent Gomila - SFML developer

tillis

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Code Blocks and Ubuntu + Static linking
« Reply #4 on: April 25, 2012, 09:01:21 am »
The ATI bug is only on Windows ;)

Quote
"/home/dean/SFML-1.6/lib"
If your home folder is "tillis", that would explain your problem :P

The directory names are all correct in code blocks. :P But code blocks just produces error messages saying it can't find "-lsfml-system" on Ubuntu.

As for my Windows install . Codeblocks is set up the same as on ubuntu, but it actually does find the libraries and compiles.  but when I try "-lsfml-system-s" it says it can't find "-lsfml-system-s".

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Code Blocks and Ubuntu + Static linking
« Reply #5 on: April 25, 2012, 09:12:59 am »
1. Like I said there should be no problem on Linux so you shouldn't need to use static libraries; your problem might be a different one

2. If the linker cannot find the library then you can trust him; check, re-check and re-re-check your project settings

3. Where did you get static SFML libraries for Linux?
Laurent Gomila - SFML developer

tillis

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Code Blocks and Ubuntu + Static linking
« Reply #6 on: April 25, 2012, 09:46:39 am »
If the ATI/AMD bug only effects windows than static wont be needed for linux. I've fixed the windows static problem, I re-read the tutorial and it seems codeblocks didn't have the right version of mingw  as default. ._.

How would I set gcc/g++ to check a directory in a terminal for the headers on Ubuntu?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Code Blocks and Ubuntu + Static linking
« Reply #7 on: April 25, 2012, 09:51:13 am »
Quote
How would I set gcc/g++ to check a directory in a terminal for the headers on Ubuntu?
Hmm? What do you mean?
Laurent Gomila - SFML developer

tillis

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Code Blocks and Ubuntu + Static linking
« Reply #8 on: April 26, 2012, 11:47:52 am »
Okay, everything is working fine on Windows now. But on Ubuntu I still have a linking issues. I have the clock.cpp sample. I have SFML 1.6 installed in /home/me/SFML-1.6/

In terminal I type the following:

g++ -c clock.cpp -I/home/me/SFML-1.6/include

This works fine. And produces clock.o.

Then I enter:   g++ clock.o -o clock -L/home/me/SFML-1.6/lib -lsfml-system

Which produces: /usr/bin/ld: cannot find -lsfml-system

The directory /home/me/SFML-1.6/lib has the following files within it.

libsfml-audio.so.1.6
libsfml-network.so.1.6
libsfml-window.so.1.6
libsfml-graphics.so.1.6
libsfml-system.so.1.6


Any ideas...?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Code Blocks and Ubuntu + Static linking
« Reply #9 on: April 26, 2012, 11:59:47 am »
For the linker to find -lsfml-system, there must be a libsfml-system.so file. This is not your case, your "lib" folder lacks the following symbolic links:
libsfml-system.so.1 -> libsfml-system.so.1.6
libsfml-system.so -> libsfml-system.so.1

You must create them.
Laurent Gomila - SFML developer

tillis

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Code Blocks and Ubuntu + Static linking
« Reply #10 on: April 26, 2012, 01:12:04 pm »
Yes. That has worked. It now compiles into a executable file. :)

I am a little confused on the next step. I have copied  libsfml-system.so.1.6 into say "/home/me/game/lib" and produced a  libsfml-system.so file in the same folder which links to  "/home/me/game/lib/libsfml-system.so.1.6" . the compile option "-L/home/me/game/lib/ -lsfml-system " works.


But when I attempt to execute the clock app by "./clock" it produces:

 ./clock: error while loading shared libraries: libsfml-system.so.1.6: cannot open shared object file: No such file or directory

I can run export "LD_LIBRARY_PATH=/home/me/game/lib" and it does work. But I want it to be fully portable. So it works on any ubuntu system that does not have SFML installed or the SFML LD path set up like that. In Windows I'd just put the .dll files into the same folder as the .exe file. What is needed in Ubuntu?

Thanks.
« Last Edit: April 26, 2012, 01:17:14 pm by tillis »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Code Blocks and Ubuntu + Static linking
« Reply #11 on: April 26, 2012, 01:43:30 pm »
If you put the SFML libraries in the executable directory:
Code: [Select]
export LD_LIBRARY_PATH=.;)
Laurent Gomila - SFML developer

tillis

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Code Blocks and Ubuntu + Static linking
« Reply #12 on: April 27, 2012, 09:09:45 am »
That works. :D :D

But I have come across another problem! When compiling SFML 1.6 from scratch. Following the tutorial here: http://www.sfml-dev.org/tutorials/1.6/start-linux.php

When I run the make command i get this:

make[1]: Entering directory `/home/me/SFML-1.6/src/SFML'
make[2]: Entering directory `/home/me/SFML-1.6/src/SFML/System'
g++ -shared -Wl,-soname,libsfml-system.so.1.6 -o ../../../lib/libsfml-system.so.1.6 Clock.o Lock.o Randomizer.o Sleep.o Unicode.o ./Unix/Initializer.o ./Unix/Mutex.o ./Unix/Platform.o ./Unix/Thread.o -lpthread
/usr/bin/ld: Unicode.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
Unicode.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [libsfml-system.so] Error 1
make[2]: Leaving directory `/home/me/SFML-1.6/src/SFML/System'
make[1]: *** [sfml-system] Error 2
make[1]: Leaving directory `/home/me/SFML-1.6/src/SFML'
make: *** [sfml] Error 2


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Code Blocks and Ubuntu + Static linking
« Reply #13 on: April 27, 2012, 12:14:08 pm »
Sorry, I have no idea about this error.
Laurent Gomila - SFML developer

tillis

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Code Blocks and Ubuntu + Static linking
« Reply #14 on: April 27, 2012, 12:18:03 pm »
Some googling suggests it's a 64bit linking issue. (I am on 64bit ubuntu) :P

Compiling them into static libs works fine, so long as the two instances of NULL are replaced with 0 inside /SFML-1.6/include/SFML/system/ResourcePtr.int.

Either way, I can use the dynamic libs that come with SFML or compile my own static. Both works fine thanks to your help. ^^

These strange quarks are fun. :P
« Last Edit: April 27, 2012, 12:22:49 pm by tillis »

 

anything