【发布时间】:2017-07-19 17:03:01
【问题描述】:
伙计们,我已经苦苦挣扎了两天,试图让 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,立马去google搜索其他有类似问题的,发现有不少。按照他们的建议,我按照不同的顺序多次做了以下所有事情:
我清理并尝试再次构建项目
我删除了 Xcode 的派生数据文件夹的内容
我将标题搜索路径、其他链接器标志、框架搜索路径和库搜索路径更新为我推荐的所有内容,但没有任何帮助。这些设置的当前状态如下:
框架搜索路径:
$(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
库搜索路径:
-L/usr/local/Cellar/gdal/1.11.5_2/lib
-lgdal
/usr/local/Cellar/gdal/1.11.5_2/lib
运行路径搜索路径:
$(继承)
@executable_path/框架
我收到了更多此类错误,我可以通过在目标的构建阶段中将一些库添加到“将二进制文件与库链接”选项卡中来修复其中的一些错误,但这些 GDAL 错误不会消失,即使当我从 /usr/local/lib 文件链接库。
背景:我需要从我的程序的 GEOTiff 文件中查看一个像素。我正在用 OBJC 编写我的应用程序,但 GDAL 库适用于 C++ 或 C。
我使用 Homebrew 安装了这些库,一切顺利,所有文件都链接在 /usr/local 中,但它们不能在 Xcode 中正常工作。我最初开始用 C++ 编写这个文件,但在经历了一天这样的错误后切换到 C。在切换到 C 之后(所以我不必在 OBJC++ 中编译),我仍然会遇到同样的错误。
注意:我也在使用 Cocoapods 来运行其他一些库,但 Cocoapods 没有 GDAL 库,否则我会尝试这条路线。
情节变深:当我为 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];
}
无论如何,谢谢大家的帮助,我很感激。希望大家能提供一些有用的建议。
【问题讨论】:
标签: ios c xcode frameworks gdal