Ticket #5197 (closed defect: fixed)

Opened 16 months ago

Last modified 15 months ago

Build for iOS (device) fails due to no crt_extern

Reported by: nsands Owned by: warmerdam
Priority: normal Milestone: 1.10.2
Component: ConfigBuild Version: 1.10.0
Severity: normal Keywords: ios
Cc: ilucena

Description (last modified by rouault) (diff)

Building GDAL 1.10 for iOS (device) fails due to no crt_extern on iOS. Note that it builds OK for the iOS simulator, but not for the device. The build error is included below, but the following fixed this error. In file 'cpl_spawn.cpp' Replace:

#ifdef __APPLE__
#include <crt_externs.h>

With:

#ifdef __APPLE__
# include <TargetConditionals.h>
#endif
#if defined(__APPLE__) && !defined(TARGET_OS_IPHONE)
#include <crt_externs.h>

For completeness, the error output before this change was:

libtool: compile: 
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Dev
eloper/usr/bin/g++ -arch armv7 -pipe -Os -gdwarf-2 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Dev
eloper/SDKs/iPhoneOS6.1.sdk -mno-thumb -mthumb-interwork -Wall
-DOGR_ENABLED -I/Users/nsands/Documents/Nik/Development/gdal-1.10.0/port
-DHAVE_LIBZ -I/usr/include/libxml2 -DHAVE_LIBXML2 -c cpl_spawn.cpp -o
cpl_spawn.o cpl_spawn.cpp:465:25: error: crt_externs.h: No such file or
directory cpl_spawn.cpp: In function 'CPLSpawnedProcess* CPLSpawnAsync(int
(*)(CPL_FILE_HANDLE, CPL_FILE_HANDLE), const char* const*, int, int, int,
char**)': cpl_spawn.cpp:727: error: '_NSGetEnviron' was not declared in
this scope make[1]: *** [cpl_spawn.lo] Error 1
make: *** [port-target] Error 2

Change History

Changed 16 months ago by rouault

  • description modified (diff)

Changed 16 months ago by rouault

  • description modified (diff)

Changed 16 months ago by rouault

  • status changed from new to closed
  • resolution set to fixed
  • milestone set to 1.10.1

trunk (r26316) and branches/1.10 (r26317) "Compilation fixes for iOS (#5197, #5198)"

Changed 15 months ago by kyngchaos

  • status changed from closed to reopened
  • resolution fixed deleted
  • milestone changed from 1.10.1 to 1.10.2

unfortunately, this breaks compiling for OS X. The problem is that when you include TargetConditionals.h, TARGET_OS_IPHONE is always defined, so extern char** environ; is always used, which doesn't work on OS X.

TARGET_OS_IPHONE = 0 on OS X and = 1 on iOS.

Changed 15 months ago by rouault

Hum, this must be more complex than that, and dependant of the OsX version since  https://travis-ci.org/rouault/gdal_coverage/builds/10816942 builds

Changed 15 months ago by kyngchaos

I'm on OS X 10.7, but same Xcode 4.6.2. TargetConditionals.h is available at least as far back as 10.5 (oldest I could check, but probably been around much longer), but TARGET_OS_IPHONE was added in 10.6, so it should be defined in all versions starting with 10.6. That's odd that the preprocessor counts #define TARGET_OS_IPHONE 0 as undefined for you.

This works for me for the conditional:

#if defined(__APPLE__) && TARGET_OS_IPHONE==0

Though to work on 10.5 and below it would be a more complex test... maybe:

#if defined(__APPLE__) && (!defined(TARGET_OS_IPHONE) || TARGET_OS_IPHONE==0)

Changed 15 months ago by ilucena

  • cc ilucena added

It looks like a safe solution independent from environment versions to do add the ==0 condition:

#if defined(APPLE) && !defined(TARGET_OS_IPHONE)

#if defined(APPLE) && (!defined(TARGET_OS_IPHONE) TARGET_OS_IPHONE==0)

But I am not building on a simulator or building for iPhone.

Do you think we should commit that change?

Changed 15 months ago by goatbar

Reported on Mac OSX 10.7 w/ fink. I've added this patch to fink:

PatchScript: <<
  perl -pi.bak -e "s| \&\& \!defined\(TARGET_OS_IPHONE\)||" port/cpl_spawn.cpp
<<

Changed 15 months ago by rouault

  • status changed from reopened to closed
  • resolution set to fixed
  • component changed from default to ConfigBuild

Applying suggested change in trunk r26423 and branches/1.10 r26424 : "Fix build failure on MacOSX due to iOS related changes (#5197)"

MacOsX and iOS users, please test and reopen if it still doesn't work.

Note: See TracTickets for help on using tickets.