Reputation: 369
So guys, I've been struggling for two days trying to get GDAL libraries working with my iOS application. Whenever I try to build my program, I get a error like the following:
Ld /Users/scottdriggers/Library/Developer/Xcode/DerivedData/Mapper-goynotoybcqaezfpmrcmfwumcokh/Build/Products/Debug-iphoneos/Mapper.app/Mapper normal arm64
cd /Users/scottdriggers/Documents/XcodeProjects/Mapper
export IPHONEOS_DEPLOYMENT_TARGET=9.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk -L/Users/scottdriggers/Library/Developer/Xcode/DerivedData/Mapper-goynotoybcqaezfpmrcmfwumcokh/Build/Products/Debug-iphoneos -L-L/usr/local/Cellar/gdal/1.11.5_2/lib -L-lgdal -L/usr/local/Cellar/gdal/1.11.5_2/lib -F/Users/scottdriggers/Library/Developer/Xcode/DerivedData/Mapper-goynotoybcqaezfpmrcmfwumcokh/Build/Products/Debug-iphoneos -F/Users/scottdriggers/Documents/XcodeProjects/Mapper/Pods/DJI-SDK-iOS/iOS_Mobile_SDK -F/Users/scottdriggers/Documents/XcodeProjects/Mapper/Pods/DJI-UILibrary-iOS/iOS_UILibrary -filelist /Users/scottdriggers/Library/Developer/Xcode/DerivedData/Mapper-goynotoybcqaezfpmrcmfwumcokh/Build/Intermediates/Mapper.build/Debug-iphoneos/Mapper.build/Objects-normal/arm64/Mapper.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -Xlinker -rpath -Xlinker @executable_path/Frameworks -miphoneos-version-min=9.0 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/scottdriggers/Library/Developer/Xcode/DerivedData/Mapper-goynotoybcqaezfpmrcmfwumcokh/Build/Intermediates/Mapper.build/Debug-iphoneos/Mapper.build/Objects-normal/arm64/Mapper_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fobjc-arc -fobjc-link-runtime -ObjC -framework DJISDK -framework DJIUILibrary -ObjC -framework DJISDK -framework DJIUILibrary -I/usr/local/Cellar/gdal/1.11.5_2/include -lgdal.1 -framework CoreGraphics -framework MapKit -framework CoreLocation -framework UIKit -framework Foundation /Users/scottdriggers/Library/Developer/Xcode/DerivedData/Mapper-goynotoybcqaezfpmrcmfwumcokh/Build/Products/Debug-iphoneos/VideoPreviewer.framework/VideoPreviewer -lPods-Mapper -Xlinker -dependency_info -Xlinker /Users/scottdriggers/Library/Developer/Xcode/DerivedData/Mapper-goynotoybcqaezfpmrcmfwumcokh/Build/Intermediates/Mapper.build/Debug-iphoneos/Mapper.build/Objects-normal/arm64/Mapper_dependency_info.dat -o /Users/scottdriggers/Library/Developer/Xcode/DerivedData/Mapper-goynotoybcqaezfpmrcmfwumcokh/Build/Products/Debug-iphoneos/Mapper.app/Mapper
ld: warning: directory not found for option '-L-L/usr/local/Cellar/gdal/1.11.5_2/lib'
ld: warning: directory not found for option '-L-lgdal'
ld: warning: ignoring file /usr/local/Cellar/gdal/1.11.5_2/lib/libgdal.1.dylib, file was built for x86_64 which is not the architecture being linked (arm64): /usr/local/Cellar/gdal/1.11.5_2/lib/libgdal.1.dylib
Undefined symbols for architecture arm64:
"_GDALGetRasterXSize", referenced from:
-[GEOTIFFManager averageFile:] in GEOTIFFManager.o
"_GDALGetRasterYSize", referenced from:
-[GEOTIFFManager averageFile:] in GEOTIFFManager.o
...many similar issues...
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Like the EXPERT LEVEL PROGRAMMER I am, I immediately went to google to search for others with similar issues, and found that there were quite a few. Following their recommendations, I did all of the following things several times in several different orders:
I cleaned and tried to build the project again
I deleted the contents of the derived data folder for Xcode
I updated the Header Search Paths, the Other Linker Flags, the Framework Search Paths, and the Library Search Paths to everything I was recommended and nothing helped. The current state of these settings is as follows:
Framework Search Paths:
$(inherited)
Header Search Paths:
$(inherited)
"${PODS_ROOT}/Headers/Public/DJI-SDK-iOS"
"${PODS_ROOT}/Headers/Public/DJI-UILibrary-iOS"
/usr/local/Cellar/gdal/1.11.5_2/include
/usr/local/include
Library Search Paths:
-L/usr/local/Cellar/gdal/1.11.5_2/lib
-lgdal
/usr/local/Cellar/gdal/1.11.5_2/lib
Runpath Search Paths:
$(inherited)
@executable_path/Frameworks
I was receiving more of these errors and I was able to fix some of these by adding some libraries into the tab "Link Binary With Libraries" in the Build Phases of my target, but these GDAL errors wont go away, even when I link the library from the /usr/local/lib file.
Background: I need to view a pixel from a GEOTiff file for my program. I am writing my application in OBJC, but the GDAL libraries are for C++ or C.
I installed these libraries using Homebrew, and this went fine, all of the files linked in /usr/local, but they are not working right with Xcode. I originally started writing this file in C++ but switched to C after a day of errors like this. After switching to C (so I wouldn't have to compile in OBJC++), I am still going through the same errors.
Note: I am also using Cocoapods to run some other libraries, but Cocoapods didn't have a GDAL library or I would have tried that route.
The Plot Thickens: When I run the program for the iPhone simulator instead of trying to run it on my iPhone 7, the program compiles just fine and says "build succeeded", but I get another error when it tries to attach it to the simulator:
dyld: Library not loaded: /usr/local/opt/gdal/lib/libgdal.1.dylib
Referenced from: /Users/scottdriggers/Library/Developer/CoreSimulator/Devices/1618C362-7271-4E1D-93C7-DE7CE2F15F59/data/Containers/Bundle/Application/905B2454-C731-42DC-8963-5B5C3F4A62A6/Mapper.app/Mapper
Reason: no suitable image found.
Did find: /usr/local/opt/gdal/lib/libgdal.1.dylib: mach-o, but not built for iOS simulator
I don't think its necessary to include the file that causes the errors, but here is a sampling if anybody wants to take a look:
#include "GEOTIFFManager.h"
#include "gdal.h"
#include "cpl_conv.h"
@interface GEOTIFFManager()
@end
@implementation GEOTIFFManager
- (id) init{
self = [super init];
GDALAllRegister();
return self;
}
- (float) getPixelValueOfCoordinate:(double *)coordinate FromFile:(char *)name{
GDALDatasetH* inFile = (GDALDatasetH*)GDALOpen(name, GA_ReadOnly);
double* transformation = NULL;
GDALGetGeoTransform(inFile, transformation);
double* transformedCoord;
transformedCoord = reverseTransform(coordinate, transformation);
int pixelX = floor(transformedCoord[0]);
int pixelY = floor(transformedCoord[1]);
float tempArray[1] = {-1.0};
float* output = tempArray;
GDALRasterBandH Band = GDALGetRasterBand(inFile, 1);
GDALRasterIO(Band, GF_Read, pixelX, pixelY, 1, 1, output, 1, 1, GDT_CFloat32, 0, 0);
return output[0];
}
Anyways, thank you all for your help, I do appreciate it. Hope yall can provide some helpful tips.
Upvotes: 0
Views: 499
Reputation: 369
I found the answer. I was trying to install Mac OSX applications to my iOS application. Yea, I know, pretty dumb. I fixed this by googling around until I found someone who had a tutorial for this solution. Hope this helps somebody sometime.
Upvotes: 0
Reputation: 1694
I've not done any Xcode or iOS development, but I'd suggest fixing the linker errors before you do anything else:
ld: warning: directory not found for option '-L-L/usr/local/Cellar/gdal/1.11.5_2/lib'
The linker could not find the directory -L/usr/local/Cellar/gdal/1.11.5_2/lib
. It looks like you've got two -L
options one after the other, so I'd remove the first, and then double check that the directory /usr/local/Cellar/gdal/1.11.5_2/lib
exists and includes the libraries you want. This might be an Xcode configuration problem. Look at wherever you configure the linker includes.
ld: warning: directory not found for option '-L-lgdal'
Same issue here, the -L
option specifies an additional directory to look for libraries, and the -l
option gives a specific library to include (in this case, gdal
). The string -L-lgdal
makes no sense, but -lgdal
does make sense.
ld: warning: ignoring file /usr/local/Cellar/gdal/1.11.5_2/lib/libgdal.1.dylib, file was built for x86_64 which is not the architecture being linked (arm64): /usr/local/Cellar/gdal/1.11.5_2/lib/libgdal.1.dylib
The library that was found is for x86_64 architecture but you're trying to build an arm64 application. If you got the libraries as pre-built binaries then go find an arm64 binary. If you built the libraries then you want to re-build them for the arm64 architecture.
Upvotes: 0