简体   繁体   English

从Homebrew下载的C库链接到Xcode Project时出错

[英]Error when linking C libraries downloaded from Homebrew to Xcode Project

So guys, I've been struggling for two days trying to get GDAL libraries working with my iOS application. 伙计们,我努力了两天,努力让GDAL库与我的iOS应用程序一起工作。 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. 就像我是专家级别的编程人员一样,我立即去Google搜索具有类似问题的其他程序,发现其中有很多问题。 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 我删除了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 /头/公/ DJI-SDK-IOS”
"${PODS_ROOT}/Headers/Public/DJI-UILibrary-iOS" “$ {} PODS_ROOT /头/公/ DJI-UILibrary-IOS”
/usr/local/Cellar/gdal/1.11.5_2/include /usr/local/Cellar/gdal/1.11.5_2/include
/usr/local/include 在/ usr /本地/包括
Library Search Paths: 图书馆搜索路径:
-L/usr/local/Cellar/gdal/1.11.5_2/lib -L在/ usr /本地/库/ @中/ 1.11.5_2 / lib目录
-lgdal -lgdal
/usr/local/Cellar/gdal/1.11.5_2/lib /usr/local/Cellar/gdal/1.11.5_2/lib
Runpath Search Paths: 运行路径搜索路径:
$(inherited) $(继承)
@executable_path/Frameworks @ executable_path /框架

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. 我收到了更多此类错误,并且可以通过在目标的“构建阶段”中将一些库添加到“使用库链接二进制文件”选项卡中来解决其中的一些问题,但是即使我链接了这些GDAL错误,这些错误也不会消失/ usr / local / lib文件中的库。

Link Binaries With Libraries 将二进制文件与库链接

Background: I need to view a pixel from a GEOTiff file for my program. 背景:我需要从我的程序的GEOTiff文件中查看像素。 I am writing my application in OBJC, but the GDAL libraries are for C++ or C. 我正在用OBJC编写应用程序,但是GDAL库适用于C ++或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. 我使用Homebrew安装了这些库,并且一切正常,所有文件都在/ usr / local中链接,但是它们不能在Xcode中正常工作。 I originally started writing this file in C++ but switched to C after a day of errors like this. 我最初开始用C ++编写此文件,但经过一天的此类错误后切换到了C。 After switching to C (so I wouldn't have to compile in OBJC++), I am still going through the same errors. 切换到C之后(因此我不必在OBJC ++中进行编译),我仍然遇到相同的错误。

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. 注意:我也使用Cocoapods运行其他库,但是Cocoapods没有GDAL库,否则我会尝试这种方法。

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: 剧情变厚:当我运行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

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: 我尚未完成任何Xcode或iOS开发,但建议您在执行其他任何操作之前先修复链接器错误:

ld: warning: directory not found for option '-LL/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 . 链接器找不到目录-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. 看起来您一个接一个的有两个-L选项,因此我将删除第一个,然后再次检查目录/usr/local/Cellar/gdal/1.11.5_2/lib存在并包含库你要。 This might be an Xcode configuration problem. 这可能是Xcode配置问题。 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 ). 此处存在同样的问题, -L选项指定一个用于查找库的附加目录, -l选项提供要包括的特定库(在本例中为gdal )。 The string -L-lgdal makes no sense, but -lgdal does make sense. 字符串-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

The library that was found is for x86_64 architecture but you're trying to build an arm64 application. 找到的库适用于x86_64体系结构,但是您正在尝试构建arm64应用程序。 If you got the libraries as pre-built binaries then go find an arm64 binary. 如果您将库作为预构建的二进制文件,则请查找arm64二进制文件。 If you built the libraries then you want to re-build them for the arm64 architecture. 如果您构建了库,则要针对arm64架构重新构建它们。

I found the answer. 我找到了答案。 I was trying to install Mac OSX applications to my iOS application. 我试图将Mac OSX应用程序安装到我的iOS应用程序。 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. 希望这对某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM