将从 Homebrew 下载的 C 库链接到 Xcode 项目时出错
Error when linking C libraries downloaded from Homebrew to Xcode Project
伙计们,我已经努力了两天,试图让 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
的派生数据文件夹的内容
我将 Header 搜索路径、其他链接器标志、框架搜索路径和库搜索路径更新为我被推荐的所有内容,但没有任何帮助。这些设置的当前状态如下:
框架搜索路径:
$(继承)
Header 搜索路径:
$(继承)
"${PODS_ROOT}/Headers/Public/DJI-SDK-iOS"
"${PODS_ROOT}/Headers/Public/DJI-UILibrary-iOS"
/usr/local/Cellar/gdal/1.11.5_2/包括
/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/Frameworks
我收到了更多这样的错误,我能够通过在我的目标的构建阶段中的选项卡 "Link Binary With Libraries" 中添加一些库来修复其中的一些错误,但是这些 GDAL 错误不会消失,即使当我 link 来自 /usr/local/lib 文件的库时。
Link Binaries With Libraries
背景: 我需要为我的程序查看 GEOTiff 文件中的像素。我正在用 OBJC 编写我的应用程序,但 GDAL 库适用于 C++ 或 C。
我使用 Homebrew 安装了这些库,一切顺利,所有文件 link 在 /usr/local 中编辑,但它们无法与 Xcode 一起正常工作。我最初开始用 C++ 编写此文件,但在出现这样的错误一天后切换到 C。切换到 C 后(这样我就不必在 OBJC++ 中编译),我仍然遇到同样的错误。
注意:我也在使用 Cocoapods 运行 其他一些库,但 Cocoapods 没有 GDAL 库,否则我会尝试那个路线。
情节加深: 当我 运行 iPhone 模拟器的程序而不是尝试 运行 它在我的 iPhone 7,程序编译得很好并显示 "build succeeded",但是当它试图将它附加到模拟器时我得到另一个错误:
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];
}
无论如何,谢谢大家的帮助,我很感激。希望大家多多指教。
我没有进行任何 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 架构重新构建它们。
我找到了答案。我试图将 Mac OSX 应用程序安装到我的 iOS 应用程序。是的,我知道,非常愚蠢。我通过谷歌搜索解决了这个问题,直到我找到一个对此解决方案有 tutorial 的人。希望这有时能对某人有所帮助。
伙计们,我已经努力了两天,试图让 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
的派生数据文件夹的内容
我将 Header 搜索路径、其他链接器标志、框架搜索路径和库搜索路径更新为我被推荐的所有内容,但没有任何帮助。这些设置的当前状态如下:
框架搜索路径:
$(继承)
Header 搜索路径:
$(继承)
"${PODS_ROOT}/Headers/Public/DJI-SDK-iOS"
"${PODS_ROOT}/Headers/Public/DJI-UILibrary-iOS"
/usr/local/Cellar/gdal/1.11.5_2/包括
/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/Frameworks
我收到了更多这样的错误,我能够通过在我的目标的构建阶段中的选项卡 "Link Binary With Libraries" 中添加一些库来修复其中的一些错误,但是这些 GDAL 错误不会消失,即使当我 link 来自 /usr/local/lib 文件的库时。
Link Binaries With Libraries
背景: 我需要为我的程序查看 GEOTiff 文件中的像素。我正在用 OBJC 编写我的应用程序,但 GDAL 库适用于 C++ 或 C。
我使用 Homebrew 安装了这些库,一切顺利,所有文件 link 在 /usr/local 中编辑,但它们无法与 Xcode 一起正常工作。我最初开始用 C++ 编写此文件,但在出现这样的错误一天后切换到 C。切换到 C 后(这样我就不必在 OBJC++ 中编译),我仍然遇到同样的错误。
注意:我也在使用 Cocoapods 运行 其他一些库,但 Cocoapods 没有 GDAL 库,否则我会尝试那个路线。
情节加深: 当我 运行 iPhone 模拟器的程序而不是尝试 运行 它在我的 iPhone 7,程序编译得很好并显示 "build succeeded",但是当它试图将它附加到模拟器时我得到另一个错误:
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];
}
无论如何,谢谢大家的帮助,我很感激。希望大家多多指教。
我没有进行任何 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 架构重新构建它们。
我找到了答案。我试图将 Mac OSX 应用程序安装到我的 iOS 应用程序。是的,我知道,非常愚蠢。我通过谷歌搜索解决了这个问题,直到我找到一个对此解决方案有 tutorial 的人。希望这有时能对某人有所帮助。