Author Topic: [SOLVED]"Cannot open shared object file ..." when running executable from C::B  (Read 19008 times)

Offline ejamsa

  • Single posting newcomer
  • *
  • Posts: 8
Hey guys,
I'm building a SFML application with C::B and encountered a problem which doesn't let me run the app within C::B.

When i press "Run" or "Build and run" I get error: "error while loading shared libraries: libsfml-system.so.2: cannot open shared object file: No such file or directory"
Project compiles and links fine. It seems to be dynamic linking issue. I've set LD_LIBRARY_PATH to point SFML libraries, so using command line to run my app, everything works fine.

Any thoughts on that?

PS! I'm using C::B 13.12 on Debian Wheezy. I don't think the C::B version matters much, because the same happened on 12.11 as well.
« Last Edit: December 10, 2013, 08:25:32 am by ejamsa »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #1 on: December 09, 2013, 04:25:56 pm »
If you look at the build log you'll what is the value of the LD_LIBRARY_PATH variable that C::B passes to your application. Is it correct?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ejamsa

  • Single posting newcomer
  • *
  • Posts: 8
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #2 on: December 09, 2013, 04:32:53 pm »
Build log shows the following:
Code
Executing: xterm -T test -e /usr/bin/cb_console_runner LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. /home/.../bin/Debug/test  (in /home/.../test/.)

when I executed it via command line, it worked fine!

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #3 on: December 09, 2013, 04:56:11 pm »
What path have you set in the linker options?
Exact one or one produced by a wrapper script like "pkg-config or sfml-config"?
I guess it is the latter.

Hint: C::B will append all linker search paths set in the project options. So if you add the path to the .so manually it should work.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ejamsa

  • Single posting newcomer
  • *
  • Posts: 8
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #4 on: December 09, 2013, 05:07:36 pm »
From
Settings->Compiler...->Search directores
i've added SFML's include and lib directories for compiler & linker respectively.

In project Build Options..->Linker settings->Other linker options:
Code
-lsfml-system
-lsfml-window
-lsfml-graphics

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #5 on: December 09, 2013, 05:11:37 pm »
Can you post a full rebuild log?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ejamsa

  • Single posting newcomer
  • *
  • Posts: 8
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #6 on: December 09, 2013, 05:21:48 pm »
Sure,
Code
-------------- Clean: Debug in test (compiler: GNU GCC Compiler)---------------

Cleaned "test - Debug"

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

g++ -Wall -g -std=c++11 -I/home/ejamsa/SFML-2.1/include -c /home/ejamsa/Projects/sfml/test/main.cpp -o obj/Debug/main.o
g++ -L/home/ejamsa/SFML-2.1/lib -o bin/Debug/test obj/Debug/main.o  -lsfml-system -lsfml-window -lsfml-graphics  ../../../SFML-2.1/lib/libsfml-system.so
Output file is bin/Debug/test with size 100.08 KB

Strange is that it complains about libsfml-system.so.2 (which is a symlink) not about libsfml-system.so (which is also symlink). The real library is libsfml-system.so.2.1!

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #7 on: December 09, 2013, 05:36:25 pm »
The linking command looks strange.
Could it be that you've overridden your libsfml-system.so by setting your project's output file to point there?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ejamsa

  • Single posting newcomer
  • *
  • Posts: 8
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #8 on: December 09, 2013, 05:44:08 pm »
Sorry, the correct output is
Code
-------------- Clean: Debug in test (compiler: GNU GCC Compiler)---------------

Cleaned "test - Debug"

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

g++ -Wall -g -std=c++11 -I/home/eero/SFML-2.1/include -c /home/eero/Projects/sfml/test/main.cpp -o obj/Debug/main.o
g++ -L/home/eero/SFML-2.1/lib -o bin/Debug/test obj/Debug/main.o  -lsfml-system -lsfml-window -lsfml-graphics  
Output file is bin/Debug/test with size 100.08 KB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))

The
Code
../../../SFML-2.1/lib/libsfml-system.so
from the previous post was my "hack" where I tried to add libsfml-system.so by selecting it in Settings->Compiler...->Linker settings->Link libraries:!

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #9 on: December 09, 2013, 06:17:12 pm »
Strange... C::B should have added "/home/ejamsa/SFML-2.1/lib"  to the LD_LIBRARY_PATH but it has not.
Can you try if C::B modifies the LD_LIBRARY_PATH with a simple console project?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ejamsa

  • Single posting newcomer
  • *
  • Posts: 8
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #10 on: December 09, 2013, 06:32:21 pm »
With simple console app it doesn't modify LD_LIBRARY_PATH during compilation/linking. As far as i can see from build log, LD_LIBRARY_PATH is modified only before running the app.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #11 on: December 09, 2013, 06:37:15 pm »
This is how it should work. LD_LIBRARY_PATH doesn't matter during compilation/linking. It is a runtime variable.

So if I understand correctly the simple project works as expected and the complex one doesn't?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ejamsa

  • Single posting newcomer
  • *
  • Posts: 8
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #12 on: December 09, 2013, 06:46:06 pm »
No, they work the same way regardless the project type!
When I run "complex one", I get
Code
-------------- Run: Debug in test (compiler: GNU GCC Compiler)---------------

Checking for existence: /home/ejamsa/Projects/sfml/test/bin/Debug/test
Executing: xterm -T test -e /usr/bin/cb_console_runner LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. /home/ejamsa/Projects/sfml/test/bin/Debug/test  (in /home/ejamsa/Projects/sfml/test/.)
Process terminated with status 0 (0 minute(s), 2 second(s))
Is it possible to print out LD_LIBRARY_PATH before it runs test program? It must be something to do with the LD_LIBRARY_PATH variable. If I open xterm and type
Code
echo $LD_LIBRARY_PATH
it displays /home/ejamsa/SFML-2.1/lib, which is correct directory

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: "Cannot open shared object file ..." when running executable from C::B
« Reply #13 on: December 09, 2013, 10:00:39 pm »
See how it should look:

Code

-------------- Build: Debug in stepping (compiler: GNU GCC Compiler)---------------

g++ -Wall -fexceptions -g -Werror=return-type -Woverloaded-virtual  -c /home/obfuscated/projects/tests/_cb_dbg/stepping/main.cpp -o .obj/debug/main.o
g++ -Wall -fexceptions -g -Werror=return-type -Woverloaded-virtual  -c /home/obfuscated/projects/tests/_cb_dbg/stepping/test.cpp -o .obj/debug/test.o
g++ -Wall -fexceptions -g -Werror=return-type -Woverloaded-virtual  -c /home/obfuscated/projects/tests/_cb_dbg/stepping/test_no_debug.cpp -o .obj/debug/test_no_debug.o
g++ -L/home/obfuscated/ -o bin/debug/stepping .obj/debug/main.o .obj/debug/test.o .obj/debug/test_no_debug.o   
Output file is bin/debug/stepping with size 29.06 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 4 warning(s) (0 minute(s), 0 second(s))
 

-------------- Run: Debug in stepping (compiler: GNU GCC Compiler)---------------

Checking for existence: /home/obfuscated/projects/tests/_cb_dbg/stepping/bin/debug/stepping
Executing: xterm -T stepping -g 200x80 -bg gray -fg black -e /usr/bin/cb_console_runner LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.:/home/obfuscated/ /home/obfuscated/projects/tests/_cb_dbg/stepping/bin/debug/stepping  (in /home/obfuscated/projects/tests/_cb_dbg/stepping/.)

I've added /home/obfuscated to the linker's search paths and as you can see it is set in LD_LIBRARY_PATH as it should.
I don't know why it doesn't work for you.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ejamsa

  • Single posting newcomer
  • *
  • Posts: 8
[SOLVED] "Cannot open shared object file ..." when running executable from C::B
« Reply #14 on: December 10, 2013, 08:20:50 am »
I got it to work finally!
It works if I right click project->Build options...->Search directories->Linker and add the directory there.
If I go Settings->Compiler...->Search directories->Linker and add linker search directory, then running the executable from C::B won't work as SFML's lib directory won't be added to LD_LIBRARY_PATH!

What i don't understand is that why such difference between global and project settings?
Also LD_LIBRARY_PATH should contain SFML's lib directory regardless of settings in C::B because I've added it to ~/.bashrc! This is the reason why i don't understand why
Code
Executing: xterm -T test -e /usr/bin/cb_console_runner LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. /home/ejamsa/Projects/sfml/test/bin/Debug/test  (in /home/ejamsa/Projects/sfml/test/.)
doesn't work as this command only appends current path to LD_LIBRARY_PATH

Thank you, oBFusCATed, for helping me to get it work!
If anyone knows answers to questions above, can you please shed some light on that?