PDA

View Full Version : qwt DYLD_LIBRARY_PATH on MacOsX



dup
15th July 2007, 15:43
Hello
I ve got some troubles with qwt on Mac OsX. I succesfully install libs and headers in /usr/local/qwt-5.0.2,
but when I build my project (with xcode making qmake -spec macx-xcode app.pro) i ve got the message:
dyld: Library not loaded: libqwt.5.dylib
I guess it is a problem with an environment variable ??
(I define DYLD_LIBRARY_PATH in my .Bashrc)
Has anyone has an idea about what i could do ?

skaiser
16th July 2007, 22:55
The only way way I have found to set an environment variable that Xcode knows about is to set it within Xcode itself.

Assuming you added this to your .pro file before you called qmake to create your Xcode project:
LIBS += -L/usr/local/qwt/lib -lqwt

Expand the "Executables" node in the Groups & Files list,
select your executable, Get Info on it,
go to the Arguments tab, and manually add
DYLD_LIBRARY_PATH for the "Name" and
/usr/local/qwt/lib (or whatever is appropriate for you) for the "Value".

I have tried all the other methods including .profile and .MacOS environment.plist settings, and could not get Xcode to recognize any of them. Only setting DYLD_LIBRARY_PATH inside Xcode works for me.

Bad news: you have to do this manually every time you create a new xcode project with qmake -spec macx-xcode. And since Xcode also does not have a way of making C++ files moc'able, you have to create a new xcode project every time you want to add a C++ file or header to your project. Using Xcode with Qt no fun unless you enjoy this kind of brain dead manual labor.

Since I am brain dead, and really like Qt, I forged on and decided to put the source code for the qwt library in my project directly, which eliminated having to setup DYLD_LIBRARY_PATH manually every time. This works. Use the source, Luke!

Then I went to the Dark Side. I decided to get rid of qwt all together and just write some simple classes for the technical plotting I need to do. For me personally, sad to say, but this actually is far easier and faster than trying to figure out all these undocumented issues.

Steve

dup
17th July 2007, 01:04
thanks very much indeed !!!
I think you almost solve my problem. I do not have anymore the message concerning the
library not loaded. But i still cannot open my app from the finder. The only way to open
it is with terminal: open myapp.app
strange ??

skaiser
17th July 2007, 03:25
Yes, this bug is strange, but that is beside the point. :) I would more accurately describe it as a curveball.

Try this:
1. with ctrl key down, click the mouse on your app and choose "Show Package Contents" from the popup menu.
2. tunnel into the "Contents" directory, and double-click on "Info.plist". This should launch the Property List Editor application.
3. Expand the "Root" Property List, and change the Value of CFBundleExecutable to the exact name of your application (without any .app extension). The current Value is probably the name of your application in quotes. Remove the quotes.

By the way, ignore the NOTE in the Property List that says "Please, do NOT change this file - It was generated by Qt/QMake." This is false bravado.

Either directly with the Property List Editor or from within Xcode, you should change the original Info.plist file in your project directory that gets copied into your application bundle. This file is the start and source of the bug. Next time you run qmake the problem may be back again of course.

In general, you may find these links informative on related macintosh matters:
http://doc.trolltech.com/4.3/deployment-mac.html
http://doc.trolltech.com/4.3/qtmac-as-native.html
http://doc.trolltech.com/4.3/mac-differences.html
http://qtnode.net/wiki?title=Distributing_Mac_Qt_applications

The bash script at qtnode.net by Thomas Keller is noteworthy.

Steve

dup
17th July 2007, 08:00
thank you Steve fot this prompt and precise reply and all the references. Actually I still have my problem. As you mentionned i checked the .plist which seems correct as far the Value of CFBundleExecutable is concerned. This is the exact name of my application without any quotes. After building process i cannot open my app by double clicking. Please note that i ve got the same problem even if i don't use xcode i.e. :
qmake -spec macx-g++ myapp.pro
make
what do you think ?

skaiser
17th July 2007, 20:06
Rats... Oh well then.. I don't know. It's been a while since I included qwt, but I do remember I never did like what I had to do to get it to work so I removed it... and never really understood what I was doing.

I think I wound up modifying the Thomas Keller script (which copies all the libraries into the your application's bundle) to add qwt. If I just wanted to copy the qwt library into my bundle, I would do something like this (you might try it just to see if this fixes your problem):

// copy library into bundle:
mkdir DupsApplication.app/Contents/Frameworks
cp /usr/local/qwt/lib/libqwt.5.dylib DupsApplication.app/Contents/Frameworks/

// change library:
install_name_tool -id @executable_path/../Frameworks/libqwt.5.dylib DupsApplication.app/Contents/Frameworks/libqwt.5.lib

// change executable:
install_name_tool -change libqwt.5.dylib @executable_path/../Frameworks/libqwt.5.dylib DupsApplication.app/Contents/MacOS/DupsApplication

Sorry if I am sending you down the wrong road. If there are any MacOS users out there, please chime in. You don't have to be a guru-- just post what little tidbit you know, and maybe all together we can figure out the undocumented truth.

If particular, if anyone ever figures out how to properly set environment variables so that your MacOS application can use the default Qt and qwt binaries as they are installed in their default locations, please post your findings. I would dearly like to understand this process.

Steve

dup
17th July 2007, 21:08
thank you Steve !!!
This time it's ok, it is working fine ! I must admit i didn't understood everything
in the code you gave me, not so easy. I keep working on it and on the references
you mentionned.
thanks again
Nicolas

dup
29th July 2007, 17:12
After long hours on google i found an interesting link for the qwt installation:
http://www.fhi-berlin.mpg.de/~jochen/Computer/MacTips

First you define in .MacOS/environment.plist two environment variables CPLUS_INCLUDE_PATH and DYLD_LIBRARY_PATH both set to /usr/local/qwt/lib.
After that you just change the identification name of the dynamic library with sudo install_name_tool -id /usr/local/qwt/lib/libqwt.5.dylib /usr/local/qwt/lib/libqwt.5.0.0.dylib and it works fine ! No need to define DYLD_LIBRARY_PATH inside xcode and to copy the library in the bundle.

windsword
24th November 2008, 14:16
After long hours on google i found an interesting link for the qwt installation:
http://www.fhi-berlin.mpg.de/~jochen/Computer/MacTips

First you define in .MacOS/environment.plist two environment variables CPLUS_INCLUDE_PATH and DYLD_LIBRARY_PATH both set to /usr/local/qwt/lib.
After that you just change the identification name of the dynamic library with sudo install_name_tool -id /usr/local/qwt/lib/libqwt.5.dylib /usr/local/qwt/lib/libqwt.5.0.0.dylib and it works fine ! No need to define DYLD_LIBRARY_PATH inside xcode and to copy the library in the bundle.
Where do you find the ".MacOS/environment.plist" to edit it and add the variable?

// Sal

windsword
24th November 2008, 14:44
After long hours on google i found an interesting link for the qwt installation:
http://www.fhi-berlin.mpg.de/~jochen/Computer/MacTips

First you define in .MacOS/environment.plist two environment variables CPLUS_INCLUDE_PATH and DYLD_LIBRARY_PATH both set to /usr/local/qwt/lib.
After that you just change the identification name of the dynamic library with sudo install_name_tool -id /usr/local/qwt/lib/libqwt.5.dylib /usr/local/qwt/lib/libqwt.5.0.0.dylib and it works fine ! No need to define DYLD_LIBRARY_PATH inside xcode and to copy the library in the bundle.
ok, I created the environment.plist file under my ~/.MacOS/ and then executed the command sudo install_name_tool and when I run my app I get this messg:

../bin/simple.app/Contents/MacOS/simple dyld: Library not loaded: libqwt.5.dylib
Referenced from: /Users/sal/Downloads/qwt-5.1.1/examples/simple_plot/../bin/simple.app/Contents/MacOS/simple
Reason: image not found
Trace/BPT trap

so I'm probably not doing something right --still. Any advice?

// Sal

asgr
10th January 2009, 02:44
Apparently one should forget about DYLD_LIBRARY_PATH, as it is an unfavourable method for defining library paths on the Mac. It caused no end of conflicts when compiling.

The following EV are from the gcc users manual and perform the same objective.

C_INCLUDE_PATH
CPLUS_INCLUDE_PATH
LIBRARY_PATH

Personally, I use the command line, so these variables are defined in my global bash profile (/etc/profile). I use both the C and CPLUS variables just in case the compiler differentiates between the two source code files. Essentially the path is the same for the two variables, i.e.

# /etc/profile
export C_INCLUDE_PATH=/paths/to/your:/include/files
export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH
export LIBRARY_PATH=/what/ever/you/did:/for/DYLD_LIBRARY_PATH

Also for posterity, the -I (include) and -L (lib) compiler flags seem to have problems finding required files and libraries on the Mac. But since I adopted the gcc EV I've had absolutely no problems.

A.