[LLVMdev] How to figure out what #includes are needed?

John Criswell jtcriswel at gmail.com
Thu Dec 18 07:23:30 PST 2014


On 12/16/14, 10:15 PM, Rodney M. Bates wrote:
> This is partly an llvm question, and maybe partly C++.
>
> I am trying to make calls on code in the llvm infrastructure.(3.4.2)  
> I appear
> to be missing some include files, but don't know how to track them 
> down.  I get
> compile errors on existing llvm header files, like the following two 
> examples:

My recommendation is to look at the header files that define the classes 
and methods that you're using in LLVM.  The easiest way to do this is to 
use doxygen.

For example, if I'm using the Function class, I look at the doxygen page at:

http://llvm.org/doxygen/classllvm_1_1Function.html

That page tells me that the class definition is in Function.h.  I look 
for Function.h and (in LLVM 3.2) it exists in:

llvm/Function.h.

As you write more LLVM code, it becomes easier to find header files as 
you'll get more accustomed to the source code.

Regards,

John Criswell


> -------------------------------------------------------------------------------- 
>
>
> In file included from LLVMDIBuilder.cpp:16:
> In file included from 
> /usr/local/include/llvm/Support/CBindingWrapping.h:17:
> In file included from /usr/local/include/llvm/Support/Casting.h:18:
> In file included from /usr/local/include/llvm/Support/type_traits.h:22:
> In file included from 
> /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/utility:70:
> In file included from 
> /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_pair.h:59:
> /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/move.h:185:5: 
> error: conflicting types for 'swap'
>     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
>     ^
> /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/move.h:166:5: 
> note: previous definition is here
>     swap(_Tp& __a, _Tp& __b)
>
> -------------------------------------------------------------------------------- 
>
> In file included from LLVMDIBuilder.cpp:16:
> In file included from 
> /usr/local/include/llvm/Support/CBindingWrapping.h:17:
> In file included from /usr/local/include/llvm/Support/Casting.h:18:
> /usr/local/include/llvm/Support/type_traits.h:48:33: error: functions 
> that differ only in their return type cannot be overloaded
>     template<typename T> double is_class_helper(...);
>                                 ^
> /usr/local/include/llvm/Support/type_traits.h:47:31: note: previous 
> declaration is here
>     template<typename T> char is_class_helper(void(T::*)());
>                               ^
> -------------------------------------------------------------------------------- 
>
>
> Obviously, these files compile when included by the normal llvm build
> process.  I have gotten many previous similar errors to go away by 
> rote copying
> in of all the #include lines in the full code listing in the new 
> Kaleidoscope
> Chapter 8 example and all those in core.cpp, but many more remain.
>
> I would have expected missing declarations from missing include files to
> give error messages like "undeclared identifier", but the effect seems to
> be to make types that look different be the same, and vice versa (but
> apparently not different enough to be legal overloads?).
>
> My command line is:
>
> clang++ -g LLVMDIBuilder.cpp `llvm-config --cxxflags --libs all`
>
> $lvm-config --cxxflags --libs all
> -I/usr/local/include  -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
> -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -g 
> -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fPIC 
> -Woverloaded-virtual -Wcast-qual
> -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 -lLLVMAArch64Disassem!
> bler -lLLV
> MAArch64CodeGen -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
>
> How do I figure out what to include to fix these?
>
>
>


-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell




More information about the llvm-dev mailing list