PDA

View Full Version : On Mac: "...file was built for unsupported file format.." - SOLVED



desertpilot
13th May 2010, 00:52
I'm trying to build a Qt application on Mac that statically links third-party libraries (i.e. boost, libjpeg).

I'm getting this linker warning for each library:

...
ld: warning: in ../../extern/libexif-0.6.19/libexif/.libs/libexif.a, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols:
"_exif_get_long", referenced from:
ExifTagParser::parseEntry(_ExifEntry*, ExifByteOrder) in sbexifinfo.o
...

So even though it's only a warning the linker refuses to use the library and ends up with undefined symbols.

I've downloaded and compiled the libraries with the default configuration on my Macbook Pro running Snow Leopard. Here are the relevant bits from my .pro file:


...
TEMPLATE = app
CONFIG += x86 debug_and_release qt warn_on thread
QT += network xml
LIBS += ../../extern/libexif-0.6.19/libexif/.libs/libexif.a
...
This happens with all static libraries I try to link. Anybody have an idea how to fix that?

Thanks much!

Holger

jkyle
13th May 2010, 02:02
The library you're liking to is not of the same architecture as the library your linking (./../extern/libexif-0.6.19/libexif/.libs/libexif.a).

libexif.a is an i386 arch. Check your build settings to ensure that you're building an i386 binary or recompile the libexif.a to match your build target arch.

fyi, If you're using Xcode, then by default Debug mode only builds your platforms native arch. So on a new mac, this would be an x86_64 binary.

desertpilot
13th May 2010, 05:34
The library you're liking to is not of the same architecture as the library your linking (./../extern/libexif-0.6.19/libexif/.libs/libexif.a).

libexif.a is an i386 arch. Check your build settings to ensure that you're building an i386 binary or recompile the libexif.a to match your build target arch.

fyi, If you're using Xcode, then by default Debug mode only builds your platforms native arch. So on a new mac, this would be an x86_64 binary.
Thanks for your help, jkyle! Turns out the libraries by default aren't i386 configured. Probably some multi-architecture mode that the linker doesn't recognize as i386 compatible. I don't see why, frankly. Anyway, I rebuilt the libraries with ./configure CC="gcc -arch i386" CXX="g++ -arch i386" and now the linker is happy. BTW, I'm using Qt Creator and it's building by default only x86. I tried x86_64 but the open source Qt 4.6 build isn't built with 64bit support. Don't need it anyway.

skizzik
13th October 2010, 14:46
How do you rebuild the libraries? I have the same problem but can't get it to work.

skyout
13th October 2010, 16:22
How do you rebuild the libraries? I have the same problem but can't get it to work.

That depends on which library. Each one had its own particular way it wanted to be configured for i386. I had to go through each documentation and follow the instructions. Most were happy with ./configure CC="gcc -arch i386" CXX="g++ -arch i386", but not all. Which library is giving you trouble?

skizzik
14th October 2010, 08:15
libboost_thread-mt.dylib
libboost_filesystem-mt.dylib
libboost_program_options-mt.dylib
libboost_system-mt.dylib

file libboost_thread-mt.dylib
gives:
libboost_thread-mt.dylib: Mach-O 64-bit dynamically linked shared library x86_64

WarGamer
20th June 2012, 16:15
I am having the same problem. Can someone tell me what to do with the line below? Where do I put it?

./configure CC="gcc -arch i386" CXX="g++ -arch i386"