conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.17k stars 974 forks source link

Got an error "dyld: Library not loaded:" when consuming framework by xcode generator #5015

Open kinglezhuang opened 5 years ago

kinglezhuang commented 5 years ago

I followed the document to export the framework library in my local cache, then consumed it by Xcode generator. It can build success but launch failed. Following is an error tip:

'dyld: Library not loaded: @rpath/PubNub.framework/PubNub
  Referenced from: /Users/admin/Library/Developer/CoreSimulator/Devices/9D56419B-F7CB-44D5-A69D-BB9723E6E092/data/Containers/Bundle/Application/61B9D82E-F016-4935-9C19-2B3CCFF4A433/DemoApp.app/DemoApp
  Reason: image not found'

It seams Xcode doesn't copy the image into app bundle. How to solve such problem?

DemoApp.zip

kinglezhuang commented 5 years ago
PRIVATE_FRAMEWORKS_PATH=${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}

mkdir -p ${PRIVATE_FRAMEWORKS_PATH}

cp -RH /Users/admin/.conan/data/pubnub/1.0.0/internal/test/package/c7e2294e57bbb3e824ab0cefd2a2e13f20c8c04e/PubNub.framework ${PRIVATE_FRAMEWORKS_PATH}

so i use above script to copy the file, it can work fine now. Is it the right way?

kinglezhuang commented 5 years ago

Does anybody give me an answer how to do it?

kinglezhuang commented 5 years ago

@memsharded

Can you help me to solve such problem?

kinglezhuang commented 5 years ago

I wrote a script for xcode intergration. Is it ok?

frameworks.sh.zip

lasote commented 5 years ago

Hi, I'll take a look and answer asap. Just a preliminar recommendation about your recipe:

    def configure(self):
        if self.settings.os == "iOS":
            self.settings.os.version = 10.0
        elif self.settings.os == "Android":
            self.settings.os.api_level = 21
        else:
            raise Exception("Error: not support os!")

Don't do that with the settings. You should apply a profile with the os.version and the os.api_level when Android, not assign them in the configure method. Then if you receive other values that you don't want to support you should raise ConanInvalidConfiguration() (imported from conan.errors)

kinglezhuang commented 5 years ago

@lasote

Thank you your reply. It's my demo app, not in production.

By the way, how to integrate into xcode project when consume framework from server, i wrote a script to copy the framework into app bundle, Is it the right way to do that? Because of all frameworks need to be copied into app's bundle on iOS platform.

lasote commented 5 years ago

Well, during the application development, as the xcode generator is adjusting the FRAMEWORK_SEARCH_PATHS to the root folder of your packages (/Users/kingle.zhuang/.conan/data/pubnub/1.0.0/internal/test/package/c7e2294e57bbb3e824ab0cefd2a2e13f20c8c04e) it should automatically find the Frameworks and build the application.

But, if you say that all frameworks need to be copied into the app's bundle on iOS you can write a deploy method in the recipe of your application to import whatever you want from your dependencies and the application itself. So, you could run conan install app/1.0@foo/bar and it will copy to the local install directory all the frameworks. It could be something similar to (not tried):

def deploy(self):
    self.copy("MyApp")  # copy from current package
    self.copy_deps("*.framework") # copy from dependencies
kinglezhuang commented 5 years ago

Copy action is in building time, not in pre build phase

lasote commented 5 years ago

You can use imports method instead. https://docs.conan.io/en/latest/reference/conanfile/methods.html#imports