I tried the steps in this link. I added all linked libraries which should also include a library called myLib.a, but I got an undefined symbols for architecture arm64 error.
Furthermore, when I used the command nm -arch arm64 -g myLibraryName, I found out that the symbols in myLib.a were missing.
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.
Link Binaries With Libraries
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.
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.
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.
I have an Xcode project (Xcode 6.3.1) with the following library search paths set:
"$(SRCROOT)/Libraries/ScaleformLib/${CURRENT_ARCH}/clang/${CONFIGURATION}_NoRTTI"
"$(SRCROOT)/Libraries/ScaleformLib/${CURRENT_ARCH}/clang/"
When building I get linker errors, which seem to be due to the CURRENT_ARCH variable not expanding correctly (paths shortened/removed for clarity):
Ld Unity-iPhone.build/Objects-normal/armv7/mud normal armv7
cd builds/iOSSubmission
export IPHONEOS_DEPLOYMENT_TARGET=7.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
clang++ -arch armv7 -isysroot
-L/builds/iOSSubmission/Libraries/ScaleformLib/arm64/clang/Release_NoRTTI
-L/builds/iOSSubmission/Libraries/ScaleformLib/arm64/clang
I'm unsure why arm64 is being inserted into the search paths when it seems like it should be armv7? What am I missing?
Thanks!
Original answer was wrong but this one works.
So for us, it came down to header search path for a .dylib. We needed libxml2 so we had header search path set to
/usr/include/libxml2
This isn't SDK dependent (shouldn't the dylib actually link to the SDK we're using?) so we changed it to:
$(SDKROOT)/usr/include/libxml2
And everything was fine.
I selectively link a library depending on the configuration in my project build settings. i.e.
Debug: -l libcws_ps
Release: -l libcws
In library search paths, I point to the directory that contains these 2 .a libraries.
I'll point out that this worked on Xcode 5, but now on Xcode 6 it's not linking properly and I'm getting undefined symbol errors. If I link using the usual method - 'link binary with libraries', then it works - but then I don't have the configuration based linking.
Any ideas how to fix this, or at least some clues how I get debug it?
Libtool /Users/dave/Library/Developer/Xcode/DerivedData/FilmFlexMovies-ddwyjuvbhaqgqralpjczhprnltla/Build/Products/Release-iphoneos/libiOSIrdetoLibrary.a normal armv7
cd /Users/dave/Developer/GIT/FilmFlex/iOS/Submodules/iOSModelController/Submodules/iOSIrdetoLibrary
export IPHONEOS_DEPLOYMENT_TARGET=7.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only armv7 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk -L/Users/dave/Library/Developer/Xcode/DerivedData/FilmFlexMovies-ddwyjuvbhaqgqralpjczhprnltla/Build/Products/Release-iphoneos -LCloakwareStreaming/lib/ios -L/Users/dave/Developer/GIT/FilmFlex/iOS/Submodules/iOSModelController/Submodules/iOSIrdetoLibrary/CloakwareStreaming/lib/ios -filelist /Users/dave/Library/Developer/Xcode/DerivedData/FilmFlexMovies-ddwyjuvbhaqgqralpjczhprnltla/Build/Intermediates/iOSIrdetoLibrary.build/Release-iphoneos/iOSIrdetoLibrary.build/Objects-normal/armv7/iOSIrdetoLibrary.LinkFileList -framework MediaPlayer -framework CoreVideo -framework AVFoundation -framework UIKit -framework Foundation -o /Users/dave/Library/Developer/Xcode/DerivedData/FilmFlexMovies-ddwyjuvbhaqgqralpjczhprnltla/Build/Products/Release-iphoneos/libiOSIrdetoLibrary.a
RTFM... or RTFRN... Xcode 6 release notes
"Xcode will no longer pass options in the build setting OTHER_LDFLAGS to libtool when building static libraries, nor will it pass options in OTHER_LIBTOOLFLAGS to the Mach-O linker when building any other kind of product. Previously all options in both settings would be passed to both tools. Make sure that options are in the correct build setting for the product type, static library, or other component being built. (4285249)"
So it just wasn't even passing my 'other linker flags'. I needed to move them to 'other librarian flags'.
I attempt to Create a Xcode-WorkSpace,there are there projects in it. Now the first Project is a static library base on ZBar Code Reader.I already download the source code ,now I drag the finder named "src" into my first project. When I bulid it,here is the problem:
Libtool /Users/asset/Library/Developer/Xcode/DerivedData/huishow1-efdjffeirjufbndvocvtzkrzkwss/Build/Products/Debug-iphonesimulator/libZBarTest.a normal i386
cd /Users/asset/iPhone_Tmp/ZBarTest
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool -static -arch_only i386 -syslibroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -L/Users/asset/Library/Developer/Xcode/DerivedData/huishow1-efdjffeirjufbndvocvtzkrzkwss/Build/Products/Debug-iphonesimulator -L/Users/asset/iPhone_Tmp/ZBarTest/SDK -L/Users/asset/iPhone_Tmp/ZBarTest/SDK3 -filelist /Users/asset/Library/Developer/Xcode/DerivedData/huishow1-efdjffeirjufbndvocvtzkrzkwss/Build/Intermediates/ZBarTest.build/Debug-iphonesimulator/ZBarTest.build/Objects-normal/i386/ZBarTest.LinkFileList -lxml2 -ObjC -framework Foundation -lzbar -o /Users/asset/Library/Developer/Xcode/DerivedData/huishow1-efdjffeirjufbndvocvtzkrzkwss/Build/Products/Debug-iphonesimulator/libZBarTest.a
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool failed with exit code 1
Who can help me?
Sounds like a missing dependency. I'm not familiar with the ZBar code reader but I'd imagine it declares dependencies on some system frameworks that you haven't yet included in your app? Look in the docs for ZBar to determine which frameworks you need to link to when including it. Typically when you get these types of libtool errors when you don't include a framework or other dependency.