做者:史宁宁(snsn1984)html
llvm-config做为LLVM的一个工具,是很是有用的,官方文档(http://llvm.org/docs/CommandGuide/llvm-config.html)关于它的介绍以下:git
llvm-config makes it easier to build applications that use LLVM. It can print the compiler flags, linker flags and object libraries needed to link against LLVM.
github
这里介绍的很是清楚,llvm-config使得使用LLVM去构建本身的应用更加的简单。之因此能够更加简单,是由于它能够打印出编译器flags、链接器flags以及须要链接的LLVM库。简单点的说,就是llvm-config能够获取系统中LLVM的全部相关信息,这些信息能够方便的用于构建基于LLVM的项目。只是这么说的话,看起来并不明显,下面我就给出一个实例来。shell
LLVM_CONFIG = llvm-config LLVM_CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags) LLVM_LDFLAGS := $(shell $(LLVM_CONFIG) --ldflags) LLVM_LIBS = $(shell $(LLVM_CONFIG) --libs bitwriter core support) llvm_model_src = ModuleMaker.cpp test_model: g++ $(llvm_model_src) $(LLVM_CXXFLAGS) $(LLVM_LIBS) $(LLVM_LDFLAGS) -lpthread -ldl -o ModuleMaker这是一个Makefile。它是一个例子ModuleMaker的编译文件。这个ModuleMaker例子自己是LLVM源码中llvm/examples/ModuleMaker/目录下的一个例子,它演示的若是凭空构建一个LLVM IR的Module。我这里写了这个Makefile之后,能够在已经安装LLVM的系统(Linux)上单独的编译这个例子,而不须要依赖LLVM的源码,也再也不须要在LLVM源码中编译这个例子。完整的包含Makefile的ModuleMaker例子的代码: https://github.com/shining1984/llvm-examples
同时,llvm-config还能够以`llvm-config --libs`这样的形式在Makefile中使用,或者在命令行中使用,这样的使用形式是获取这个命令在shell执行后所输出的信息。这里须要指出的是“`”这个符号,并非“‘”。这二者是有区别的,前者是和“~”同键的符号,后者是和“"” 同键的符号。这一点是必定要区别的,否者系统没法识别。例如:app
g++ `llvm-config --cxxflags` -o HowToUseJIT.o -c HowToUseJIT.cpp g++ `llvm-config --ldflags` -o HowToUseJIT HowToUseJIT.o \ `llvm-config --libs engine bcreader scalaropts`
llvm-config的主要参数以下:ide
–version工具
Print the version number of LLVM.
-helpui
Print a summary of llvm-config arguments.
–prefixthis
Print the installation prefix for LLVM.
–src-rootspa
Print the source root from which LLVM was built.
–obj-root
Print the object root used to build LLVM.
–bindir
Print the installation directory for LLVM binaries.
–includedir
Print the installation directory for LLVM headers.
–libdir
Print the installation directory for LLVM libraries.
–cxxflags
Print the C++ compiler flags needed to use LLVM headers.
–ldflags
Print the flags needed to link against LLVM libraries.
–libs
Print all the libraries needed to link against the specified LLVM components, including any dependencies.
–libnames
Similar to –libs, but prints the bare filenames of the libraries without -l or pathnames. Useful for linking against a not-yet-installed copy of LLVM.
–libfiles
Similar to –libs, but print the full path to each library file. This is useful when creating makefile dependencies, to ensure that a tool is relinked if any library it uses changes.
–components
Print all valid component names.
–targets-built
Print the component names for all targets supported by this copy of LLVM.
–build-mode
Print the build mode used when LLVM was built (e.g. Debug or Release)参考文档: http://llvm.org/docs/CommandGuide/llvm-config.html