json-c / json-c

https://github.com/json-c/json-c is the official code repository for json-c. See the wiki for release tarballs for download. API docs at http://json-c.github.io/json-c/
https://github.com/json-c/json-c/wiki
Other
2.9k stars 1.05k forks source link

build ios simulator error #863

Closed Shian-Wang closed 1 week ago

Shian-Wang commented 1 week ago

Note: for general questions and comments, please use the forums at: https://groups.google.com/g/json-c

Describe the bug A clear and concise description of what the bug is, and any information about where you're running into the bug that you feel might be relevant.

Steps To Reproduce List the steps to reproduce the behavior. If possible, please attach a sample json file and/or a minimal code example.

Version and Platform

I build lib for ios simulator success, build load in xcode project compiler show error message

Showing Recent Messages Building for 'iOS-simulator', but linking in object file (/Users/Shian_Wang/Desktop/Git_Temp/DUTUtil/dist/apple-ios/libjson-c-ios.a[x86_64]2) built for 'macOS'

export SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.5.sdk export CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fPIC -arch x86_64 export CFLAGS="-arch x86_64 -isysroot ${SYSROOT} -fPIC"

hawicz commented 1 week ago

so what's the problem you're seeing?

Shian-Wang commented 1 week ago

I use below the parameters and ../cmake-configure to compile for ios simulator(as below command line), but I loaded static lib in xcode project compiler failed. I can't use the lib in xcode project. xcode compiler show the error message which the lib build for macos not simulator. How to fix the bug? Any settings I miss in building lib for ios simulator?

export SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.5.sdk export CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fPIC -arch x86_64 export CFLAGS="-arch x86_64 -isysroot ${SYSROOT} -fPIC" ../cmake-configure --prefix=$PWD/apple-ios-simulator-$ARCH \ --enable-static

make clean make

Shian-Wang commented 1 week ago

I find the parameters to build ios simulator for json-c v17.0

as below to build ios simulator success sdk_target="iphonesimulator" ios_ver=xcodebuild -version -sdk $sdk_target | grep SDKVersion: if [[ "$ios_ver" == "" ]] then echo "Could not determine iOS SDK version. Is xcodebuild on your path?" exit 1 fi

ios_ver_num=echo $ios_ver | sed 's/SDKVersion: \([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\1\2/' ios_ver_str=echo $ios_ver | sed 's/SDKVersion: //'

echo $ios_ver

SDK_VER=echo $ios_ver_str MIN_VER=-mios-simulator-version-min=8.0 DEVELOPER=xcode-select -print-path ARCH=x86_64

export ac_cv_func_malloc_0_nonnull=yes export ac_cv_func_realloc_0_nonnull=yes

export SYSROOT="${DEVELOPER}/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDK_VER}.sdk"

export SYSROOT="${DEVELOPER}/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDK_VER}.sdk ${MIN_VER}"

echo $SYSROOT export CC="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch ${ARCH}" echo $CC export CFLAGS="-arch ${ARCH} -isysroot ${SYSROOT} -fPIC" echo $CFLAGS

if [ ! -d ${PWD}/buildlib/apple-ios-simulator-$ARCH ]; then mkdir -p ${PWD}/buildlib/apple-ios-simulator-$ARCH fi

cd ${PWD}/buildlib rm -f "CMakeCache.txt"

../cmake-configure --prefix=$PWD/apple-ios-simulator-$ARCH \ --enable-static \ --disable-shared \ --disable-Bsymbolic

make clean make make install

hawicz commented 1 week ago

It seems like a common way to do this is with a toolchain file (-DCMAKE_TOOLCHAIN_FILE=path_to_your_toolchain_file) and https://github.com/cristeab/ios-cmake/blob/master/toolchain/iOS.cmake, but I guess there's more than one way to do it. I'm glad you were able to get it working.