c – 成功构建iOS后没有libclang.a?

我已经为3.7版本提取了官方llvm / clang源代码,做了一些小修补(NSGetEnviron()),使用cmake为iOS配置和构建:

cmake ../llvm_37_ios \
 -DCMAKE_INSTALL_PREFIX=/Volumes/Transcend/dev/src/llvm_37_ios_armv7_installed \
 -DLLVM_ENABLE_TERMINFO=OFF \
 -DLLVM_ENABLE_THREADS=OFF \
 -DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk \
 -DCMAKE_C_FLAGS="-stdlib=libc++ -arch armv7 -mios-version-min=8.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk" \
 -DCMAKE_CXX_FLAGS="-stdlib=libc++ -arch armv7 -mios-version-min=8.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk" \
 -DCMAKE_CROSSCOMPILING=True \
 -DLLVM_TABLEGEN=/Volumes/Transcend/dev/src/llvm_37_local_build/bin/llvm-tblgen \
 -DCLANG_TABLEGEN=/Volumes/Transcend/dev/src/llvm_37_local_build/bin/clang-tblgen \
 -DCMAKE_BUILD_TYPE=Release \
 -DLLVM_TARGETS_TO_BUILD="ARM;X86"

但是我没有找到libclang.a,但发现了另一个libclang * .a libs:

MBA-Anton:llvm_37_ios_armv7_build asmirnov$find . -name "libclang.a"
MBA-Anton:llvm_37_ios_armv7_build asmirnov$find . -name "libclang*.a"
./lib/libclangBasic.a
./lib/libclangLex.a
./lib/libclangASTMatchers.a
./lib/libclangParse.a
./lib/libclangDynamicASTMatchers.a
./lib/libclangAnalysis.a
./lib/libclangEdit.a
./lib/libclangRewrite.a
./lib/libclangAST.a
./lib/libclangDriver.a
./lib/libclangCodeGen.a
./lib/libclangSerialization.a
./lib/libclangRewriteFrontend.a
./lib/libclangSema.a
./lib/libclangFrontendTool.a
./lib/libclangARCMigrate.a
./lib/libclangToolingCore.a
./lib/libclangFrontend.a
./lib/libclangIndex.a
./lib/libclangTooling.a
./lib/libclangFormat.a
./lib/libclangStaticAnalyzerFrontend.a
./lib/libclangStaticAnalyzerCore.a
./lib/libclangStaticAnalyzerCheckers.a

由于某种原因共享库已创建但静态不是:

Linking CXX executable ../../../../bin/clang
[ 98%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexDiagnostic.cpp.o
[ 98%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexHigh.cpp.o
[ 98%] Built target clang
[ 98%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexInclusionStack.cpp.o
[ 98%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexUSRs.cpp.o
[ 98%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexer.cpp.o
[ 98%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXComment.cpp.o
[ 98%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXCursor.cpp.o
[ 98%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXCompilationDatabase.cpp.o
[ 98%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXLoadedDiagnostic.cpp.o
[100%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXSourceLocation.cpp.o
[100%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXStoredDiagnostic.cpp.o
[100%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXString.cpp.o
[100%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXType.cpp.o
[100%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/IndexBody.cpp.o
[100%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/IndexDecl.cpp.o
[100%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/IndexTypeSourceInfo.cpp.o
[100%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/Indexing.cpp.o
[100%] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/IndexingContext.cpp.o
Linking CXX shared library ../../../../lib/libclang.dylib
[100%] Built target libclang

我错过了什么或它的铿锵配置错误?

解决方法:

默认情况下,libclang是作为共享库构建的,因为它使用FFI或类似机制简化了其他语言(如Python)的使用.

要构建静态库,请使用clang / tools / libclang / CMakeLists.txt中定义的LIBCLANG_BUILD_STATIC CMake选项:

option(LIBCLANG_BUILD_STATIC
  "Build libclang as a static library (in addition to a shared one)" OFF)

您可以按如下方式使用它:

cmake -DLIBCLANG_BUILD_STATIC=ON ...
上一篇:c – 使用libclang从内存中的C代码生成程序集


下一篇:c – 如何将可变数量的参数传递给LLVM opt pass?