Author Topic: Problem with working directory and dynamic library path on OS X  (Read 4335 times)

Offline badday

  • Single posting newcomer
  • *
  • Posts: 3
Problem with working directory and dynamic library path on OS X
« on: September 24, 2011, 10:02:33 am »
Hi,

I´m actually working on porting some project to OS X using Code::Blocks. First of all, I use Code::Blocks for the Linux port as well - without any problems. I use the Mac Version 8.02-p2. I actually face two problems which might be strongly linked to each other:

1. Dynamic Library path set incorrectly
The following scenario: The project-file for the dynamic library is located in root/dir/subdir, the output-file is written to: root/bin. All paths are given relative, therefore output filename would be: ../../bin/lib.dynlib. The working directory of the dynlib is set to ../../bin. The project compiles and links as intended, alright so far. But now, as soon as I execute the binary it can´t find the dynlib. The working directory is ../bin, that´s the relative path from the binaries project file to the bin-folder. The thing is: According to the output, the dynamic linker tries to find  ../../bin/lib.dynlib, what is the output filename of the dynlib. It seems to treat it as a absolute path somehow. I cannot see this behavior under GNU/Linux.
I then thought I might tell the linker manually where to find the dynamic libs by setting the path manually in the linker options via
Code
-Wl,-rpath,../bin
But this didn´t change a thing. What temporarily fixed the thing is to set the dynlib path manually in the terminal session via
Code
DYLD_LIBRARY_PATH=<full path to bin folder>
But this is not really an option. Therefore: How can I fix this?


2. Working directory of libraries
I´m actually not sure whether this is a Code::Blocks-problem, but I guess it is somehow. The working directory (given by getwd()) of the binary is correctly the absolute version of /root/bin. But when I call this function from a library (surprisingly no matter whether this is a static or dynamic one), I get /root. I set the working directories of the dynamic libraries correctly, for instance  ../../bin for the above example (setting the relative path). I wonder how it finally becomes /root, I mean I could think of /root/dir/subdir or /root/bin as possible options, but why ../ ?



I tried to find the solution myself, but I couldn´t. I really hope someone can help me.


Thanks a lot & best Regards,

badday


PS: If further information is required, just let me know it ;)


Offline Freem

  • Almost regular
  • **
  • Posts: 218
Re: Problem with working directory and dynamic library path on OS X
« Reply #1 on: September 25, 2011, 04:31:09 pm »
I can't really help you, as I never used a mac to develop (I only used it once to try to help a friend with his newly acquired old mac computer... and it took me many times to just find bash...) but it seem CB is not well tested on MAC, because there is a lack of developer.

However, I guess that your version, with near 3 years and a half, is quite old. I browse a bit the forum and found that: http://forums.codeblocks.org/index.php/topic,15108.msg101721.html#msg101721
It seem that there is a nightly (or yearly as they said) build for mac, maybe it can be less buggy than the old one you are using?