Opened 4 years ago

Closed 3 years ago

#5197 closed defect (fixed)

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 Even Rouault)

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>


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

For completeness, the error output before this change was:

libtool: compile: 
eloper/usr/bin/g++ -arch armv7 -pipe -Os -gdwarf-2 -isysroot
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 (9)

comment:1 Changed 4 years ago by Even Rouault

Description: modified (diff)

comment:2 Changed 4 years ago by Even Rouault

Description: modified (diff)

comment:3 Changed 4 years ago by Even Rouault

Milestone: 1.10.1
Resolution: fixed
Status: newclosed

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

comment:4 Changed 3 years ago by kyngchaos

Resolution: fixed
Status: closedreopened

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.

comment:5 Changed 3 years ago by Even Rouault

Hum, this must be more complex than that, and dependant of the OsX version since builds

comment:6 Changed 3 years 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)

comment:7 Changed 3 years 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)

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

Do you think we should commit that change?

comment:8 Changed 3 years ago by Kurt Schwehr

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

comment:9 Changed 3 years ago by Even Rouault

Component: defaultConfigBuild
Resolution: fixed
Status: reopenedclosed

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.