Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: JHAx86 on November 07, 2010, 10:28:54 pm

Title: Launch a shell script within CB [Linux] [Solved]
Post by: JHAx86 on November 07, 2010, 10:28:54 pm
Since I'm using shared objects that lies in the same directory as my app main binary I need to launch the app by executing a simple shell script. While Windows will use dll files that lies in the same .exe directory, the same do not apply to Linux .so files, except the directory is in PATH but I do not want to add this directory to PATH.

The script ensures that .so files in the same directory that the main executable are used. But I have to launch the app by executing the script in a Terminal or from Nautilus, because clicking "run" button from CB will try to run the binary file, that will exit saying the needed .so files are not found.

It is possible to configure CB to execute the script before attempting to run the program?
Title: Re: Launch a shell script within CB [Linux]
Post by: Jenna on November 07, 2010, 10:43:12 pm
As far as I know not.
You can create a tool inside the "Tools"-menu or run the script from post-build steps, but that's not the same.

You can try to put
Code
-Wl,-rpath=.
in "Project -> Build options -> Linlker settings -> Other linker options:" to use shared libs that are in the same directory as the executable.
Title: Re: Launch a shell script within CB [Linux]
Post by: Jenna on November 07, 2010, 10:54:49 pm
As far as I know not.
You can create a tool inside the "Tools"-menu or run the script from post-build steps, but that's not the same.

You can try to put
Code
-Wl,-rpath=.
in "Project -> Build options -> Linlker settings -> Other linker options:" to use shared libs that are in the same directory as the executable.
:oops: forgotten: that should only be needed, if you want to run the exe from inside filemanager,
Inside C::B all search libs should be added to LD_LIBRARY_PATH before running the app, so if the exe's bin-directory is in the linkers include-path (that should be so to make the linker find the lib), C::B should add it automagically to LD_LIBRARY_PATH (just for running the exe inside C::B or in debugger-session).
Title: Re: Launch a shell script within CB [Linux]
Post by: JHAx86 on November 07, 2010, 11:27:19 pm
Yes, that solved my problem, thank you very much.

In resume, after reading the replies, I did this:

1- Add -Wl,-rpath=. to Other linker options
2- Add the output directory to linker include-path
3- Add the output directory to Execution working dir in Project properties

My first try, without step 3, didn't worked, because the default value in Execution working dir(.) means project file directory, no executable output directory.  :?

Now, if I remove step 1, clicking "run" in CB still launch the program and *.so files in the same directory are used as I wanted, but the app cannot be launch from Nautilus except you launch from the script. Depending how it evolve, maybe I will remove the script (It does not much anyway) and use -Wl,-rpath=..

Should I lock the topic?
Title: Re: Launch a shell script within CB [Linux]
Post by: Jenna on November 08, 2010, 07:41:49 am
Yes, that solved my problem, thank you very much.

In resume, after reading the replies, I did this:

1- Add -Wl,-rpath=. to Other linker options
2- Add the output directory to linker include-path
3- Add the output directory to Execution working dir in Project properties

My first try, without step 3, didn't worked, because the default value in Execution working dir(.) means project file directory, no executable output directory.  :?

Now, if I remove step 1, clicking "run" in CB still launch the program and *.so files in the same directory are used as I wanted, but the app cannot be launch from Nautilus except you launch from the script. Depending how it evolve, maybe I will remove the script (It does not much anyway) and use -Wl,-rpath=..

Should I lock the topic?
No need to do so, but you can add a "[solved]" to the title of the first post.