问题
I'm attempting to cross compile this C library as an iOS library, i.e., for an armv7 machine. I'm using an OSX machine to compile the library. The project is setup to use Autoconf - here are the options i'm using :
./configure --host=arm-apple-darwin --prefix ~/dev/xmlrpc-c-1.25.28/iOS_bin_arm CFLAGS="-arch armv7s -isysroot /Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk -miphoneos-version-min=4.0" --disable-curl-client --disable-cplusplus LDFLAGS='-arch armv7s -miphoneos-version-min=4.0 --sysroot /Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk'
This compiles fine. The problem occurs in the linking stage:
ld: warning: ignoring file parse_datetime.osh, file was built for armv7s which is not the architecture being linked (x86_64): parse_datetime.osh
ld: warning: ignoring file parse_value.osh, file was built for armv7s which is not the architecture being linked (x86_64): parse_value.osh
ld: warning: ignoring file resource.osh, file was built for armv7s which is not the architecture being linked (x86_64): resource.osh
ld: warning: ignoring file trace.osh, file was built for armv7s which is not the architecture being linked (x86_64): trace.osh
ld: warning: ignoring file version.osh, file was built for armv7s which is not the architecture being linked (x86_64): version.osh
ld: warning: ignoring file xmlrpc_data.osh, file was built for armv7s which is not the architecture being linked (x86_64): xmlrpc_data.osh
ld: warning: ignoring file xmlrpc_datetime.osh, file was built for armv7s which is not the architecture being linked (x86_64): xmlrpc_datetime.osh
ld: warning: ignoring file xmlrpc_string.osh, file was built for armv7s which is not the architecture being linked (x86_64): xmlrpc_string.osh
and so on. The dylib files generated are built for x86 instead of armv7, which is the architecture my iOS application will link against - Xcode throws these errors when trying to build the project :
ld: warning: ld: warning: ld: warning: ignoring file ~/dev/xmlrpc-c-1.25.28/iOS_bin_arm/lib/libxmlrpc_server_pstream++.7.25.dylib, file was built for x86_64 which is not the architecture being linked (armv7): ~/dev/xmlrpc-c-1.25.28/iOS_bin_arm/lib/libxmlrpc_server_pstream++.7.25.dylib
ignoring file ~/dev/xmlrpc-c-1.25.28/iOS_bin_arm/lib/libxmlrpc_server_cgi++.dylib, file was built for x86_64 which is not the architecture being linked (armv7):~/dev/xmlrpc-c-1.25.28/iOS_bin_arm/lib/libxmlrpc_server_cgi++.dylib
and so on for every executable generated earlier using ./configure
and make
.
Obviously, when I test my code on the simulator, all is well, since there are no cross-compilation issues.
I even tried specifying the LDFLAGS in the make command directly, but it's still trying to link against x86. Is there a way to tell the compiler to link against the specified architecture? I've checked the man page for ld
, but I couldn't find anything that might help. Any ideas?
回答1:
Autoconf is basically my worst nightmare, so this solution may not be "correct" but can hopefully unblock you - it looks like the build config does not take into account LDFLAGS when linking on OS X. It uses LDFLAGS_SHLIB, but I wasn't able to get it to override that from a command line argument. Try this patch (note that I downloaded v1.25.29) -- all I did was add your arguments to the end of the existing link command for shared libraries.
neals-mbp: ~/xmlrpc-c-1.25.29> diff config.mk.in config.mk.in2
297c297
< LDFLAGS_SHLIB = -dynamiclib -undefined suppress -single_module \
---
> LDFLAGS_SHLIB = -dynamiclib -undefined suppress -single_module -arch armv7s -miphoneos-version- min=4.0 --sysroot /Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk \
来源:https://stackoverflow.com/questions/25019656/linker-error-trying-to-link-against-arm-but-linker-using-x86