Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: amarty on September 17, 2008, 12:41:21 am
-
Hello!
I have a workspace with two projects - one is shared library libmy.so, another is exe my, output directory is same for both. I add $(TARGET_OUTPUT_DIR) to library search path for linking executable, and it's linked good. Then I try to run executable and get error: libmy.so not found. I think I need to modify option "Terminal to run console programs" and add to LD_LIBRARY_PATH output directory of my projects, but I don't know how to do this. Anybody can help me?
I wrote next script:
#!/bin/bash
# cbrun title command args ...
# set up Codeblocks parameter - terminal to launch console program - cbrun $TITLE
dirname()
{
local dir="${1%${1##*/}}"
[ "${dir:=./}" != "/" ] && dir="${dir%?}"
echo "$dir"
}
title=$1
shift
command=$2
dir=`dirname "$command"`
PATH=`echo $dir`:$PATH
LD_LIBRARY_PATH=`echo $dir`:$LD_LIBRARY_PATH
export PATH
export LD_LIBRARY_PATH
xterm -T "$title" -e $@
#xterm -T "$dir" -e $@
place it to /usr/bin and set up the Codeblocks parameter (Settings/Environment) - terminal to launch console program - cbrun $TITLE
it runs, but the same error occurs - error while loading shared libraries: libmy.so: cannot open shared object file: no such file or directory.
I run xterm manualy. go to output dir. run ./my - lib not found
Next, I wrote script:
#!/bin/bash
export PATH=`echo $PWD`:$PATH
export LD_LIBRARY_PATH=`echo $PWD`:$LD_LIBRARY_PATH
my
It works good. How can I get the same result from Codeblocks environment?
-
Setting up "Execution working directory" in Project properties/Build targets does not work too.
-
I found plugin EnvVar (in Settings/Environment/Environment variables) and try to set up LD_LIBRARY_PATH as:
LD_LIBRARY_PATH=$(TARGET_OUTPUT_DIR):$LD_LIBRARY_PATH
but it isn't work too.
-
I found plugin EnvVar (in Settings/Environment/Environment variables) and try to set up LD_LIBRARY_PATH as:
LD_LIBRARY_PATH=$(TARGET_OUTPUT_DIR):$LD_LIBRARY_PATH
but it isn't work too.
Accessing macro variables within the envvars plugin is not supported (because it would be hard to distinguish if it's a environment variable *or* an internal one)... But hey - that's a nice idea for a feature to implement. :-)
Ooops - it *is* implemented (completely forgotten I did that :oops:). But it's probably not working because the C::B core modifies this variable, too. In addition the variable might be resolvable at the stage you are trying to access it.
-
Accessing macro variables within the envvars plugin is not supported (because it would be hard to distinguish if it's a environment variable *or* an internal one)... But hey - that's a nice idea for a feature to implement. :-)
As sample, sintax of environment variable usage can be changed - $VAR, $(VAR) - C::B var, #VAR, #(VAR) - environment variable. after substitution of C::B var simple change # to $.
It seems that I have found solution of my problem. I have set launch terminal string to [konsole --name "$TITLE" -e] and have set program working directory (Execution working dir) to output directory, where exe and .so located. But how can I use exe and .so in different folders, or change working dir to another path, I don't know.
-
TOOL CHAIN:
Code::Blocks 8.02 Build: Feb 27 2008, 21:58:34 - wx2.8.7 (Linux, unicode)
gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
[Did I miss anything?]
PROBLEM:
I have a similar setup, but a slightly different problem. I have a workspace with 2 projects. Project A: creates a shared (dynamic?) library (MyLib.so). Project B: creates a console application.
I build Project A, with no problem. I see MyLib.so in the output directory.
I try to have Project B link MyLib.so, but I always get the following output in the "Build log":
-------------- Build: Debug in VideoSvrLinux ---------------
Linking console executable: bin/Debug/MyConsoleApp
/usr/bin/ld: cannot find -lMyLib.so
collect2: ld returned 1 exit status
So my console application (Project B) does not even link.
QUESTION: does someone have a very simple example of a Workspace, Project File, Source file that I can use a starting point?
QUESTION: is Code::Blocks "Dynamic library" the same thing as a "Shared Library"?
Project A creates a shared library.
Project B links in that shared library.
Thank in advance.
NOTES:
* tried copying MyLib.so to /usr/local/lib and edited the /etc/ld.so.conf to include that path; no success
* previously Project A was just generating a Static library (libMyLib.a) and I could link against that no problem.
-
Add the path where the dynamic (shared) library gets created as linker searchpath for your console app.
-
Tried that. Both a relative path and fixed path with no success.
-
I'm not a Unix or Linux expert, but isn't LD_LIBRARY_PATH only used for compiling and linking? Don't you need to use LD_RUN_PATH when executing the program?
Ringo
-
I run in the same problem and since i couldn't find solution on this forum i decided to post one.
The problem is that xterm do not propagate environment variables.
So i use the following script
#!/bin/bash
# usage: cbrun title args
xterm -T $1 -e bash -c 'export LD_LIBRARY_PATH=$0;shift;$@' $LD_LIBRARY_PATH $@
To use set up Codeblocks parameter (Settings/Environment) - terminal to launch console program:
<path_to_script> $TITLE
I tried to make it work directly from parameter (without script) but it become too complex. Maybe i just miss something.
---------
And about second one. For some reason C::B doesn't add "lib" prefix to dynamic libraries but linker expect it. Just add it by hand (so output of project A become libMyLib.so). (But i think this problem was solved lOOng ago.)
-
I have this problem now, the fix did not resolve it for me...