LLVM : Unknown CMake command "add_llvm_loadable_module".

编写LLVM Pass的文档:HowToWriteALLVMPass

1.写Makefile

# Makefile for hello pass

# Path to top level of LLVM hierarchy
LEVEL = ../../..

# Name of the library to build
LIBRARYNAME = Hello

# Make the shared library become a loadable module so the tools can
# dlopen/dlsym on the resulting library.
LOADABLE_MODULE = 1

# Include the makefile implementation stuff
include $(LEVEL)/Makefile.common
2.写Hello.cpp


3.得到Hello.so。

clang++ `llvm-config --libs --ldflags --cxxflags ` Hello.cpp -std=c++0x -fPIC -shared -o Hello.so

4.使用Hello.so。

opt -load /usr/local/arm/llvm3.8.0/lib/Transforms/Hello/Hello.so -hello <hello.bc> /dev/null


在尝试编写一个LLVM pass时,遇到以下问题(未解决,最终使用的第3步的方法):

CMake Error at CMakeLists.txt:16 (include):

  include could not find load file:

    AddLLVM

CMake Error at CMakeLists.txt:17 (add_llvm_loadable_module):
  Unknown CMake command "add_llvm_loadable_module".

-- Configuring incomplete, errors occurred!

Building LLVM with CMake 点击打开链接

[2025-10-05T02:28:03.374Z] [system]: FAILED: out/soong/.intermediates/vendor/sprd/platform/frameworks/av/service/audio/audiopolicy/engineconfigurable/libunisocaudiopolicyengineconfigurable/android_arm64_armv8-2a_cortex-a55_shared/unstripped/libunisocaudiopolicyengineconfigurable.so [2025-10-05T02:28:03.374Z] [system]: prebuilts/clang/host/linux-x86/clang-r547379/bin/clang++ out/soong/.intermediates/bionic/libc/crtbegin_so/android_arm64_armv8-2a_cortex-a55/crtbegin_so.o @out/soong/.intermediates/vendor/sprd/platform/frameworks/av/service/audio/audiopolicy/engineconfigurable/libunisocaudiopolicyengineconfigurable/android_arm64_armv8-2a_cortex-a55_shared/unstripped/libunisocaudiopolicyengineconfigurable.so.rsp out/soong/.intermediates/bionic/libc/crtend_so/android_arm64_armv8-2a_cortex-a55/crtend_so.o out/soong/.intermediates/bionic/libc/crt_pad_segment/android_arm64_armv8-2a_cortex-a55/crt_pad_segment.o -o out/soong/.intermediates/vendor/sprd/platform/frameworks/av/service/audio/audiopolicy/engineconfigurable/libunisocaudiopolicyengineconfigurable/android_arm64_armv8-2a_cortex-a55_shared/unstripped/libunisocaudiopolicyengineconfigurable.so -target aarch64-linux-android10000 -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 -Wl,--fatal-warnings -Wl,--no-undefined-version -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_stripped.a -Wl,--exclude-libs,libunwind_llvm.a -Wl,--exclude-libs,libunwind.a -fuse-ld=lld -Wl,--icf=safe -Wl,--no-demangle -Wl,--compress-debug-sections=zstd -Wl,--no-undefined -Wl,-z,separate-code -Wl,-z,separate-loadable-segments -Wl,-z,max-page-size=16384 -Wl,--pack-dyn-relocs=android+relr -nostdlib -Wl,--gc-sections -shared -Wl,-soname,libunisocaudiopolicyengineconfigurable.so -flto=thin -fsplit-lto-unit -Wl,-plugin-opt,-import-instr-limit=5 -Wl,-mllvm,-regalloc-enable-advisor=release -Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a -Wl,--exclude-libs=libclang_rt.ubsan_minimal-aarch64-android.a [2025-10-05T02:28:03.374Z] [system]: ld.lld: error: undefined symbol: _ZN7android22AudioPolicyManagerStub33loadAudioPolicyEngineConfigCustomEv [2025-10-05T02:28:03.374Z] [system]: >>> referenced by EngineBase.cpp:232 (frameworks/av/services/audiopolicy/engine/common/src/EngineBase.cpp:232) [2025-10-05T02:28:03.374Z] [system]: >>> out/soong/.intermediates/frameworks/av/services/audiopolicy/engine/common/libaudiopolicyengine_common/android_arm64_armv8-2a_cortex-a55_static/libunisocaudiopolicyengineconfigurable.so.lto.libaudiopolicyengine_common.a(EngineBase.o at 544442).o:(_ZN7android12audio_policy10EngineBase27loadAudioPolicyEngineConfigERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEb) [2025-10-05T02:28:03.374Z] [system]: clang++: error: linker command failed with exit code 1 (use -v to see invocation)
最新发布
10-06
使用clang++编译,报错: /usr/bin/ld: /usr/local/lib/libclangSerialization.a(ASTWriter.cpp.o): in function `llvm::SHA1::SHA1()': ASTWriter.cpp:(.text._ZN4llvm4SHA1C2Ev[_ZN4llvm4SHA1C5Ev]+0x14): undefined reference to `llvm::SHA1::init()' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(ASTWriter.cpp.o): in function `clang::ASTWriter::createSignature() const [clone .localalias]': ASTWriter.cpp:(.text._ZNK5clang9ASTWriter15createSignatureEv+0xa0): undefined reference to `llvm::SHA1::update(llvm::StringRef)' /usr/bin/ld: ASTWriter.cpp:(.text._ZNK5clang9ASTWriter15createSignatureEv+0xb6): undefined reference to `llvm::SHA1::result()' /usr/bin/ld: ASTWriter.cpp:(.text._ZNK5clang9ASTWriter15createSignatureEv+0x11d): undefined reference to `llvm::SHA1::update(llvm::StringRef)' /usr/bin/ld: ASTWriter.cpp:(.text._ZNK5clang9ASTWriter15createSignatureEv+0x15a): undefined reference to `llvm::SHA1::update(llvm::StringRef)' /usr/bin/ld: ASTWriter.cpp:(.text._ZNK5clang9ASTWriter15createSignatureEv+0x193): undefined reference to `llvm::SHA1::update(llvm::StringRef)' /usr/bin/ld: ASTWriter.cpp:(.text._ZNK5clang9ASTWriter15createSignatureEv+0x1a9): undefined reference to `llvm::SHA1::result()' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(ASTWriter.cpp.o): in function `clang::ASTWriter::createSignatureForNamedModule() const [clone .localalias]': ASTWriter.cpp:(.text._ZNK5clang9ASTWriter29createSignatureForNamedModuleEv+0x86): undefined reference to `llvm::SHA1::update(llvm::StringRef)' /usr/bin/ld: ASTWriter.cpp:(.text._ZNK5clang9ASTWriter29createSignatureForNamedModuleEv+0x1ba): undefined reference to `llvm::SHA1::update(llvm::ArrayRef<unsigned char>)' /usr/bin/ld: ASTWriter.cpp:(.text._ZNK5clang9ASTWriter29createSignatureForNamedModuleEv+0x23b): undefined reference to `llvm::SHA1::update(llvm::ArrayRef<unsigned char>)' /usr/bin/ld: ASTWriter.cpp:(.text._ZNK5clang9ASTWriter29createSignatureForNamedModuleEv+0x258): undefined reference to `llvm::SHA1::result()' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(ASTWriter.cpp.o): in function `emitBlob(llvm::BitstreamWriter&, llvm::StringRef, unsigned int, unsigned int)': ASTWriter.cpp:(.text._ZL8emitBlobRN4llvm15BitstreamWriterENS_9StringRefEjj+0x44): undefined reference to `llvm::compression::zstd::isAvailable()' /usr/bin/ld: ASTWriter.cpp:(.text._ZL8emitBlobRN4llvm15BitstreamWriterENS_9StringRefEjj+0x9a): undefined reference to `llvm::compression::zstd::compress(llvm::ArrayRef<unsigned char>, llvm::SmallVectorImpl<unsigned char>&, int, bool)' /usr/bin/ld: ASTWriter.cpp:(.text._ZL8emitBlobRN4llvm15BitstreamWriterENS_9StringRefEjj+0x123): undefined reference to `llvm::compression::zlib::isAvailable()' /usr/bin/ld: ASTWriter.cpp:(.text._ZL8emitBlobRN4llvm15BitstreamWriterENS_9StringRefEjj+0x173): undefined reference to `llvm::compression::zlib::compress(llvm::ArrayRef<unsigned char>, llvm::SmallVectorImpl<unsigned char>&, int)' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(ASTWriter.cpp.o): in function `clang::ASTRecordWriter::AddCXXDefinitionData(clang::CXXRecordDecl const*) [clone .localalias]': ASTWriter.cpp:(.text._ZN5clang15ASTRecordWriter20AddCXXDefinitionDataEPKNS_13CXXRecordDeclE+0x1a98): undefined reference to `clang::CXXRecordDecl::getFirstFriend() const' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(ASTWriterDecl.cpp.o): in function `clang::ASTDeclWriter::VisitOMPDeclareReductionDecl(clang::OMPDeclareReductionDecl*) [clone .localalias]': ASTWriterDecl.cpp:(.text._ZN5clang13ASTDeclWriter28VisitOMPDeclareReductionDeclEPNS_23OMPDeclareReductionDeclE+0x139): undefined reference to `clang::OMPDeclareReductionDecl::getPrevDeclInScope()' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(ASTWriterDecl.cpp.o): in function `clang::ASTDeclWriter::VisitOMPDeclareMapperDecl(clang::OMPDeclareMapperDecl*) [clone .localalias]': ASTWriterDecl.cpp:(.text._ZN5clang13ASTDeclWriter25VisitOMPDeclareMapperDeclEPNS_20OMPDeclareMapperDeclE+0x6e): undefined reference to `clang::OMPDeclareMapperDecl::getPrevDeclInScope()' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(GlobalModuleIndex.cpp.o): in function `clang::GlobalModuleIndex::GlobalModuleIndex(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::BitstreamCursor) [clone .localalias]': GlobalModuleIndex.cpp:(.text._ZN5clang17GlobalModuleIndexC2ESt10unique_ptrIN4llvm12MemoryBufferESt14default_deleteIS3_EENS2_15BitstreamCursorE+0x236): undefined reference to `llvm::BitstreamCursor::EnterSubBlock(unsigned int, unsigned int*)' /usr/bin/ld: GlobalModuleIndex.cpp:(.text._ZN5clang17GlobalModuleIndexC2ESt10unique_ptrIN4llvm12MemoryBufferESt14default_deleteIS3_EENS2_15BitstreamCursorE+0x33c): undefined reference to `llvm::BitstreamCursor::readRecord(unsigned int, llvm::SmallVectorImpl<unsigned long>&, llvm::StringRef*)' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(GlobalModuleIndex.cpp.o): in function `clang::GlobalModuleIndex::readIndex(llvm::StringRef)': GlobalModuleIndex.cpp:(.text._ZN5clang17GlobalModuleIndex9readIndexEN4llvm9StringRefE+0x246): undefined reference to `llvm::MemoryBufferRef::MemoryBufferRef(llvm::MemoryBuffer const&)' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(GlobalModuleIndex.cpp.o): in function `(anonymous namespace)::GlobalModuleIndexBuilder::loadModuleFile(clang::FileEntryRef)': GlobalModuleIndex.cpp:(.text._ZN12_GLOBAL__N_124GlobalModuleIndexBuilder14loadModuleFileEN5clang12FileEntryRefE+0x111): undefined reference to `llvm::MemoryBufferRef::MemoryBufferRef(llvm::MemoryBuffer const&)' /usr/bin/ld: GlobalModuleIndex.cpp:(.text._ZN12_GLOBAL__N_124GlobalModuleIndexBuilder14loadModuleFileEN5clang12FileEntryRefE+0x389): undefined reference to `llvm::BitstreamCursor::skipRecord(unsigned int)' /usr/bin/ld: GlobalModuleIndex.cpp:(.text._ZN12_GLOBAL__N_124GlobalModuleIndexBuilder14loadModuleFileEN5clang12FileEntryRefE+0x417): undefined reference to `llvm::BitstreamCursor::EnterSubBlock(unsigned int, unsigned int*)' /usr/bin/ld: GlobalModuleIndex.cpp:(.text._ZN12_GLOBAL__N_124GlobalModuleIndexBuilder14loadModuleFileEN5clang12FileEntryRefE+0x4ad): undefined reference to `llvm::BitstreamCursor::EnterSubBlock(unsigned int, unsigned int*)' /usr/bin/ld: GlobalModuleIndex.cpp:(.text._ZN12_GLOBAL__N_124GlobalModuleIndexBuilder14loadModuleFileEN5clang12FileEntryRefE+0x543): undefined reference to `llvm::BitstreamCursor::EnterSubBlock(unsigned int, unsigned int*)' /usr/bin/ld: GlobalModuleIndex.cpp:(.text._ZN12_GLOBAL__N_124GlobalModuleIndexBuilder14loadModuleFileEN5clang12FileEntryRefE+0x687): undefined reference to `llvm::BitstreamCursor::readRecord(unsigned int, llvm::SmallVectorImpl<unsigned long>&, llvm::StringRef*)' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(GlobalModuleIndex.cpp.o): in function `clang::GlobalModuleIndex::writeIndex(clang::FileManager&, clang::PCHContainerReader const&, llvm::StringRef)': GlobalModuleIndex.cpp:(.text._ZN5clang17GlobalModuleIndex10writeIndexERNS_11FileManagerERKNS_18PCHContainerReaderEN4llvm9StringRefE+0x110): undefined reference to `llvm::LockFileManager::LockFileManager(llvm::StringRef)' /usr/bin/ld: GlobalModuleIndex.cpp:(.text._ZN5clang17GlobalModuleIndex10writeIndexERNS_11FileManagerERKNS_18PCHContainerReaderEN4llvm9StringRefE+0x129): undefined reference to `llvm::LockFileManager::tryLock()' /usr/bin/ld: GlobalModuleIndex.cpp:(.text._ZN5clang17GlobalModuleIndex10writeIndexERNS_11FileManagerERKNS_18PCHContainerReaderEN4llvm9StringRefE+0x65d): undefined reference to `llvm::LockFileManager::~LockFileManager()' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(ModuleCache.cpp.o): in function `std::_MakeUniq<llvm::LockFileManager>::__single_object std::make_unique<llvm::LockFileManager, llvm::StringRef&>(llvm::StringRef&)': ModuleCache.cpp:(.text._ZSt11make_uniqueIN4llvm15LockFileManagerEJRNS0_9StringRefEEENSt9_MakeUniqIT_E15__single_objectEDpOT0_[_ZSt11make_uniqueIN4llvm15LockFileManagerEJRNS0_9StringRefEEENSt9_MakeUniqIT_E15__single_objectEDpOT0_]+0x4b): undefined reference to `llvm::LockFileManager::LockFileManager(llvm::StringRef)' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(ModuleManager.cpp.o): in function `clang::serialization::ModuleManager::addModule(llvm::StringRef, clang::serialization::ModuleKind, clang::SourceLocation, clang::serialization::ModuleFile*, unsigned int, long, long, clang::ASTFileSignature, clang::ASTFileSignature (*)(llvm::StringRef), clang::serialization::ModuleFile*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)': ModuleManager.cpp:(.text._ZN5clang13serialization13ModuleManager9addModuleEN4llvm9StringRefENS0_10ModuleKindENS_14SourceLocationEPNS0_10ModuleFileEjllNS_16ASTFileSignatureEPFS8_S3_ERS7_RNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x7d8): undefined reference to `llvm::MemoryBufferRef::MemoryBufferRef(llvm::MemoryBuffer const&)' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(TemplateArgumentHasher.cpp.o): in function `(anonymous namespace)::TemplateArgumentHasher::AddTemplateArgument(clang::TemplateArgument)': TemplateArgumentHasher.cpp:(.text._ZN12_GLOBAL__N_122TemplateArgumentHasher19AddTemplateArgumentEN5clang16TemplateArgumentE+0xec): undefined reference to `llvm::APSInt::Profile(llvm::FoldingSetNodeID&) const' /usr/bin/ld: /usr/local/lib/libclangSerialization.a(TemplateArgumentHasher.cpp.o): in function `(anonymous namespace)::TemplateArgumentHasher::AddIdentifierInfo(clang::IdentifierInfo const*)': TemplateArgumentHasher.cpp:(.text._ZN12_GLOBAL__N_122TemplateArgumentHasher17AddIdentifierInfoEPKN5clang14IdentifierInfoE+0x61): undefined reference to `llvm::FoldingSetNodeID::AddString(llvm::StringRef)' clang++: error: linker command failed with exit code 1 (use -v to see invocation)
08-07
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值