Including Third party libraries(Example : AFNetworking) in static library

Is it possible to include 3rd party libraries in static library? Example : Can AFNetworking can be included in static library

Upvotes: 3

Views: 2248

Answers (2)

xverges
xverges

Reputation: 4718

Just for completeness, because I think that the previous answers/comments provide good advice, this is a custom script to include a third party lib to the output lib of a build

set -e
set +u

TGT_FULLPATH="${BUILT_PRODUCTS_DIR}/${EXECUTABLE_NAME}"
TMP_FULLPATH="${BUILT_PRODUCTS_DIR}/original_${EXECUTABLE_NAME}"
THIRPARTY_FULLPATH=...
ARCHSPECIFIC_THIRDPARTY="${BUILT_PRODUCTS_DIR}/thinThirdparty"

# What's the architecture for the lib we just built?
LIPO_ARCH=$(lipo -info  ${TGT_FULLPATH} | awk 'END{ print $NF }')

# Create a thirdparty lib only for the current architecture
lipo -thin ${LIPO_ARCH} ${THIRPARTY_FULLPATH} -output ${ARCHSPECIFIC_THIRDPARTY}

# Join the two libaries
mv ${TGT_FULLPATH} ${TMP_FULLPATH}
libtool -static -o ${TGT_FULLPATH} ${TMP_FULLPATH} ${ARCHSPECIFIC_THIRDPARTY} 2>&1  >/dev/null 

# Remove the temp artifacts
rm ${TMP_FULLPATH}
rm ${ARCHSPECIFIC_THIRDPARTY}

Upvotes: 0

chathuram
chathuram

Reputation: 636

The direct answer to your question is YES, you can definitely include any third party library if they expose a public API (a set of headers for you to refer). For AFNetworking, they have made it so simple by providing a Cocoapods script so that your project can refer it.

But be aware that when you release your static library with including AFNetwork inside, and someday if your static lib user decides to use AFNetwork in his own code, the Obj-C compiler will complain about duplicate symbols and he will be unable to build his project with your static lib.

My advice

My advice :just refer to the link shared by @Amar above. It is very important NOT to include any third party libraries in your static library if you are hoping to share it with other developers or community. Always consider using references for other third party static libraries instead of including them, for example make use of Cocoapods.

Upvotes: 3

Related Questions