User forums > Using Code::Blocks

C::B/Linux - run console and LD_LIBRARY_PATH

(1/3) > >>

amarty:
 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:


--- Quote ---#!/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 $@

--- End quote ---

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:

--- Quote ---#!/bin/bash
export PATH=`echo $PWD`:$PATH
export LD_LIBRARY_PATH=`echo $PWD`:$LD_LIBRARY_PATH
my

--- End quote ---

It works good. How can I get the same result from Codeblocks environment?

amarty:
 Setting up "Execution working directory" in Project properties/Build targets does not work too.

amarty:
I found plugin EnvVar (in Settings/Environment/Environment variables) and try to set up LD_LIBRARY_PATH as:

--- Quote ---LD_LIBRARY_PATH=$(TARGET_OUTPUT_DIR):$LD_LIBRARY_PATH

--- End quote ---
but it isn't work too.

MortenMacFly:

--- Quote from: amarty on September 17, 2008, 03:38:04 pm ---I found plugin EnvVar (in Settings/Environment/Environment variables) and try to set up LD_LIBRARY_PATH as:

--- Quote ---LD_LIBRARY_PATH=$(TARGET_OUTPUT_DIR):$LD_LIBRARY_PATH

--- End quote ---
but it isn't work too.

--- End quote ---
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.

amarty:

--- Quote from: MortenMacFly on September 17, 2008, 03:54:08 pm ---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. :-)

--- End quote ---

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.

Navigation

[0] Message Index

[#] Next page

Go to full version