如何将LLVM clang ++命令行转换为cmake配置? [英] how to convert LLVM clang++ command line to cmake config?

查看:229
本文介绍了如何将LLVM clang ++命令行转换为cmake配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过一些教程来构建LLVM语言.
在某种情况下,可以使用以下命令:

I'm building a LLVM language with some tutorials.
In a situation, there are command with:

clang++ -g main.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core orcjit native` -O3 -o toy 

此处是命令 llvm-config --cxxflags --ldflags --system-libs --libs核心orcjit本机,可以扩展为:

here a command llvm-config --cxxflags --ldflags --system-libs --libs core orcjit native which can expand to:

-I/usr/local/include  -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -g  -fno-exceptions -fno-rtti -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-L/usr/local/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names
-lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMGlobalISel -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMBitWriter -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMOrcJIT -lLLVMTransformUtils -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMProfileData -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMCore -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle
-lz -lcurses -lm -lxml2

使用clang ++可能效果很好,但是我想在这里用CMake进行编码.
这是我的CmakeLists.txt:

It could be works fine with clang++ but I want coding with a CMake here.
Here is my CmakeLists.txt:

cmake_minimum_required(VERSION 3.10)

set(CMAKE_CXX_STANDARD 17)


project(SimpleProject)

find_package(LLVM 7.0.0 REQUIRED CONFIG)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "CMAKE_ROOT ${CMAKE_ROOT}")
message(STATUS "CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}")
message(STATUS "LLVM_FOUND ${LLVM_FOUND}")
message(STATUS "LLVM_DIR ${LLVM_DIR}")
message(STATUS "LLVM_INCLUDE_DIRS: ${LLVM_INCLUDE_DIRS}")
message(STATUS "LLVM_DEFINITIONS: ${LLVM_DEFINITIONS}")

message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

# Set your project compile flags.
# E.g. if using the C++ header files
# you will need to enable C++11 support
# for your compiler.

include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})

# Now build our tools
add_executable(simple-tool KaleidoscopeJIT.h main.cpp)

# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(
        llvm_libs
        Analysis
        Core
        ExecutionEngine
        InstCombine
        Object
        OrcJIT
        RuntimeDyld
        ScalarOpts
        Support
        TransformUtils
        native
        irreader
        )

# Link against LLVM libraries
target_link_libraries(simple-tool ${llvm_libs})

使用生成的make时出现链接错误:

It has a link error when use generated make:

[ 50%] Linking CXX executable simple-tool
Undefined symbols for architecture x86_64:
  "typeinfo for llvm::ErrorInfoBase", referenced from:
      typeinfo for llvm::ErrorInfo<llvm::ErrorList, llvm::ErrorInfoBase> in main.cpp.o
  "typeinfo for llvm::orc::SymbolResolver", referenced from:
      typeinfo for llvm::orc::LegacyLookupFnResolver<llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)> in main.cpp.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[3]: *** [simple-tool] Error 1
make[2]: *** [CMakeFiles/simple-tool.dir/all] Error 2
make[1]: *** [CMakeFiles/simple-tool.dir/rule] Error 2
make: *** [simple-tool] Error 2

想知道如何将LLVM clang ++命令转换为CMake config. Github 中的完整CMake项目(对不起,github在今天10-22截止)

Wonder how to convert the LLVM clang++ command to CMake config it. Full CMake project in Github (sorry for github is down at today 10-22)

推荐答案

您做对了所有事情!

您看到的错误消息是因为LLVM是在没有RTTI的情况下编译的(运行时类型信息).

The error message you are seeing is because LLVM was compiled without RTTI (Run-time type information) enabled.

您应该明确指定编译器标志.LLVM公开了另一个有助于做出正确决策的属性:

You should specify compiler flags explicitly. LLVM exposes another property that helps to make the right decision:

if (NOT LLVM_ENABLE_RTTI)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif()

应该有帮助.

这篇关于如何将LLVM clang ++命令行转换为cmake配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆