I'm completely new to using C++ libraries, so appreciate this might be a bit specific for my case (let me know and I can provide more details).
I have an external C++ library that I'm trying to use with an iOS project. The library follows a configure, make, make build pattern to output a .a library file. When I try and add this library file to Xcode, I get the following error:
ignoring file /Users/Developer/iOS/TestProj/libpresage.a, file was built for archive which is not the architecture being linked (i386):
/Users/Developer/iOS/TestProj/libpresage.a
Based on this question, I've tried turning Build Active Architecture Only to NO, and I get the same error. This makes me suspect that I've compiled the library for the incorrect architecture.
Running lipo -info on the .a file gives:
input file libpresage.a is not a fat file Non-fat file: libpresage.a
is architecture: x86_64
Given that this isn't armv7s, armv7, or arm64, I try and compile the C++ library again with the following parameters:
1) Try
./configure CC="gcc -arch armv7s" \
CXX="g++ -arch armv7s" \
CPP="gcc -E" CXXCPP="g++ -E"
Error in compiling, I get:
ld: library not found for -lcrt1.3.1.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
2) Try
./configure CC="gcc -arch arm64" \
CXX="g++ -arch arm64" \
CPP="gcc -E" CXXCPP="g++ -E"
Error in compiling, I get:
ld: warning: ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libSystem.dylib, missing required architecture arm64 in file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libSystem.dylib (2 slices)ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libstdc++.dylib, missing required architecture arm64 in file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libstdc++.dylib (2 slices)
ld: dynamic main executables must link with libSystem.dylib for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is there something obvious that I'm missing?
EDIT:
Thanks for the replies, so I've managed to get the library into Xcode as a custom build target, pointing the 'make' command to the libraries MakeFile. This build fine.
My steps from here:
- Add a dependency from my Objective C iOS app target to the custom build target.
- Reference the library and make an Objective C++ wrapper.
- This seems fine until I need to call the external C++ library, then I get the error when compiling:
Undefined symbols for architecture armv7: "Presage::Presage(PresageCallback*)", referenced from: -[PresageBridge init] in PresageBridge.o "Presage::~Presage()", referenced from: -[PresageBridge init] in PresageBridge.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)
My objective C++ wrapper (linking the external C++ library header presage.h):
#import "PresageBridge.h" #include "presage.h" @implementation PresageBridge - (instancetype)init { if(self = [super init]) { Presage hello(&callback); } return self; }
Based on the code above it doesn't seem like I'm missing the header, and what's interesting is that I've also tried creating an instance of other classes in the external library and they seem to be working, which suggests that Xcode can't link presage.h properly for some reason.