Author Topic: LD_LIBRARY_PATH fix  (Read 10992 times)

Offline simonrodan

  • Single posting newcomer
  • *
  • Posts: 6
LD_LIBRARY_PATH fix
« on: June 06, 2010, 01:45:58 am »
The environment variable LD_LIBRARY_PATH has to be set for a program to know where to look for shared libraries at run time. Because Codeblocks seems to wipe out or ignore this setting, I've had problems running programs that use shared libraries from the IDE even though they run fine from a terminal window. I get this message:

"error while loading shared libraries: <library name>: cannot open shared object file: No such file or directory"   

So here is a workaround:

Look for the program "cb_console_runner" - it's in /usr/bin
Rename it cb_console_runner_bin
Create a shell script called "cb_console_runner" this will be called by Codeblocks
Add these lines:
#!/bin/bash
export LD_LIBRARY_PATH="your path here"
cb_console_runner_bin $1
make the script executable

Inelegant but it seems to work.
 


   

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: LD_LIBRARY_PATH fix
« Reply #1 on: June 06, 2010, 03:35:01 am »
First the basics: OS, CB version please ... the forum rules said you should provide them....

Do you have the paths to this library added to the project configuration in Project-> Build options -> Search directories -> Linker ?
If you have them there the console_runner or C::B will export the LD_LIBRARY_PATH variable for you.

Can you provide a simple test 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 Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: LD_LIBRARY_PATH fix
« Reply #2 on: June 06, 2010, 05:53:26 pm »
First the basics: OS, CB version please ... the forum rules said you should provide them....

Do you have the paths to this library added to the project configuration in Project-> Build options -> Search directories -> Linker ?
If you have them there the console_runner or C::B will export the LD_LIBRARY_PATH variable for you.

Can you provide a simple test project?

And what terminal do you use to run console-projects in ?
Some terminals seem not expand shell-variables (correctly) given on commandline.
« Last Edit: June 06, 2010, 05:57:08 pm by jens »

Offline simonrodan

  • Single posting newcomer
  • *
  • Posts: 6
Re: LD_LIBRARY_PATH fix
« Reply #3 on: June 27, 2010, 08:58:01 pm »
First the basics: OS, CB version please ... the forum rules said you should provide them....

Ubuntu 10.04 LTS
CodeBlocks 8.02 (Build Sept 13 2009)

Do you have the paths to this library added to the project configuration in Project-> Build options -> Search directories -> Linker ? If you have them there the console_runner or C::B will export the LD_LIBRARY_PATH variable for you.
Yes - the path the the library is defined in "Project-> Build options -> Search directories -> Linker"

Here is an example...
project "test", file "test.cpp"
Code
#include <iostream>
#include "testlib.h"

using namespace std;

int main()
{
cout << foobar() << endl;
cout << FooBar() << endl;

    return 0;
}
project definition file "test.cbp"
Code
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="test" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/test" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/test" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Linker>
<Add library="testlib" />
<Add directory="/work/lib" />
</Linker>
<Unit filename="test.cpp" />
<Extensions>
<code_completion />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>
project testlib, file "testlib.h"
Code
#ifndef TESTLIB_H_INCLUDED
#define TESTLIB_H_INCLUDED

#include <string>

using namespace std;

double foobar();

string FooBar();

#endif // TESTLIB_H_INCLUDED
project testlib, file "testlib.cpp"
Code
#include "testlib.h"

using namespace std;

double foobar()
{
return 1; // "Hello world";
}

string FooBar()
{
return "Hello world";
}
project definition file "testlib.cbp"
Code
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="testlib" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="/work/lib/libtestlib" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="3" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Option createStaticLib="1" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="/work/lib/libtestlib" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="3" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Option createStaticLib="1" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fPIC" />
</Compiler>
<Unit filename="testlib.cpp">
<Option compilerVar="CC" />
</Unit>
<Unit filename="testlib.h" />
<Extensions>
<code_completion />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>


And what terminal do you use to run console-projects in ?
Some terminals seem not expand shell-variables (correctly) given on commandline.


gnome-terminal  -t $TITLE -x

Hope this helps

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: LD_LIBRARY_PATH fix
« Reply #4 on: June 27, 2010, 10:38:35 pm »
Works fine here with gnome-terminal.

You can try to update to C::B 10.05 .

Offline simonrodan

  • Single posting newcomer
  • *
  • Posts: 6
Re: LD_LIBRARY_PATH fix
« Reply #5 on: June 29, 2010, 03:22:40 am »
Jens - thanks for testing with 10.05 and the suggestion to upgrade.

However, for simplicity I think I'll stay with 8.02 until Ubuntu adopts a later version, since my workaround, horrible though it is, does what I need.     

Simon

Offline Mauricio

  • Single posting newcomer
  • *
  • Posts: 3
Re: LD_LIBRARY_PATH fix
« Reply #6 on: December 11, 2023, 08:03:44 am »
I still have this problem, the fix did not resolve it... I am using AntiX Linux on an old Laptop.