Re: How to make a program look for dylibs other than /usr/local/lib?
Re: How to make a program look for dylibs other than /usr/local/lib?
- Subject: Re: How to make a program look for dylibs other than /usr/local/lib?
- From: "parag vibhute" <email@hidden>
- Date: Fri, 7 Dec 2007 21:09:14 +0530
I am also facing certain type of problem. I tried two ways. First scenario is as follows
1. Dynamic library's install name is /usr/lib/libopbx.dylib.
2. I set extension of source file (which is using that dynamic library) to cpp & placed that dynamic library at executable path.
3. In cpp file I am loading dynamic library at run time i.e. using dlopen, dlclose etc. functions.(i.e. treating dynamic library is dynamic dependant library)
3. Compilation is successful.
4. Now if I change extension to mm, it gives me error.
5. But with cpp, there is one function for which I get error "/usr/bin/ld: Undefined symbols:"
Second scenario is
1. Dynamic library's install name is /usr/lib/libopbx.dylib.
2. I set extension of source file (which is using that dynamic library) to mm & placed that dynamic library at root("/") path.
3. Now this time I am loading dyamic library at launch of my application using -l flag of gcc(i.e. treating dynamic library as dependant library)
3. Compilation is successful.
4. Now I set value of DYLD_LIBRARY_PATH to "/"
5. Run the code, it was successful.
4. And also I do not get error for the function which I was getting in first scenario.
I am using Xcode 2.4.1 to build the application.
My requirement is to avoid setting value of variable DYLD_LIBRARY_PATH; for that I require to follow first path but in that case I am getting error for a certain function. What should I do?
Thanks,
Palav
LStrange thing is my dynamic library's install name is /usr/lib/liboesis.dylib & if I set extension of my source file (which is using that dynamic library) to cpp & place my library at executable path then compilation is successful. But if I change that extension to mm then it does not, it gives error. Another problem is
On Dec 7, 2007 1:33 PM, Peter O'Gorman <
email@hidden> wrote:
Graham Reitz wrote:
> Thanks Peter that definitely has me in the right direction.
>
> Ok I can see the problem using otool -L
>
> The executable is still looking in the /usr/local/lib for the
> libmysqlpp.2.dylib file. I changed the Runpath Search Paths variable
> (-rpath) to a directory with the location of the libmysqlpp.2.dylib
> file(s) but it's not changing where the executable is looking for the
> dylib. Is there a way to change that at compile/link time?
When you created libmysqlpp.2.dylib, it was done, probably with
./configure; make; sudo make install so the prefix was set to /usr/local
, so it has an install_name of /usr/local/lib/libmysqlpp.2.dylib. You
will also have trouble with /sw/lib/mysql/libmysqlclient_r.15.dylib,
which was, I assume, built by fink.
The install_name is encoded in the library, it is like an soname on ELF
systems, except the install_name is usually an absolute path. If you
create a library with just the basename as the install_name (e.g the
install_name is libmysqlpp.2.dylib) then the dynamic linker will look
for it only in DYLD_FALLBACK_LIBRARY_PATH
($(HOME)/lib:/usr/local/lib:/lib:/usr/lib by default).
For this reason Apple originally came up with @executable_path. If you
set the install_name of the library to
@executable_path/libmysqlpp.2.dylib and relink your executable then the
dynamic linker will look for it in the same directory as the executable.
With 10.4 @loader_path was introduced, which allowed you to have
libraries reference each other relative to themselves rather than the
main executable.
And with 10.5 comes @rpath. If the install_name of your library is
@rpath/libmysqlpp.2.dylib and you link your executable with,
-Wl,-rpath,/home/graham/lib -Wl,-rpath,../lib -Wl,-rpath,. then th
dynamic linker will look for libmysqlpp.2.dylib in each dir in turn
until it finds it.
In each case, if you change the install_name of the library itself using
install_name_tool -id you must relink everything that uses the library
or change the references in the users too with install_name_tool -change.
This is all fairly well documented in the manpages for dyld(1) dyld(3)
ld(1), otool(1) and install_name_tool(1).
Peter
--
Peter O'Gorman
http://pogma.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
--
There are many things in your life that will catch your eye but only a few will catch your heart....pursue those'.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden