News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

[SOLVED]"Cannot open shared object file ..." when running executable from C::B

Started by ejamsa, December 09, 2013, 03:53:18 PM

Previous topic - Next topic

ejamsa

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.

oBFusCATed

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!]

ejamsa

Build log shows the following:
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!

oBFusCATed

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!]

ejamsa

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:
-lsfml-system
-lsfml-window
-lsfml-graphics


oBFusCATed

(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!]

ejamsa

Sure,

-------------- 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!

oBFusCATed

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!]

ejamsa

Sorry, the correct output is
-------------- 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
../../../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:!

oBFusCATed

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!]

ejamsa

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.

oBFusCATed

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!]

ejamsa

No, they work the same way regardless the project type!
When I run "complex one", I get
-------------- 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
echo $LD_LIBRARY_PATH
it displays /home/ejamsa/SFML-2.1/lib, which is correct directory

oBFusCATed

See how it should look:



-------------- 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!]

ejamsa

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
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?