我一直试图编写一个LLVM通行证混合使用this和this部分文档。
我假设由于Mac附带了Clang和LLVM,我应该可以使用他们的安装来创建插件。所以我制作了如下目录布局:
optimizations
CMakeLists.txt (--> outer)
Hello
CMakeLists.txt (--> inner)
Hello.cpp
"outer"
的内容是:
find_package(LLVM REQUIRED CONFIG)
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(AddLLVM)
add_definitions(${LLVM_DEFINITONS})
include_directories(${LLVM_INCLUDE_DIRS})
add_subdirectory(Hello)
"inner"
的内容是:
add_llvm_loadable_module(LLVMHello
Hello.cpp
)
在Hello.cpp中我得到了另一组说明中的内容:
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
namespace {
struct Hello : public FunctionPass {
static char ID;
Hello() : FunctionPass(ID) {}
bool runOnFunction(Function &F) override {
errs() << "Hello: ";
errs().write_escaped(F.getName()) << '\n';
return false;
}
};
}
char Hello::ID = 0;
static RegisterPass<Hello> X("hello", "Hello World Pass", false, false);
然后我转到优化目录并运行cmake CMakeLists.txt
。这在每个目录中创建了一个Makefile
以及一堆其他与cmake相关的文件。这工作正常但后来我尝试运行make
并且首先I got errors similar to here。为了解决这个问题,我在Hello.cpp
的顶部添加了:
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
但现在我收到了这些错误:
/usr/local/include/llvm/Support/AlignOf.h:53:10: error: unknown type name 'constexpr'
static constexpr unsigned Alignment =
^
/usr/local/include/llvm/Support/AlignOf.h:53:20: error: expected member name or ';' after declaration specifiers
static constexpr unsigned Alignment =
~~~~~~~~~~~~~~~~ ^
/usr/local/include/llvm/Support/AlignOf.h:59:42: error: use of undeclared identifier 'Alignment'
enum { Alignment_GreaterEqual_2Bytes = Alignment >= 2 ? 1 : 0 };
^
/usr/local/include/llvm/Support/AlignOf.h:60:42: error: use of undeclared identifier 'Alignment'
enum { Alignment_GreaterEqual_4Bytes = Alignment >= 4 ? 1 : 0 };
^
/usr/local/include/llvm/Support/AlignOf.h:61:42: error: use of undeclared identifier 'Alignment'
enum { Alignment_GreaterEqual_8Bytes = Alignment >= 8 ? 1 : 0 };
^
/usr/local/include/llvm/Support/AlignOf.h:62:43: error: use of undeclared identifier 'Alignment'
enum { Alignment_GreaterEqual_16Bytes = Alignment >= 16 ? 1 : 0 };
^
/usr/local/include/llvm/Support/AlignOf.h:64:39: error: use of undeclared identifier 'Alignment'
enum { Alignment_LessEqual_2Bytes = Alignment <= 2 ? 1 : 0 };
^
/usr/local/include/llvm/Support/AlignOf.h:65:39: error: use of undeclared identifier 'Alignment'
enum { Alignment_LessEqual_4Bytes = Alignment <= 4 ? 1 : 0 };
^
/usr/local/include/llvm/Support/AlignOf.h:66:39: error: use of undeclared identifier 'Alignment'
enum { Alignment_LessEqual_8Bytes = Alignment <= 8 ? 1 : 0 };
^
/usr/local/include/llvm/Support/AlignOf.h:67:40: error: use of undeclared identifier 'Alignment'
enum { Alignment_LessEqual_16Bytes = Alignment <= 16 ? 1 : 0 };
^
/usr/local/include/llvm/Support/AlignOf.h:71:23: error: unknown type name 'constexpr'
template <typename T> constexpr unsigned AlignOf<T>::Alignment;
^
/usr/local/include/llvm/Support/AlignOf.h:71:33: error: expected unqualified-id
template <typename T> constexpr unsigned AlignOf<T>::Alignment;
我不确定如何处理这些错误。任何帮助将不胜感激。
将set(CMAKE_CXX_STANDARD 11)
添加到我的CMakeLists.txt
会产生:
Hello[ 50%] Linking CXX shared module LLVMHello.dylib
Undefined symbols for architecture x86_64:
"llvm::FunctionPass::assignPassManager(llvm::PMStack&, llvm::PassManagerType)", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"llvm::FunctionPass::createPrinterPass(llvm::raw_ostream&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"llvm::Pass::getAnalysisUsage(llvm::AnalysisUsage&) const", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"llvm::Pass::getAdjustedAnalysisPointer(void const*)", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"llvm::Pass::getPassName() const", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"llvm::Pass::verifyAnalysis() const", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"llvm::Value::getName() const", referenced from:
(anonymous namespace)::Hello::runOnFunction(llvm::Function&) in Hello.o
"llvm::errs()", referenced from:
(anonymous namespace)::Hello::runOnFunction(llvm::Function&) in Hello.o
"llvm::raw_ostream::write(char const*, unsigned long)", referenced from:
llvm::raw_ostream::operator<<(llvm::StringRef) in Hello.o
"llvm::Pass::dumpPassStructure(unsigned int)", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"llvm::Pass::getAsPMDataManager()", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"llvm::Pass::~Pass()", referenced from:
llvm::FunctionPass::~FunctionPass() in Hello.o
"llvm::Pass::print(llvm::raw_ostream&, llvm::Module const*) const", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"llvm::raw_ostream::write(unsigned char)", referenced from:
llvm::raw_ostream::operator<<(char) in Hello.o
"llvm::FunctionPass::getPotentialPassManagerType() const", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"vtable for llvm::FunctionPass", referenced from:
llvm::FunctionPass::FunctionPass(char&) in Hello.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"llvm::Pass::preparePassManager(llvm::PMStack&)", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"llvm::Pass::getAsImmutablePass()", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"vtable for llvm::Pass", referenced from:
llvm::Pass::Pass(llvm::PassKind, char&) in Hello.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"llvm::raw_ostream::write_escaped(llvm::StringRef, bool)", referenced from:
(anonymous namespace)::Hello::runOnFunction(llvm::Function&) in Hello.o
"llvm::Pass::releaseMemory()", referenced from:
vtable for (anonymous namespace)::Hello in Hello.o
"llvm::PassRegistry::getPassRegistry()", referenced from:
llvm::RegisterPass<(anonymous namespace)::Hello>::RegisterPass(char const*, char const*, bool, bool) in Hello.o
"llvm::PassRegistry::registerPass(llvm::PassInfo const&, bool)", referenced from:
llvm::RegisterPass<(anonymous namespace)::Hello>::RegisterPass(char const*, char const*, bool, bool) in Hello.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Hello/LLVMHello.dylib] Error 1
make[1]: *** [Hello/CMakeFiles/LLVMHello.dir/all] Error 2
make: *** [all] Error 2
答案 0 :(得分:1)
编译器抱怨constexpr
这是一个C ++ 11特性。通过将-std=c++11
开关传递给gcc(或Clang,两个编译器的相同开关)确保启用C ++ 11。这将解决您所看到的所有错误。由于您使用的是makefile,因此您应该将此切换添加到CXXFLAGS
变量中,如here所示。
答案 1 :(得分:-2)
更新:忽略这个答案。关于C ++ 11的答案是正确的。
无法找到Ole::Storage::FormatError: OLE2 signature is invalid
的定义。这可以是constexpr
中的typedef,但更可能是typedef something constexpr
它应该在某个地方的.h文件中定义(或在makefile中定义为#define constexpr const
)。
注意:在您引用的页面上,他们建议在makefile中添加-D&#39。另请参阅使用-Dconstexpr=const
的第二个答案。只需输入并查看输出内容即可。
但是,你必须进一步排除故障......
首先,通过以下内容找到具有定义的文件:
egrep -r '#define.*constexpr' .您可能会得到一些额外内容。筛选它们并找到具有该定义的文件。然后,在它周围寻找一个
llvm-config --cppflags
包装器。 BLAH没有被正确定义。
如果BLAH原来是你提到的__STDC_ *之一,你可能需要间接定义它,因为有时某些.h文件将取消这些并取消它们,基于更多&#34;全局&#34;符号(例如STDC_ *或_STDC_SOURCE)
例如,使用GNU,要获得子功能,您不能直接定义它们,使用_GNU_SOURCE打开一大堆