How do we add facebookSDK into a xcode project usi

2019-08-19 04:45发布

问题:

I am having some difficulties adding facebookSDK.framework into my xcode project using cmake? Here's what i have done up to now. But it doesn't seem to work

set (facebook_sdk_path ${CMAKE_HOME_DIRECTORY}/external/framework/facebook/ios)
message("adding facebookSDK" ${facebook_sdk_path})
target_link_libraries(${Target} "${facebook_sdk_path}/facebookSDK.framework/facebookSDK")

I believe we need to set the framework under "framework search paths" on the project settings, but I am not exactly too sure on how to do this.

回答1:

found my solution: i used this macro i found from CMake and XCode: "cannot find interface declaration for 'NSObject'"

macro(AddExternalFramework fwname appname libpath)
    find_library(FRAMEWORK_${fwname}
        NAMES ${fwname}
        PATHS ${libpath} 
        NO_DEFAULT_PATH)
    if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND)
        MESSAGE(ERROR ": Framework ${fwname} not found: ${FRAMEWORK_${fwname}}")
    else()
        TARGET_LINK_LIBRARIES(${appname} ${FRAMEWORK_${fwname}})
        MESSAGE(STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}")
    endif()
endmacro(AddExternalFramework)


回答2:

I ran into the same issue but Frank's answer didn't work for me. As it was mentioned on the post referenced, calling TARGET_LINK_LIBRARIES messes up the FRAMEWORK_SEARCH_PATHS variable. In my case it finds FacebookSDK.framework but then generates linker errors for the rest of the frameworks included (e.g. UIKit, Foundation, etc.).

My solution was simply copying FacebookSDK.framework to the XCode frameworks folders. Bear in mind you need to copy it to both iPhoneOS and iPhoneSimulator if you build for device and simulator. Currently, XCode7 and SDK9.0, those folders are:

  • /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/System/Library/Frameworks
  • /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/System/Library/Frameworks

Adding FacebookSDK.framework as usual works fine then:

SET (OUR_FRAMEWORKS "-framework Foundation -framework UIKit -framework FacebookSDK ...")