Author Topic: C::B execution paths  (Read 12334 times)

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
C::B execution paths
« on: September 15, 2012, 10:40:32 pm »
I'm on Kubuntu 12.04 running C::B nightly build svn 8248 (from jens Lody repository).

My application uses boost that I have compiled from source and installed in a non-standard location. If I try to run the application from the command line I get the following error message at startup
Code
error while loading shared libraries: libboost_thread.so.1.51.0: cannot open shared object file: No such file or directory

This is all quite logical as I am using boost::thread and didn't include the directory where boost is installed in LD_LIBRARY_PATH.

But what is surprising, is that the application starts just fine from within Code::Blocks.
How does C::B find the boost shared object files, when I haven't really told it where to look?
« Last Edit: September 15, 2012, 11:33:35 pm by cacb »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: C::B execution paths
« Reply #1 on: September 15, 2012, 11:20:58 pm »
You have by specifying the path for the linker.
C::B uses it to modify the LD_LIBRARY_PATH variable.
C::B makes it work automagically.
(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 cacb

  • Lives here!
  • ****
  • Posts: 536
Re: C::B execution paths
« Reply #2 on: September 15, 2012, 11:51:21 pm »
You have by specifying the path for the linker.
C::B uses it to modify the LD_LIBRARY_PATH variable.
C::B makes it work automagically.

Ok, thanks. Now I understand.

I think that automagic behaviour is often confusing, although quite convenient for those who understand what is happening. Now that default compiler behaviour is to provide a full command line log, perhaps it would be an idea to also display the automagic modifications to LD_LIBRARY_PATH when running a program from within the IDE:

Now it says:
Checking for existence: /path/to/program
Executing: /path/to/program  (in /path/to/project/.)


It could be more explicit:
Checking for existence: /path/to/program
Added to LD_LIBRARY_PATH: /path/to/my/boost/lib
Executing: /path/to/program  (in /path/to/project/.)



Offline Freem

  • Almost regular
  • **
  • Posts: 219
Re: C::B execution paths
« Reply #3 on: September 20, 2012, 10:43:21 am »
If you enabled full debug logs, you will have, at least when you debug.

note: A 'recent' (2-3 months ago if I am right) modification made compilation logs full by default, but it have not been made for debug, as far as I know (and if your configuration is older it will not change anyway).
But it is doable: I did when having problems with debugger plug-in and wanted to try with command-line ;)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: C::B execution paths
« Reply #4 on: September 20, 2012, 08:25:05 pm »
note: A 'recent' (2-3 months ago if I am right) modification made compilation logs full by default, but it have not been made for debug, as far as I know (and if your configuration is older it will not change anyway).
Yes, and this won't change in the future, because the log slows down the debugging.
(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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: C::B execution paths
« Reply #5 on: September 22, 2012, 02:13:19 pm »
I'm playing with this patch: http://cmpt.benbmp.org/codeblocks/patches/path_env_log.patch
And the results are rather strange. The code to set the env variable seems to be executed after the command for launching the program.
I've tried both "Build & Run" and "Run".

Can someone test the patch on windows and paste the log from the "Build log" tab?
(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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: C::B execution paths
« Reply #6 on: September 23, 2012, 12:03:51 pm »
Can someone test the patch on windows and paste the log from the "Build log" tab?
I'll try, but from what I can say personally: In a private project of mine I had the issue that wxSetEnv is unreliable for some reason. So what I did was the following:
Code
bool mySetEnv(const wxString& name, const wxString& value)
{
  // The WX-way...
  bool success = wxSetEnv(name, value);

  // The MinGW-way...
  wxString putenv_var = name + wxT("=") + value;
#if wxUSE_UNICODE
  std::string stl_putenv_var = (const char*)putenv_var.mb_str(wxConvLocal);
#else
  std::string stl_putenv_var = putenv_var.c_str();
#endif
  char buffer[stl_putenv_var.length()+1]; memset(buffer, 0x00, sizeof(buffer));
  memcpy(buffer, stl_putenv_var.c_str(), stl_putenv_var.length());
  success &= ( putenv(buffer)==0 ); // returns 0 on success
  // success &= ( _putenv(stl_putenv_var.c_str())==0 );

  return success;
}// mySetEnv
...then (and only then!), all my low-level code that relies on envvars being set worked properly. You may face a similar issue here.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: C::B execution paths
« Reply #7 on: September 23, 2012, 12:49:07 pm »
I don't know it wxSetEnv works, but I think there is a logic error. As the setenv is called after the program (xterm+project executable) is executed. So there is no point in setting LD_LIBRARY_PATH there.
(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 Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: C::B execution paths
« Reply #8 on: September 23, 2012, 02:18:14 pm »
...I had the issue that wxSetEnv is unreliable ...

I too found that setting env vars via wxWidgets did *not* work.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: C::B execution paths
« Reply #9 on: September 23, 2012, 02:40:39 pm »
I too found that setting env vars via wxWidgets did *not* work.
Well sometimes it does, sometimes not. The envvar plugin within C::B works fine for me (as an example) which only used wxSetEnv. However, in my own application when I used it it did not work on Windows... or at least not all the time. I didn't find a pattern and didn't digged further into it, as my work-around (as posted) worked just fine.

but I think there is a logic error
Oh, I see...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: C::B execution paths
« Reply #10 on: December 08, 2012, 02:37:25 pm »
(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!]