Compiling external C++ library for use with iOS project

后端 未结 6 1612
滥情空心
滥情空心 2020-11-29 01:49

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

6条回答
  •  青春惊慌失措
    2020-11-29 02:06

    Considering that you are new with C++ libraries, I guess you will need to do a bit more research.

    However, I will try to outline some steps things you need to take into consideration :

    • you need to make sure you compile for the same architecture both the static library (.a) and the project
    • from your error , you need to compile your static library for i386 OR change your project to x86_64 ( the difference between these architectures is a bit more complex, but for now let's say that i386 means desktop 32 bit while x86_64 means desktop 64 bit)
    • arm architectures are for iPhone , not for your MacOS (that's why it fails to find libraries with arm architecture inside the MacOSX folder) !

    There are multiple ways to approach these issues .

    For the first one I would suggest to include into your workspace the static library, and add it as dependency to your build target . For this you need to understand XCode builds.

    I'm guessing that you actually are trying to make a phone application, so for the 3rd option you need to configure your g++ build to look into the iPhoneSDK from XCode when linking arm targets (look after iPhoneOS.platform) for this.

    Making an arm build will only work on iPhones . If you want it to work on simulator , you will need to link your static library to libraries inside the iPhoneSimulator.platform.

    If you want your static library to work for both iPhones and iPhone simulator, you will need to make a fat lib (basically a library containing symbols for both platforms)

    If you are missing these platforms, you can download them from XCode (but I believe they are there)

    As you can see, things are going to get more and more complex along the way, so I strongly recommend to use XCode for compiling the static library (it is still doable with g++ thou).

    I believe the following concepts you would be useful to research upon :

    • arm, x86 , x86_64
    • static library
    • static linkage
    • fat lib (universal library)
    • XCode workspace with multiple projects

    Hope this helps :).

提交回复
热议问题