Author Topic: What is done exactly by Build -> Run ?  (Read 5401 times)

Offline Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
What is done exactly by Build -> Run ?
« on: July 27, 2011, 01:45:04 pm »
Hi,

The question is in the title : on linux, what is the exact command line that C::B executes when I press Ctrl+F10 (or Build -> Run) ?
I guess that, like windows, it has to do with the "execution working dir", which I've set as the directory of the compiled executable.

My problem is, I use some .so that I've compiled myself and that are not present in the standard directories (/usr/lib, etc). Like in Windows, I've put them in the same directory as my executable.
When I run my program through C::B, everything works fine, but if I run it via the file manager, nothing shows up. If I run it manually using the console, it says it can't find any of the custom .so I'm using.

Am I doing something wrong ?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: What is done exactly by Build -> Run ?
« Reply #1 on: July 27, 2011, 02:53:07 pm »
C::B sets LD_LIBRARY_PATH for you.
In the console you should do export LD_LIBRARY_PATH="`pwd`:$LD_LIBRARY_PATH".
On unix (linux at least) the current directory is not in the library search paths, this is made for security.
(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 Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Re: What is done exactly by Build -> Run ?
« Reply #2 on: July 27, 2011, 03:33:57 pm »
Thank you !

I've searched for LD_LIBRARY_PATH, and found a supposedly better method : add "-Wl,-rpath,." to the linker options, and create a bash script in the program directory (assuming "prog" is the name of the program you want to run) :
Code
#!/bin/bash
cd `dirname $0`
./prog

The bash script is only necessary if you run "prog" outside of its own directory. Else, the linker option is sufficient.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: What is done exactly by Build -> Run ?
« Reply #3 on: July 27, 2011, 05:24:27 pm »
Wrong, the best way is to support autotools or something similar and then install you app in the proper location for the OS.

If you should have to use a script, it is easier to export LD_LIBRARY_PATH in the script. (this is what cb is doing (see run.sh in svn))


p.s. (Installing in the proper location can be done without using autotools too)
(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 Kalith

  • Multiple posting newcomer
  • *
  • Posts: 67
Re: What is done exactly by Build -> Run ?
« Reply #4 on: July 27, 2011, 08:57:41 pm »
Yes, but installing to the proper location is not always possible.
For example, I use my own version of some shared libraries. I could put them in a standard directory such as /usr/lib, but then all programs would use my own versions instead of the official ones, or my versions could be replaced by the original ones should I decide to (re-)install the official package.

About LD_LIBRARY_PATH, I found this webpage : [click], among others.

Offline Freem

  • Almost regular
  • **
  • Posts: 219
Re: What is done exactly by Build -> Run ?
« Reply #5 on: July 28, 2011, 10:52:30 am »
If you compiled them yourself, what about changing their name (I don't know, by adding "_kalith" at the end maybe)?
It should avoid to write on official ones if you copy them in /usr/lib, and your program, linked with that file, won't see any problem.
(I thought there was a directory to put "handbuilded" files and avoid mess in files managed by apt, but I can't retrieve those informations)

Btw, DLL HELL is not a microsoft trademark XD (ok, on linux distrib it only happen if you compile files yourself)
« Last Edit: July 28, 2011, 10:57:59 am by Freem »