“dyld:Library not loaded”错误 [英] "dyld: Library not loaded" error

查看:330
本文介绍了“dyld:Library not loaded”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功编译了静态库,并将其添加到XCode项目中,就像它在文档


  1. libclang.a文件位于项目目录(添加文件副本和组) / li>
  2. libclang.a列在框架中

  3. 我已将-Objc链接器标记添加到其他链接器标记 >
  4. libclang.a列在复制捆绑资源中

libclang.a是为ios模拟器编译的:

  MBA-Anton:llvm_34_build_i386 asmirnov $ lipo -info ../llvm_34_ios_i386_installed/lib/libclang.a 
输入file ../llvm_34_ios_i386_installed/lib/libclang.a不是一个胖文件
不胖的文件:../llvm_34_ios_i386_installed/lib/libclang.a是架构:i386



我可以构建这个项目,但是我在ios模拟器启动应用程序时出现错误:

  dyld:未加载的库:@ rpath / libclang.dylib 
引用自:/ Users / asmirnov / Library / Application Support / iPhone Simulator / 7.1 / Applications / D87A3FA9 -7207-40B4-9EA0-5F06CEF6EF7B / StaticLibraryUsage.app / StaticLibraryUsage
原因:找不到图片

我发现了类似的问题,但似乎我做了一切的建议。有任何想法吗?



PS。我有libclang.dylib文件,但我不确定它真的需要,因为我已经在项目中添加了libclang.a文件。



PPS。我已经编译armv7版本的libclang.a并使用 lipo 创建了带有i386和armv7的fat库。删除i386版本的libclang.a和添加胖版本的libclang.ai后,多个未解决的i386 arch建立错误的参考。



PPPS。我已通过添加所有libLLVM * .a文件在项目中解决未解决的引用错误。但现在我有原始的dyld:库未加载。



PPPPS:.m编译命令行:

  CompileC /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/Objects-normal /i386/ASAppDelegate.o StaticLibraryUsage2 / ASAppDelegate.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler 
cd / Users / asmirnov / Documents / dev / src / iOS_Projects / StaticLibraryUsage2
export LANG = en_US.US-ASCII
export PATH =/ Applications / Xcode.app / Contents / Developer / Platforms / iPhoneSimulator.platform / Developer / usr / bin:/Applications/Xcode.app/Contents/开发人员/ usr / bin:/ usr / bin:/ bin:/ usr / sbin:/ sbin
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch i386 -fmessage-length = 0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit = 0 -std = gnu99 -fobjc-arc -fmodules -fmodules-cache-path = asmirnov / Library / Developer / Xcode / DerivedData / ModuleCache -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror = return-type -Wno-implicit- Werror = deprecated-objc-isa-usage -Werror = objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing- Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wonditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno- char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-选择匹配-Wundeclared选择器-Wno弃用的实现-DDEBUG = 1 -DDEBUG = 1 -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/ iPhoneSimulator7.1.sdk -fexceptions -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -fobjc-abi-version = 2 -fobjc-legacy-dispatch -mios-simulator-version-分= 7.1 -iquote /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/StaticLibraryUsage2-generated-files.hmap -I /用户/ asmirnov / Library / Developer / Xcode / DerivedData / TestProject-axtxqjlvmrcxqsfnvgobybceosvb / Build / Intermediates / StaticLibraryUsage2.build / Debug-iphonesimulator / StaticLibraryUsage2.build / StaticLibraryUsage2-own-target-headers.hmap -I / Users / asmirnov / Xcode / DerivedData / TestProject-axtxqjlvmrcxqsfnvgobybceosvb / Build / Intermediates / StaticLibraryUsage2.build / Debug-iphonesimulator / StaticLibraryUsage2.build / StaticLibraryUsage2-all-target-headers.hmap -iquote / Users / asmirnov / Library / Developer / Xcode / DerivedData / TestProject- axtxqjlvmrcxqsfnvgobybceosvb /编译/中间体/ StaticLibraryUsage2.build /调试-iphonesimulator / StaticLibraryUsage2.build / StaticLibraryUsage2项目-headers.hmap -I /用户/ asmirnov /库/开发商/ Xcode中/ DerivedData / TestProject-axtxqjlvmrcxqsfnvgobybceosvb /建设/产品/调试 - iphonesimulator / include -I / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / include -I / Users / asmirnov / Library / Developer / Xcode / DerivedData / TestProject-axtxqjlvmrcxqsfnvgobybceosvb / Build / Intermediates / StaticLibraryUsage2。构建/调试-iphonesimulator / StaticLibraryUsage2.build / DerivedSources / I386 -I /用户/ asmirnov /库/开发商/ Xcode中/ DerivedData / TestProject-axtxqjlvmrcxqsfnvgobybceosvb /建设/中间体/ StaticLibraryUsage2.build /调试-iphonesimulator / StaticLibraryUsage2.build / DerivedSources - F /用户/ asmirnov /库/开发商/ Xcode中/ DerivedData / TestProject-axtxqjlvmrcxqsfnvgobybceosvb /建设/产品/调试-iphonesimulator -include /用户/ asmirnov /库/开发商/ Xcode中/ DerivedData / TestProject-axtxqjlvmrcxqsfnvgobybceosvb /建设/中间体/ PrecompiledHeaders / StaticLibraryUsage2前缀baynabgphydhcmapwpcclpqhagrv / StaticLibraryUsage2-Prefix.pch -MMD -MT依赖-MF /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build /Objects-normal/i386/ASAppDelegate.d --serialize诊断/Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/Objects-正常/ I386 / ASAppDelegate.dia -c /Users/asmirnov/Documents/dev/src/iOS_Projects/StaticLibraryUsage2/StaticLibraryUsage2/ASAppDelegate.m -o /用户/ asmirnov /库/开发商/ Xcode中/ DerivedData / TestProject-axtxqjlvmrcxqsfnvgobybceosvb /建设/中间体/ StaticLibraryUsage2.build / Debug-iphonesimulator / StaticLibraryUsage2.build / Objects-normal / i386 / ASAppDelegate.o

链接命令行:

  Ld / Users / asmirnov / Library / Developer / Xcode / DerivedData / TestProject-axtxqjlvmrcxqsfnvgobybceosvb / /Products/Debug-iphonesimulator/StaticLibraryUsage2.app/StaticLibraryUsage2 normal i386 
cd / Users / asmirnov / Documents / dev / src / iOS_Projects / StaticLibraryUsage2
export IPHONEOS_DEPLOYMENT_TARGET = 7.1
export PATH =/ Applications / Xcode.app / Contents / Developer / Platforms / iPhoneSimulator.platform / Developer / usr / bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/ usr / bin:/ bin:/ usr / sbin: / sbin
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform /Developer/SDKs/iPhoneSimulator7.1.sdk -L / Users / asmirnov / Library / Developer / Xcode / DerivedData / TestProject-axtxqjlvmrcxqsfnvgobybceosvb / Build / Products / Debug-iphonesimulator -L / Users / asmirnov / Documents / dev / src / llvm_34_ios_fat_installed -L / Users / asmirnov / Documents / dev / src / iOS_Projects / StaticLibraryUsage2 / StaticLibraryUsage2 -L / Users / asmirnov / Documents / dev / src / llvm_34_ios_i386_installed_2 / lib -F / Users / asmirnov / Library / Developer / Xcode / DerivedData / TestProject -axtxqjlvmrcxqsfnvgobybceosvb /编译/产品/调试,iphonesimulator -filelist /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/Objects-normal/i386 /StaticLibraryUsage2.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -ObjC -lstdc ++ -fobjc弧-fobjc链接运行时-Xlinker -no_implicit_dylibs -mios模拟器版本分钟= 7.1 -lLLVMRuntimeDyld -lLLVMSystemZAsmParser -lLLVMAArch64CodeGen -lLLVMTarget -lLLVMMCJIT - lLLVMX86Disassembler -lLLVMExecutionEngine -lLLVMPowerPCInfo -lLLVMHexagonAsmPrinter -lLLVMX86Utils -lLLVMPowerPCAsmParser -lclangDriver -lLLVMARMInfo -lLLVMAArch64AsmParser -lLLVMHexagonDesc -lLLVMipa -lclangARCMigrate -lLLVMMipsDesc -lLLVMNVPTXCodeGen -lLLVMBitWriter -lLLVMXCoreDisassembler -lLLVMNVPTXDesc -lLLVMX86CodeGen -lLLVMHexagonInfo -lLLVMSystemZAsmPrinter -lLLVMTableGen -lLLVMSystemZCodeGen -lLLVMInstrumentation -lLLVMAArch64Disassembler -lLLVMX86AsmPrinter - lLLVMCppBackendInfo -lclangBasic -lLLVMCodeGen -lLLVMDebugInfo -lLLVMAArch64Utils -lLLVMNVPTXAsmPrinter -framework CoreGraphics中-lLLVMAsmParser -lLLVMSparcCodeGen -lclangFormat -lLLVMXCoreDesc -lLLVMipo -lLLVMObject -lclang -lLLVMX86Desc -lLLVMPowerPCDesc -lLLVMXCoreCodeGen -lLLVMVectorize -lclangAST -lclangSema -lclangTooling -lLLVMIRReader -lLLVMMipsCodeGen -lclangRewriteCore -lLLVMXCoreAsmPrinter -lLLVMMSP430Desc -lLLVMInstCombine -lLLVMAArch64AsmPrinter -lLLVMMCParser -lLLVMR600Info -lLLVMMipsAsmPrinter -lLLVMMipsAsmParser -lLLVMMCDisassembler -lLLVMBitReader -lclangAnalysis -lclangStaticAnalyzerCore -lLLVMMipsDisassembler -lLLVMR600AsmPrinter -lLLVMR600CodeGen -lLLVMAArch64Info -lclangDynamicASTMatchers -lLLVMARMAsmPrinter -lLLVMXCoreInfo -lclangStaticAnalyzerFrontend -lLLVMMipsInfo -lLLVMSelectionDAG -lLLVMTransformUtils -lLLVMSparcInfo -lLLVMR600Desc -lLLVMOption -lLLVMAArch64Desc -lLLVMObjCARCOpts -lLLVMJIT -lclangEdit -lLLVMSystemZDesc -lLLVMARMDesc -lLLVMSparcDesc -lLLVMMC -lLLVMMSP430CodeGen -lLTO -lLLVMHexagonCodeGen -lLLVMMSP430AsmPrinter -framework UIKit的-lLLVMAnalysis -lLLVMMSP430Info -lLLVMARMCodeGen -lLLVMARMAsmParser -lclangCodeGen -lLLVMLinker -lLLVMPowerPCCodeGen -lLLVMAsmPrinter -lLLVMX86AsmParser -lLLVMSystemZInfo -framework基金会-lclangASTMatchers -lLLVMScalarOpts -lLLVMPowerPCAsmPrinter -lLLVMARMDisassembler -lLLVMNVPTXInfo -lclangParse -lclangIndex -lclangStaticAnalyzerCheckers -lclangRewriteFrontend -lLLVMInterpreter -lclangLex -lLLVMCppBackendCodeGen -lLLVMX86Info -lLLVMCore -lLLVMLTO -lclangFrontend -lclangFrontendTool -lLLVMSupport -lLLVMSystemZDisassembler -lclangSerialization -Xlinker -dependency_info -Xlinker /用户/ asmirnov /Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/Objects-normal/i386/StaticLibraryUsage2_dependency_info.dat -o /用户/ asmirnov /库/开发/的Xcode /DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Products/Debug-iphonesimulator/StaticLibraryUsage2.app/StaticLibraryUsage2

libclang .a添加到可执行命令行:

  CpResource / Users / asmirnov / Documents / dev / src / llvm_34_ios_i386_installed_2 / lib / libclang .A /Users/asmirnov/Library/Developer/Xcode/DerivedData/PocketIDE-axtxqjlvmrcxqsfnvgobybceosvb/Build/Products/Debug-iphonesimulator/StaticLibraryUsage2.app/libclang.a 
CD /用户/ asmirnov /文件为/ dev / SRC / iOS_Projects / StaticLibraryUsage2
出口PATH =/应用/ Xcode.app /内容/开发/平台/ iPhoneSimulator.platform /开发人员的/ usr / bin中:/Applications/Xcode.app/Contents/Developer/usr/bin:/ usr / bin:/ bin:/ usr / sbin:/ sbin
builtin-copy -exclude .DS_Store -exclude CVS -exclude .svn -exclude .git -exclude .hg -resolve-src-symlinks / Users / asmirnov /文件为/ dev / SRC / llvm_34_ios_i386_installed_2 / lib中/ libclang.a /Users/asmirnov/Library/Developer/Xcode/DerivedData/PocketIDE-axtxqjlvmrcxqsfnvgobybceosvb/Build/Products/Debug-iphonesimulator/StaticLibraryUsage2.app

控制器代码测试libclang:

  #importIndex.h

// ...

//显示diagnostics
void showHighlight(CXTranslationUnit TU,const char * src_filename,unsigned文件大小)
{
if(TU)
NSLog(@翻译单位有效:%s\\\
,src_filename);

CXFile file = clang_getFile(TU,src_filename);

if(file)
NSLog(@file is valid,size =%i\\\
,filesize);

unsigned int line,column,offset;

CXToken * tokens;
unsigned numTokens;

// range =所有文件
CXSourceLocation beginning = clang_getLocationForOffset(TU,file,0);
CXSourceLocation end = clang_getLocationForOffset(TU,file,filesize);
CXSourceRange range = clang_getRange(beginning,end);

clang_tokenize(TU,range,& tokens,& numTokens);

NSLog(@%i tokens:\\\
,numTokens);

for(int i = 0; i CXToken token = tokens [i];

CXTokenKind kind = clang_getTokenKind(token);
CXSourceLocation location = clang_getTokenLocation(TU,token);
clang_getSpellingLocation(location,& file,& line,& column,& offset);
CXString filename = clang_getFileName(file);
CXString spelling = clang_getTokenSpelling(TU,token);

NSLog(@kind = [%s],[%s%i:%i offset =%i] [%s] \\\

kinds [kind] clang_getCString(filename),line,column,offset,clang_getCString(spelling));

clang_disposeString(filename);
clang_disposeString(spelling);
}

clang_disposeTokens(TU,tokens,numTokens);
}

unsigned getfilesize(const char * filename)
{
FILE * fp = fopen(filename,r);
fseek(fp,0L,SEEK_END);
unsigned sz = ftell(fp);
fclose(fp);
return sz;
}
- (void)testClang
{
NSLog(@started);

//从bundle获取文件
NSString * ns_filename = [[NSBundle mainBundle] pathForResource:@test_hlofType:@cpp];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:ns_filename];
NSLog(@文件%@存在:%d,ns_filename,fileExists);

CXIndex index = clang_createIndex(false,false);

//命令行tu
const char * filename = [ns_filename UTF8String];
const char * argv = {filename};
int argc = 1;
CXTranslationUnit commandLineTu = clang_parseTranslationUnit(index,0,& argv,argc,0,0,CXTranslationUnit_None);

unsigned filesize = getfilesize(filename);
showHighlight(commandLineTu,filename,filesize);

clang_disposeTranslationUnit(commandLineTu);
clang_disposeIndex(index);

NSLog(@finished);
}

- (void)viewWillAppear:(BOOL)animated
{
[self testClang];
}


解决方案

告诉你是lib clang认为它的@rpath是在你的应用程序包的根,但它不是。



我想到了这一点,只是在另一天。
很难。
你必须使用libclang.a使用构建阶段设置做一些疯狂的东西。
在目标的构建阶段中,您需要添加几个运行脚本阶段。



一个是:

  echowarning:OTOOL BEGIN1; 
pwd;
otool -L $ {SRCROOT} /Clangwrap/ClangAndLLVM/lib/libclang.dylib;
echoWarning:OTOOL END1;

这只是做了一些事情。
首先,它很好地把一个日志三明治,看看发生了什么。
第二个是它真的只是确认你的lib的路径,一旦它被复制。 (是的,你应该把它复制到你的项目,保持健康。)
otool这样做。
SRCROOT是你的项目的根目录,那么之后的任何内容是你在Finder中的项目文件夹中的相对路径到你要使用的lib。



再次,这只是确认它是你认为它是在哪里。



好的,下一步。这是真正的doozy。

  echoBEGIN install_name_tool 
install_name_tool -id @executable_path /../ Frameworks / libclang.dylib $ {SRCROOT} /Clangwrap/ClangAndLLVM/lib/libclang.dylib;
echoEND install_name_tool;

这运行模糊的命令行工具install_name_tool,用于设置lib认为它的路径位于您的应用程序包中。没有这样做,lib会认为它是在其他路径。你将设置这个路径到你打算它是什么。在Mac应用程序中,我使用Frameworks文件夹内的bundle,所以我这样设置。 install_name_tool的第一个参数是您的应用程序包中的相对路径,即lib将要。第二个参数是lib目前在您的项目中,以便install_name_tool可以设置其可执行路径。
这个字面上修改了lib的一个位,所以它是可加载的。 libs必须知道自己的加载路径。



请注意,第一步只是您自己的可选属性。
第二步是必需的,两者都应该在编译源构建阶段之前发生。
单击并拖动以将其向上移动。



现在最后一步。添加一个新的复制文件阶段,这将保持在您的构建阶段的最后。
将目标设置为与install_name_tool的第一个参数相同,因此您知道您的相对路径已设置,并且您将要放置lib。
我使用框架。
现在添加文件到这个Build阶段,对于iPhone,添加libclang.a(我不认为你可以使用libclang.dylib在iOS上)



注意,你看到我使用libclang.dylib,这是因为我在Mac应用程序项目。



这不是一个简单或可发现的过程,我从几个博客和文档拼凑而成。


i have successfully compiled static library and added it to the XCode project just like it's written in documentation:

  1. libclang.a file is in project directory (added file copy and group)
  2. libclang.a is listed in "Frameworks"
  3. i've added '-Objc' linker flag to 'Other linker flags'.
  4. libclang.a is listed in "Copy bundle resources"

libclang.a is compiled for ios simulator:

MBA-Anton:llvm_34_build_i386 asmirnov$ lipo -info ../llvm_34_ios_i386_installed/lib/libclang.a
input file ../llvm_34_ios_i386_installed/lib/libclang.a is not a fat file
Non-fat file: ../llvm_34_ios_i386_installed/lib/libclang.a is architecture: i386

I'm able to build the project but i'm getting error while ios simulator starts the app:

dyld: Library not loaded: @rpath/libclang.dylib
  Referenced from: /Users/asmirnov/Library/Application Support/iPhone Simulator/7.1/Applications/D87A3FA9-7207-40B4-9EA0-5F06CEF6EF7B/StaticLibraryUsage.app/StaticLibraryUsage
  Reason: image not found

I have found similar questions but it seems i did everything what was recommended. Any thoughts?

PS. I have libclang.dylib file but i'm not sure it's really needed since i have added libclang.a file in the project.

PPS. I have compiled armv7 version of libclang.a and created fat library with both i386 and armv7 using lipo. After removing i386 version of libclang.a and adding fat version of libclang.a i have multiple unresolved references for i386 arch build errors.

PPPS. I have resolved "unresolved references" errors by adding all libLLVM*.a files in the project. but now i'm having original "dyld: Library not loaded".

PPPPS: .m compile command-line:

CompileC /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/Objects-normal/i386/ASAppDelegate.o StaticLibraryUsage2/ASAppDelegate.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/asmirnov/Documents/dev/src/iOS_Projects/StaticLibraryUsage2
    export LANG=en_US.US-ASCII
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch i386 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-cache-path=/Users/asmirnov/Library/Developer/Xcode/DerivedData/ModuleCache -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -DDEBUG=1 -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk -fexceptions -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch -mios-simulator-version-min=7.1 -iquote /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/StaticLibraryUsage2-generated-files.hmap -I/Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/StaticLibraryUsage2-own-target-headers.hmap -I/Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/StaticLibraryUsage2-all-target-headers.hmap -iquote /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/StaticLibraryUsage2-project-headers.hmap -I/Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Products/Debug-iphonesimulator/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/DerivedSources/i386 -I/Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/DerivedSources -F/Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Products/Debug-iphonesimulator -include /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/PrecompiledHeaders/StaticLibraryUsage2-Prefix-baynabgphydhcmapwpcclpqhagrv/StaticLibraryUsage2-Prefix.pch -MMD -MT dependencies -MF /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/Objects-normal/i386/ASAppDelegate.d --serialize-diagnostics /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/Objects-normal/i386/ASAppDelegate.dia -c /Users/asmirnov/Documents/dev/src/iOS_Projects/StaticLibraryUsage2/StaticLibraryUsage2/ASAppDelegate.m -o /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/Objects-normal/i386/ASAppDelegate.o

link command-line:

Ld /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Products/Debug-iphonesimulator/StaticLibraryUsage2.app/StaticLibraryUsage2 normal i386
    cd /Users/asmirnov/Documents/dev/src/iOS_Projects/StaticLibraryUsage2
    export IPHONEOS_DEPLOYMENT_TARGET=7.1
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk -L/Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Products/Debug-iphonesimulator -L/Users/asmirnov/Documents/dev/src/llvm_34_ios_fat_installed -L/Users/asmirnov/Documents/dev/src/iOS_Projects/StaticLibraryUsage2/StaticLibraryUsage2 -L/Users/asmirnov/Documents/dev/src/llvm_34_ios_i386_installed_2/lib -F/Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Products/Debug-iphonesimulator -filelist /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/Objects-normal/i386/StaticLibraryUsage2.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -ObjC -lstdc++ -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=7.1 -lLLVMRuntimeDyld -lLLVMSystemZAsmParser -lLLVMAArch64CodeGen -lLLVMTarget -lLLVMMCJIT -lLLVMX86Disassembler -lLLVMExecutionEngine -lLLVMPowerPCInfo -lLLVMHexagonAsmPrinter -lLLVMX86Utils -lLLVMPowerPCAsmParser -lclangDriver -lLLVMARMInfo -lLLVMAArch64AsmParser -lLLVMHexagonDesc -lLLVMipa -lclangARCMigrate -lLLVMMipsDesc -lLLVMNVPTXCodeGen -lLLVMBitWriter -lLLVMXCoreDisassembler -lLLVMNVPTXDesc -lLLVMX86CodeGen -lLLVMHexagonInfo -lLLVMSystemZAsmPrinter -lLLVMTableGen -lLLVMSystemZCodeGen -lLLVMInstrumentation -lLLVMAArch64Disassembler -lLLVMX86AsmPrinter -lLLVMCppBackendInfo -lclangBasic -lLLVMCodeGen -lLLVMDebugInfo -lLLVMAArch64Utils -lLLVMNVPTXAsmPrinter -framework CoreGraphics -lLLVMAsmParser -lLLVMSparcCodeGen -lclangFormat -lLLVMXCoreDesc -lLLVMipo -lLLVMObject -lclang -lLLVMX86Desc -lLLVMPowerPCDesc -lLLVMXCoreCodeGen -lLLVMVectorize -lclangAST -lclangSema -lclangTooling -lLLVMIRReader -lLLVMMipsCodeGen -lclangRewriteCore -lLLVMXCoreAsmPrinter -lLLVMMSP430Desc -lLLVMInstCombine -lLLVMAArch64AsmPrinter -lLLVMMCParser -lLLVMR600Info -lLLVMMipsAsmPrinter -lLLVMMipsAsmParser -lLLVMMCDisassembler -lLLVMBitReader -lclangAnalysis -lclangStaticAnalyzerCore -lLLVMMipsDisassembler -lLLVMR600AsmPrinter -lLLVMR600CodeGen -lLLVMAArch64Info -lclangDynamicASTMatchers -lLLVMARMAsmPrinter -lLLVMXCoreInfo -lclangStaticAnalyzerFrontend -lLLVMMipsInfo -lLLVMSelectionDAG -lLLVMTransformUtils -lLLVMSparcInfo -lLLVMR600Desc -lLLVMOption -lLLVMAArch64Desc -lLLVMObjCARCOpts -lLLVMJIT -lclangEdit -lLLVMSystemZDesc -lLLVMARMDesc -lLLVMSparcDesc -lLLVMMC -lLLVMMSP430CodeGen -lLTO -lLLVMHexagonCodeGen -lLLVMMSP430AsmPrinter -framework UIKit -lLLVMAnalysis -lLLVMMSP430Info -lLLVMARMCodeGen -lLLVMARMAsmParser -lclangCodeGen -lLLVMLinker -lLLVMPowerPCCodeGen -lLLVMAsmPrinter -lLLVMX86AsmParser -lLLVMSystemZInfo -framework Foundation -lclangASTMatchers -lLLVMScalarOpts -lLLVMPowerPCAsmPrinter -lLLVMARMDisassembler -lLLVMNVPTXInfo -lclangParse -lclangIndex -lclangStaticAnalyzerCheckers -lclangRewriteFrontend -lLLVMInterpreter -lclangLex -lLLVMCppBackendCodeGen -lLLVMX86Info -lLLVMCore -lLLVMLTO -lclangFrontend -lclangFrontendTool -lLLVMSupport -lLLVMSystemZDisassembler -lclangSerialization -Xlinker -dependency_info -Xlinker /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Intermediates/StaticLibraryUsage2.build/Debug-iphonesimulator/StaticLibraryUsage2.build/Objects-normal/i386/StaticLibraryUsage2_dependency_info.dat -o /Users/asmirnov/Library/Developer/Xcode/DerivedData/TestProject-axtxqjlvmrcxqsfnvgobybceosvb/Build/Products/Debug-iphonesimulator/StaticLibraryUsage2.app/StaticLibraryUsage2

libclang.a adding to executable command-line:

CpResource /Users/asmirnov/Documents/dev/src/llvm_34_ios_i386_installed_2/lib/libclang.a /Users/asmirnov/Library/Developer/Xcode/DerivedData/PocketIDE-axtxqjlvmrcxqsfnvgobybceosvb/Build/Products/Debug-iphonesimulator/StaticLibraryUsage2.app/libclang.a
    cd /Users/asmirnov/Documents/dev/src/iOS_Projects/StaticLibraryUsage2
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    builtin-copy -exclude .DS_Store -exclude CVS -exclude .svn -exclude .git -exclude .hg -resolve-src-symlinks /Users/asmirnov/Documents/dev/src/llvm_34_ios_i386_installed_2/lib/libclang.a /Users/asmirnov/Library/Developer/Xcode/DerivedData/PocketIDE-axtxqjlvmrcxqsfnvgobybceosvb/Build/Products/Debug-iphonesimulator/StaticLibraryUsage2.app

controller code to test libclang:

#import "Index.h"

// ...

// show diagnostics
void showHighlight(CXTranslationUnit TU, const char *src_filename, unsigned filesize)
{
    if (TU)
        NSLog(@"Translation unit valid: %s\n", src_filename);

    CXFile file = clang_getFile(TU, src_filename);

    if (file)
        NSLog(@"file is valid, size = %i\n", filesize);

    unsigned int line, column, offset;

    CXToken *tokens;
    unsigned numTokens;

    // range = all the file
    CXSourceLocation beginning = clang_getLocationForOffset(TU, file, 0);
    CXSourceLocation end = clang_getLocationForOffset(TU, file, filesize);
    CXSourceRange range = clang_getRange(beginning, end);

    clang_tokenize(TU, range, &tokens, &numTokens);

    NSLog(@"%i tokens:\n", numTokens);

    for (int i=0; i<numTokens; i++) {
        CXToken token = tokens[i];

        CXTokenKind kind = clang_getTokenKind(token);
        CXSourceLocation location = clang_getTokenLocation(TU, token);
        clang_getSpellingLocation(location, &file, &line, &column, &offset);
        CXString filename = clang_getFileName(file);
        CXString spelling = clang_getTokenSpelling(TU, token);

        NSLog(@"kind=[%s], [%s %i:%i offset=%i] [%s]\n",
                kinds[kind], clang_getCString(filename), line, column, offset, clang_getCString(spelling));

        clang_disposeString(filename);
        clang_disposeString(spelling);
    }

    clang_disposeTokens(TU, tokens, numTokens);
}

unsigned getfilesize(const char* filename)
{
    FILE *fp = fopen(filename, "r");
    fseek(fp, 0L, SEEK_END);
    unsigned sz = ftell(fp);
    fclose(fp);
    return sz;
}
- (void)testClang
{
    NSLog(@"started");

    // get file from bundle
    NSString *ns_filename = [[NSBundle mainBundle] pathForResource:@"test_hl" ofType:@"cpp"];
    BOOL fileExists = [[NSFileManager defaultManager]fileExistsAtPath:ns_filename];
    NSLog(@"file %@ exists: %d", ns_filename, fileExists);

    CXIndex index = clang_createIndex(false, false);

    // command-line tu
    const char *filename = [ns_filename UTF8String];
    const char *argv = { filename };
    int argc = 1;
    CXTranslationUnit commandLineTu = clang_parseTranslationUnit(index, 0, &argv, argc, 0, 0, CXTranslationUnit_None);

    unsigned filesize = getfilesize(filename);
    showHighlight(commandLineTu, filename, filesize);

    clang_disposeTranslationUnit(commandLineTu);
    clang_disposeIndex(index);

    NSLog(@"finished");
}

- (void)viewWillAppear:(BOOL)animated
{
    [self testClang];
}

解决方案

What this error is sadly trying to tell you is that lib clang thinks its @rpath is at the root of your app bundle, but it's not.

I figured this out the hard way just the other day. It's hard. You have to do some crazy stuff with libclang.a using Build Phase settings. In your target's Build Phases, you will need to add a few Run Script Phases.

One will be this:

echo "warning: OTOOL BEGIN1";
pwd;
otool -L ${SRCROOT}/Clangwrap/ClangAndLLVM/lib/libclang.dylib;
echo "Warning: OTOOL END1";

This just does a few things. First it nicely sandwiches things with a log to see what happened. The second is it really is just confirming the path to your lib once it's copied. (and yes, you should be copying it into your project to keep things sane.) otool does this. SRCROOT is the root of your project, then anything after that is your relative path within you project's folder in Finder to the lib you are going to use.

Again, this just confirms it is where you think it is.

Ok, next step. This is the real doozy.

echo "BEGIN install_name_tool";
install_name_tool -id @executable_path/../Frameworks/libclang.dylib ${SRCROOT}/Clangwrap/ClangAndLLVM/lib/libclang.dylib;
echo "END install_name_tool";

This runs the obscure command line tool install_name_tool and that is used to set the path where the lib thinks it is located within your app's bundle. Without doing this, the lib will think it is in some other path. You will be setting this path to what you intend it to be. In a Mac app, I used the Frameworks folder inside the bundle so I set it as such. The first argument to install_name_tool is the relative path in your app bundle where the lib is going to be. The second argument is where the lib is currently in your project so that install_name_tool can set its executable path. This literally modifies a bit of the lib so it is loadable. libs must know their own load path.

Note the first step is only optional for your own sanity. The second step is required, and both should occur before the Compile Sources Build Phase. Click and drag to move them up.

Now the final step. Add a new Copy Files Phase and this will remain last in your build phases. Set the destination to the same as the first arg of install_name_tool so you know your relative path is set and that's where you're going to put the lib. I used Frameworks. Now add the files to this Build Phase, for iPhone, add libclang.a (I don't think you can use libclang.dylib on iOS)

Note, you saw me use libclang.dylib and that's because I did this on a Mac app project. It should be the same process for just about anything.

this is not an easy or discoverable process, I pieced it together from several blogs and docs.

这篇关于“dyld:Library not loaded”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆