这项工作的目标是使用非c ++ 11编译器中的一些c ++ 11特性
完成以下步骤,
生成llvm位代码,
clang++ -emit-llvm -c test.cc -o test.o
将llvm bitcode转换为c ++代码,
llc-3.4 test.o -o test.cpp -march=cpp
使用GNU g ++编译llvm生成的c ++代码时出现以下错误
arunprasadr @ geekvm:〜/ works / myex / llvm $ g ++ test.cpp test.cpp:3:23:致命错误:llvm / Pass.h:没有这样的文件或目录 编译终止。
我甚至尝试添加llvm-dev包含路径,但仍然失败,
arunprasadr@geekvm:~/works/myex/llvm$ g++ test.cpp -I/usr/include/llvm-3.4 -I /usr/include/llvm-c-3.4
In file included from /usr/include/llvm-3.4/llvm/Support/type_traits.h:20:0,
from /usr/include/llvm-3.4/llvm/ADT/StringRef.h:13,
from /usr/include/llvm-3.4/llvm/PassRegistry.h:20,
from /usr/include/llvm-3.4/llvm/PassSupport.h:26,
from /usr/include/llvm-3.4/llvm/Pass.h:366,
from test.cpp:3:
/usr/include/llvm-3.4/llvm/Support/DataTypes.h:48:3: error: #error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
/usr/include/llvm-3.4/llvm/Support/DataTypes.h:52:3: error: #error "Must #define __STDC_CONSTANT_MACROS before " "#including Support/DataTypes.h"
In file included from /usr/include/llvm-3.4/llvm/ADT/SmallVector.h:19:0,
from /usr/include/llvm-3.4/llvm/PassAnalysisSupport.h:22,
from /usr/include/llvm-3.4/llvm/Pass.h:367,
from test.cpp:3:
/usr/include/llvm-3.4/llvm/Support/MathExtras.h: In function ‘bool llvm::isInt(int64_t)’:
/usr/include/llvm-3.4/llvm/Support/MathExtras.h:264:33: error: there are no arguments to ‘INT64_C’ that depend on a template parameter, so a declaration of ‘INT64_C’ must be available [-fpermissive]
/usr/include/llvm-3.4/llvm/Support/MathExtras.h:264:33: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
/usr/include/llvm-3.4/llvm/Support/MathExtras.h:264:65: error: there are no arguments to ‘INT64_C’ that depend on a template parameter, so a declaration of ‘INT64_C’ must be available [-fpermissive]
/usr/include/llvm-3.4/llvm/Support/MathExtras.h: In function ‘bool llvm::isUInt(uint64_t)’:
/usr/include/llvm-3.4/llvm/Support/MathExtras.h:290:36: error: there are no arguments to ‘UINT64_C’ that depend on a template parameter, so a declaration of ‘UINT64_C’ must be available [-fpermissive]
/usr/include/llvm-3.4/llvm/Support/MathExtras.h: In function ‘bool llvm::isIntN(unsigned int, int64_t)’:
/usr/include/llvm-3.4/llvm/Support/MathExtras.h:322:33: error: ‘INT64_C’ was not declared in this scope
答案 0 :(得分:2)
您需要针对llvm-config
提供的标记进行编译。如下所示:
#include <iostream>
int main() {
std::cout << "hello" << std::endl;
}
[3:21pm][wlynch@apple /tmp] /opt/llvm/3.4/bin/clang++ -emit-llvm -c input.cc -o input.o
[3:22pm][wlynch@apple /tmp] /opt/llvm/3.4/bin/llc input.o -o llvm.cc -march=cpp
[3:22pm][wlynch@apple /tmp] /opt/llvm/3.4/bin/clang++ -gcc-toolchain /opt/gcc/4.8.2/ llvm.cc `/opt/llvm/3.4/bin/llvm-config --cxxflags --ldflags --libs`
-I/opt/llvm/3.4/include -DNDEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -O3 -fomit-frame-pointer
-std=c++11 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fPIC
-Woverloaded-virtual -Wcast-qual -L/opt/llvm/3.4/lib -lz -lpthread -ltinfo -lrt
-ldl -lm -lLLVMInstrumentation -lLLVMIRReader -lLLVMAsmParser -lLLVMDebugInfo
-lLLVMOption -lLLVMLTO -lLLVMLinker -lLLVMipo -lLLVMVectorize -lLLVMBitWriter
-lLLVMBitReader -lLLVMTableGen -lLLVMR600CodeGen -lLLVMR600Desc -lLLVMR600Info
-lLLVMR600AsmPrinter -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen
-lLLVMSystemZAsmParser -lLLVMSystemZDesc -lLLVMSystemZInfo
-lLLVMSystemZAsmPrinter -lLLVMHexagonCodeGen -lLLVMHexagonAsmPrinter
-lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc
-lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMCppBackendCodeGen
-lLLVMCppBackendInfo -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info
-lLLVMMSP430AsmPrinter -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen
-lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMXCoreAsmPrinter -lLLVMMipsDisassembler
-lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo
-lLLVMMipsAsmPrinter -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser
-lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMAArch64Disassembler
-lLLVMAArch64CodeGen -lLLVMAArch64AsmParser -lLLVMAArch64Desc -lLLVMAArch64Info
-lLLVMAArch64AsmPrinter -lLLVMAArch64Utils -lLLVMPowerPCCodeGen
-lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo
-lLLVMPowerPCAsmPrinter -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcInfo
-lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG
-lLLVMAsmPrinter -lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils
-lLLVMMCDisassembler -lLLVMMCParser -lLLVMInterpreter -lLLVMMCJIT -lLLVMJIT
-lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMScalarOpts -lLLVMInstCombine
-lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMRuntimeDyld
-lLLVMExecutionEngine -lLLVMTarget -lLLVMMC -lLLVMObject -lLLVMCore
-lLLVMSupport