tensorflow: Building TensorFlow for iOS failed on macOS Sierra and xCode 8.0

When running compile_ios_protobuf.sh, it says: checking whether we are cross compiling… configure: error: in ‘…/tensorflow/tensorflow/contrib/makefile/downloads/protobuf’: configure: error: cannot run C compiled programs. If you meant to cross compile, use --host'. Seeconfig.log’ for more details

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 51 (8 by maintainers)

Commits related to this issue

Most upvoted comments

You must also make similar changes to tensorflow/contrib/makefile/compile_ios_tensorflow.sh to avoid building the X86_64 library and then also to avoid linking into the final artifact.

This is perhaps an easier split view of the necessary work-around changes:

https://github.com/alphamule/tensorflow/commit/672da4fef637c5511fd2cf78a4ac8e710d0efbda?diff=split

@arundasan91 I am also of the opinion that this is an OS issue. My best guess is that, in the upgrade to Sierra, now when you link against the ios simulator libraries (sorry if this is the wrong nomenclature—I’m new to iOS dev) the resulting binary is not executable, whereas I presume it was in El Cap. Even using old simulator versions does not fix the problem. When I compile the same test binary as ./configure but don’t use the simulator for -isysroot, the binary runs fine.

The only links to the mach-o error message from config.log I could find are:

https://curl.haxx.se/mail/lib-2016-09/0079.html http://stack1.ocim.top/39762289/issue-with-executing-a-out-file-c-macos-sierra-10-12-1.html http://stackoverflow.com/questions/39762289/issue-with-executing-a-out-file-c-macos-sierra-10-12-1

But none seem to have satisfactory answers here.

Yeah, it’s not Xcode, as you’re still on the step before you can use Xcode (building the libraries).

Did you maybe misinterpret the deleted lines as empty lines?

It needs to look like this:

lipo \
${LIBDIR}/iossim_386/lib/libprotobuf-lite.a \
${LIBDIR}/ios_arm7/lib/libprotobuf-lite.a \
${LIBDIR}/ios_arm7s/lib/libprotobuf-lite.a \
${LIBDIR}/ios_arm64/lib/libprotobuf-lite.a \
-create \
-output ${LIBDIR}/libprotobuf-lite.a

not

lipo \
${LIBDIR}/iossim_386/lib/libprotobuf-lite.a \

${LIBDIR}/ios_arm7/lib/libprotobuf-lite.a \
${LIBDIR}/ios_arm7s/lib/libprotobuf-lite.a \
${LIBDIR}/ios_arm64/lib/libprotobuf-lite.a \
-create \
-output ${LIBDIR}/libprotobuf-lite.a

Or else, maybe did you remove one of those trailing backslashes?

From your error logs, I can tell that you are running the command:

+ lipo /Users/kduy/temp/tensorflow/tensorflow/contrib/makefile/gen/protobuf_ios/lib/iossim_386/lib/libprotobuf.a

which means that the second half of the command is getting cut off.

Downgrading to Xcode 8.0.0 -> 7.3.1 does not seem to fix it.

Same issue. Is there a workaround to build TensorFlow static library?

I modified the camera sample to let it run on photos and succeeded to build library in x86_64 on Sierra by following workaround. Also confirmed the library works in iPhone simulator. (By checking config.log, I found that “–enable-cross-compile” option is likely to become outdated on Sierra. To enable cross-compile, specify “–build” and “–host” with different value worked.)

➜  makefile git:(r0.10) ✗ ln -s /usr/bin/llvm-gcc /usr/local/bin/x86_64-apple-darwin15.0.0-gcc

➜  makefile git:(r0.10) ✗ diff -u compile_ios_protobuf.sh compile_ios_protobuf.sh_bkp
diff -u compile_ios_protobuf.sh_bkp compile_ios_protobuf.sh
--- compile_ios_protobuf.sh_bkp	2017-02-14 10:57:47.000000000 +0900
+++ compile_ios_protobuf.sh	2017-02-14 15:39:18.000000000 +0900
@@ -38,7 +38,9 @@
 LIBDIR=${GENDIR}lib
 mkdir -p ${LIBDIR}
 
-OSX_VERSION=darwin14.0.0
+# OSX_VERSION=darwin14.0.0
+OSX_VERSION=darwin15.0.0
+OSX_VERSION2=darwin16.4.0
 
 IPHONEOS_PLATFORM=`xcrun --sdk iphoneos --show-sdk-platform-path`
 IPHONEOS_SYSROOT=`xcrun --sdk iphoneos --show-sdk-path`
@@ -100,7 +102,7 @@
 make distclean
 ./configure \
 --build=x86_64-apple-${OSX_VERSION} \
---host=x86_64-apple-${OSX_VERSION} \
+--host=x86_64-apple-${OSX_VERSION2} \
 --disable-shared \
 --enable-cross-compile \
 --with-protoc="${PROTOC_PATH}" \

Although actually doesn’t affect the build process, version values are picked from “15.0.0” => “brew info gcc; ls /usr/local/Cellar/gcc/*/bin” “16.4.0” => “uname -r”

For me, at least, the compile_ios_protobuf.sh script is only failing when compiling for -arch x86_64. The other 4 targets - i386, armv7, armv7s, and arm64 - compile without an error.