所以小伙子们,我一直在努力让GDAL库与我的iOS应用程序一起工作两天。每当我尝试构建程序时,都会出现如下错误:
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
......很多类似的问题......
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
就像 EXPERT LEVEL PROGRAMMER 那样,我立即去谷歌搜索有类似问题的其他人,并发现有不少。按照他们的建议,我按照几个不同的顺序多次做了以下所有事情:
我清理并试图再次建造项目
我删除了Xcode
的派生数据文件夹的内容
我将标题搜索路径,其他链接标记,框架搜索路径和库搜索路径更新为我推荐的所有内容,没有任何帮助。这些设置的当前状态如下:
框架搜索路径:
$(继承)
标题搜索路径:
$(继承)
“$ {} PODS_ROOT /头/公/ DJI-SDK-IOS”
“$ {} PODS_ROOT /头/公/ DJI-UILibrary-IOS”
/usr/local/Cellar/gdal/1.11.5_2/include
在/ usr /本地/包括
图书馆搜索路径:
-L在/ usr /本地/库/ @中/ 1.11.5_2 / lib目录
-lgdal
/usr/local/Cellar/gdal/1.11.5_2/lib
运行路径搜索路径:
$(继承)
@ executable_path / Frameworks
我收到了更多这些错误,我能够通过在我的目标的构建阶段中的“Link Binary With Libraries”选项卡中添加一些库来解决其中一些问题,但这些GDAL错误不会消失,即使是我从/ usr / local / lib文件链接库。
后台:我需要查看我的程序的GEOTiff文件中的像素。我在OBJC中编写我的应用程序,但GDAL库是用于C ++或C. 我使用Homebrew安装了这些库,这很好,所有文件都链接在/ usr / local中,但它们无法正常使用Xcode。我最初开始用C ++编写这个文件,但是经过一天这样的错误后切换到了C.切换到C后(所以我不必在OBJC ++中编译),我仍然会遇到同样的错误。
注意:我也在使用Cocoapods来运行其他一些库,但是Cocoapods没有GDAL库,或者我会试过这条路。
Plot Thickens:当我运行iPhone模拟器的程序而不是试图在我的iPhone 7上运行它时,程序编译得很好并说“构建成功”,但我得到另一个尝试将其附加到模拟器时出错:
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
我认为没有必要包含导致错误的文件,但如果有人想看一下,这里有一个抽样:
#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];
}
无论如何,谢谢大家的帮助,我很感激。希望你能提供一些有用的提示。
答案 0 :(得分:0)
我没有做任何Xcode或iOS开发,但我建议你在做其他事情之前修复链接器错误:
ld: warning: directory not found for option '-L-L/usr/local/Cellar/gdal/1.11.5_2/lib'
链接器找不到目录-L/usr/local/Cellar/gdal/1.11.5_2/lib
。看起来你一个接一个地有两个-L
选项,所以我将删除第一个,然后仔细检查目录/usr/local/Cellar/gdal/1.11.5_2/lib
是否存在并包含你想要的库。这可能是Xcode配置问题。查看配置链接器包含的位置。
ld: warning: directory not found for option '-L-lgdal'
此处的问题相同,-L
选项指定要查找库的其他目录,-l
选项提供要包含的特定库(在本例中为gdal
)。字符串-L-lgdal
毫无意义,但-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
找到的库是针对x86_64架构的,但您正在尝试构建arm64应用程序。如果您将库作为预先构建的二进制文件,那么请找到arm64二进制文件。如果您构建了库,那么您需要为arm64架构重新构建它们。
答案 1 :(得分:0)
我找到了答案。我试图将Mac OSX应用程序安装到我的iOS应用程序中。是的,我知道,非常愚蠢。我通过谷歌搜索来解决这个问题,直到我发现有人tutorial为此解决方案。希望这有时可以帮助某人。