g ++编译CLang独立应用程序,但CMake不是

时间:2013-12-11 06:47:24

标签: c++ cmake clang

我正在尝试使用我的Ubuntu计算机上的CLang编译我的cmake独立应用程序,但还没有运气。这是我的CMakeLists.txt: -

cmake_minimum_required(VERSION 2.8)

project(Demo)

execute_process(
    COMMAND llvm-config --cxxflags
    OUTPUT_VARIABLE LLVM_CXX_FLAGS
)

execute_process(
    COMMAND llvm-config --ldflags
    OUTPUT_VARIABLE LLVM_LD_FLAGS
)

execute_process(
    COMMAND llvm-config --libs
    OUTPUT_VARIABLE LLVM_LIB_FLAGS
)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS}")
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${LLVM_LD_FLAGS}")

add_executable(clangTestApp TestCLang.cpp)

target_link_libraries(clangTestApp ${LLVM_LIB_FLAGS})

这是从项目目录中的build目录运行cmake ..时的输出: -

-- Configuring done
CMake Error at CMakeLists.txt:23 (add_executable):
  Target "clangTestApp" links to item "-lLLVMAsmParser -lLLVMInstrumentation
  -lLLVMLinker -lLLVMArchive -lLLVMBitReader -lLLVMDebugInfo -lLLVMJIT
  -lLLVMipo -lLLVMVectorize -lLLVMBitWriter -lLLVMTableGen
  -lLLVMHexagonCodeGen -lLLVMHexagonDesc -lLLVMHexagonInfo
  -lLLVMHexagonAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo
  -lLLVMNVPTXAsmPrinter -lLLVMMBlazeAsmParser -lLLVMMBlazeDisassembler
  -lLLVMMBlazeCodeGen -lLLVMMBlazeDesc -lLLVMMBlazeInfo
  -lLLVMMBlazeAsmPrinter -lLLVMCppBackendCodeGen -lLLVMCppBackendInfo
  -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info
  -lLLVMMSP430AsmPrinter -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo
  -lLLVMCellSPUCodeGen -lLLVMCellSPUDesc -lLLVMCellSPUInfo
  -lLLVMMipsDisassembler -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc
  -lLLVMMipsInfo -lLLVMMipsAsmPrinter -lLLVMARMDisassembler
  -lLLVMARMAsmParser -lLLVMARMCodeGen -lLLVMARMDesc -lLLVMARMInfo
  -lLLVMARMAsmPrinter -lLLVMPowerPCCodeGen -lLLVMPowerPCDesc
  -lLLVMPowerPCInfo -lLLVMPowerPCAsmPrinter -lLLVMSparcCodeGen
  -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMX86Disassembler -lLLVMX86AsmParser
  -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter
  -lLLVMX86Utils -lLLVMR600CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter
  -lLLVMR600Desc -lLLVMR600Info -lLLVMR600AsmPrinter -lLLVMMCDisassembler
  -lLLVMMCParser -lLLVMInterpreter -lLLVMCodeGen -lLLVMScalarOpts
  -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMMCJIT
  -lLLVMRuntimeDyld -lLLVMExecutionEngine -lLLVMTarget -lLLVMMC -lLLVMObject
  -lLLVMCore -lLLVMSupport

  " which has leading or trailing whitespace.  This is now an error according
  to policy CMP0004.


-- Generating done
-- Build files have been written to: /home/prakhar/Desktop/CLang/Demo/build

现在,当我在内部构建目录中运行make时,它给了我: -

Scanning dependencies of target clangTestApp
[100%] Building CXX object CMakeFiles/clangTestApp.dir/TestCLang.o
Linking CXX executable clangTestApp
c++: fatal error: no input files
compilation terminated.
make[2]: *** [clangTestApp] Error 4
make[1]: *** [CMakeFiles/clangTestApp.dir/all] Error 2
make: *** [all] Error 2

我不知道为什么c ++会说no input files。如果有人知道发生了什么?

由于

1 个答案:

答案 0 :(得分:0)

我建议你使用FindClang.cmake,你可以找到它,例如在这里:https://github.com/woboq/woboq_codebrowser/blob/master/cmake/modules/FindClang.cmake(或者只是google for FindClang.cmake)。您还需要相应的FindLLVM.cmake(https://github.com/woboq/woboq_codebrowser/blob/master/cmake/modules/FindLLVM.cmake