Compile C ++ files for all iOS architectures

I have some cpp files that I would like to compile to run on a simulator and iPhone. I am trying to do this:

g++ -c file1.cpp file2.cpp -std=c++11 ar rcs libabc.a *.o 

And this compiles fine, but only for x86_64 architecture. Obviously ...

Is there any simple way I can edit these two lines of the command to have a library compiled for all architectures (x86_64 i386 armv7 armv7s arm64)? Or should I build some huge scripts to have this library? If so? Are there any scripts for this?

I also tried running it with -arch:

 g++ -c file1.cpp file2.cpp -std=c++11 -arch armv7 -arch x86_64 

but these are some errors that I get

 //----------------- Error 1 -------------------------// 

enter image description here

 //----------------- Error 2 -------------------------// 

enter image description here

 //----------------- Error 3 -------------------------// 

enter image description here

Thanks!

+6
source share
2 answers

It is better to build for each arc individually, and then glue together. This helps in calculating the various or erroneously included platform specific headers as well.

But in my experience, all this is not worth it if you can avoid building through the console. Create an Xcode project and use a fake structure if it suits you. Or create static libraries separately, and then merge them yourself.

0
source

Did you -arch flag of the compiler?

 g++ -c file1.cpp file2.cpp -std=c++11 -arch x86_64 -arch i386 -arch armv7 #... 
+4
source

All Articles