Ios 将从自制下载的C库链接到Xcode项目时出错

Ios 将从自制下载的C库链接到Xcode项目时出错,ios,c,xcode,frameworks,gdal,Ios,C,Xcode,Frameworks,Gdal,伙计们,我花了两天时间试图让GDAL库与我的iOS应用程序一起工作。每当我尝试构建程序时,都会出现如下错误: Ld /Users/scottdriggers/Library/Developer/Xcode/DerivedData/Mapper-goynotoybcqaezfpmrcmfwumcokh/Build/Products/Debug-iphoneos/Mapper.app/Mapper normal arm64 cd /Users/scottdriggers/Documents/Xcod

伙计们,我花了两天时间试图让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)
就像我是专家级程序员一样,我立即去谷歌搜索其他有类似问题的人,发现有很多。按照他们的建议,我以不同的顺序多次做了以下事情:

我清理并尝试再次构建项目
我删除了Xcode的派生数据文件夹的内容
我更新了头搜索路径、其他链接器标志、框架搜索路径和库搜索路径,使之符合所有推荐的内容,但没有任何帮助。这些设置的当前状态如下:
框架搜索路径:
$(继承)
标题搜索路径:
$(继承)
“${PODS_ROOT}/Headers/Public/DJI SDK iOS”
“${PODS_ROOT}/Headers/Public/DJI-UILibrary-iOS”
/usr/local/Cell/gdal/1.11.5_2/包括
/usr/本地/包括
库搜索路径:
-L/usr/local/Cell/gdal/1.11.5_2/lib
-lgdal
/usr/local/Cell/gdal/1.11.5_2/lib
运行路径搜索路径:
$(继承)
@可执行路径/框架

我收到了更多这样的错误,我能够通过在目标的构建阶段将一些库添加到“linkbinary With libraries”选项卡中来修复其中的一些错误,但是这些GDAL错误不会消失,即使我从/usr/local/lib文件链接库时也是如此

背景:我需要为我的程序查看GEOTiff文件中的像素。我在Objc中写我的应用程序,但是GDAL库是C++或C.BR> 我用自制软件安装了这些库,一切都很顺利,所有的文件都链接在/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];
}

无论如何,谢谢你们的帮助,我真的很感激。希望yall能提供一些有用的提示。

我没有做过任何Xcode或iOS开发,但我建议在做其他事情之前先修复链接器错误:

ld:warning:未找到选项'-L-L/usr/local/ceral/gdal/1.11.5_2/lib'的目录。

链接器找不到目录
-L/usr/local/ceral/gdal/1.11.5_2/lib
。看起来您有两个
-L
选项,一个接一个,因此我将删除第一个选项,然后再次检查目录
/usr/local/ceral/gdal/1.11.5_2/lib
是否存在并包含您想要的库。这可能是Xcode配置问题。查看链接器的配置位置

ld:警告:未找到选项'-L-lgdal'的目录。

与此相同的问题是,
-L
选项指定了一个额外的目录来查找库,
-L
选项提供了一个要包含的特定库(在本例中,
gdal
)。字符串
-L-lgdal
没有意义,但是
-lgdal
确实有意义

ld:warning:忽略文件/usr/local/ceral/gdal/1.11.5_2/lib/libgdal.1.dylib,该文件是为x86_64构建的,它不是要链接的体系结构(arm64):/usr/local/ceral/gdal/1.11.5_2/lib/libgdal.1.dylib


找到的库适用于x86_64体系结构,但您正在尝试构建arm64应用程序。如果您将库作为预构建的二进制文件,那么请查找arm64二进制文件。如果您构建了这些库,那么您需要为arm64体系结构重新构建它们

我找到了答案。我试图将Mac OSX应用程序安装到我的iOS应用程序中。是的,我知道,相当愚蠢。我通过谷歌搜索解决了这个问题,直到我找到一个对此解决方案有兴趣的人。希望这对某些人有所帮助。

当我在Xcode中将这些路径添加到“库搜索路径”时,我添加它们时没有“-L”,并且它提供了“-L”我应该添加路径“/usr/local/Cellar/gdal/1.11.5_2/lib lgdal”这样吗?@ScottDriggers我从未使用过Xcode,抱歉。我所能说的是,
ld
没有得到您想要它得到的参数。@ScottRiggers但是库搜索路径听起来像是指定该路径的正确位置,而在其他地方您将要指定库
gdal