Opened 10 years ago
Closed 10 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 )
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 (9)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|
comment:2 by , 10 years ago
Description: | modified (diff) |
---|
comment:3 by , 10 years ago
Milestone: | → 1.10.1 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:4 by , 10 years ago
Milestone: | 1.10.1 → 1.10.2 |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
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 by , 10 years ago
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
comment:6 by , 10 years ago
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 by , 10 years ago
Cc: | 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?
comment:8 by , 10 years ago
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 by , 10 years ago
Component: | default → ConfigBuild |
---|---|
Resolution: | → fixed |
Status: | reopened → closed |
trunk (r26316) and branches/1.10 (r26317) "Compilation fixes for iOS (#5197, #5198)"