用cmake叮当声。 target_include_directories“没有这样的文件或目录”

时间:2019-12-08 11:15:46

标签: c++ linux cmake clang

这是我的c ++项目。

├── CMakeLists.txt
├── include
│   └── ccli
        └──  # headers
├── src
│   ├── CMakeLists.txt
│   ├── exec_expr.cpp
│   ├── GlobalContext.cpp
│   ├── main.cpp
    └──  # others

/CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)                                                                  

project(main)                                                                                        

set(CMAKE_CXX_FLAGS "-Wall -std=c++17")                                                              

find_package(LLVM REQUIRED CONFIG)                                                                   
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION} in ${LLVM_INSTALL_PREFIX}")                       
message(STATUS "Using LLVMConfig.cmake in ${LLVM_DIR}")                                              

find_package(Clang REQUIRED CONFIG HINTS "{LLVM_INSTALL_PREFIX}/lib/cmake/clang")                    
message(STATUS "Found Clang in ${CLANG_INSTALL_PREFIX}")                                             
message(STATUS "Found Cland headers in ${CLANG_INCLUDE_DIRS}")                                       
message(STATUS "Found LLVM headers in ${LLVM_INCLUDE_DIRS}")                                         

add_subdirectory(src)                                                                                

add_executable(                                                                                      
    main                                                                                             
        src/main.cpp                                                                                 
)                                                                                                    

target_include_directories(main PRIVATE ${LLVM_INCLUDE_DIRS})                                        
target_include_directories(                                                                          
    main PUBLIC                                                                                      
        ${PROJECT_SOURCE_DIR}/include                                                                
)                                                                                                    

# Fixes clang linking error.                                                                         
target_compile_definitions(main PUBLIC -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING)                 
target_link_libraries(main ccli readline)  

/src/CMakeLists.txt:

cmake_minimum_required (VERSION 3.5)                             

add_library(                                                     
    ccli STATIC                                                  
        exec_expr.cpp                                            
        runToolOnCode.cpp                                        
        GlobalContext.cpp                                        
        Utility.cpp                                              
)                                                                

target_include_directories(ccli PRIVATE "${LLVM_INCLUDE_DIR}")   
target_include_directories(                                      
    ccli PRIVATE                                                 
        ${PROJECT_SOURCE_DIR}/include                            
)                                                                

target_link_libraries(                                           
    ccli PRIVATE                                                 
        clangTooling                                             
        clangFrontend                                            
        clangStaticAnalyzerFrontend                              
)                                                                

src / main.cpp的顶部:

#include "ccli/runToolOnCode.hpp"          
#include "ccli/GlobalContext.hpp"          
#include "ccli/exec_expr.hpp"              
#include "ccli/Utility.hpp"                

#include "clang/Frontend/FrontedActions.h"  //<- error occures here                                   

问题是add_library()中使用的所有文件都可以包含和使用clang头文件,但main.cpp不能。 另外我不明白为什么允许main.cpp包含 / include / ccli标头,据我了解,这意味着此代码可以正常运行:

target_include_directories(                                                                          
    main PUBLIC                                                                                      
        ${PROJECT_SOURCE_DIR}/include                                                                
)

但这不是吗?:

target_include_directories(main PRIVATE ${LLVM_INCLUDE_DIRS})

最后 cmake的输出。

-- Found LLVM 8.0.0 in /usr/lib/llvm-8
-- Using LLVMConfig.cmake in /usr/lib/llvm-8/cmake
-- Found Clang in /usr/lib/llvm-8
-- Found Cland headers in /usr/lib/llvm-8/include
-- Found LLVM headers in /usr/lib/llvm-8/include
-- Configuring done
-- Generating done
-- Build files have been written to: /c_repl/build

make的输出

/c_repl/src/main.cpp:6:10: fatal error: clang/Frontend/FrontedActions.h: No such file or directory
 #include "clang/Frontend/FrontedActions.h"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/main.dir/build.make:62: recipe for target 'CMakeFiles/main.dir/src/main.cpp.o' failed
make[2]: *** [CMakeFiles/main.dir/src/main.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

任何帮助或提示将不胜感激。谢谢。 PS在Linux上工作

Distributor ID: Ubuntu
Description:    Ubuntu 18.04.3 LTS
Release:        18.04
Codename:       bionic

PPS: 对不起,我的英语不好

1 个答案:

答案 0 :(得分:1)

似乎是拼写错误,请尝试:#include“ clang / Frontend / Fronte n dActions.h”

希望有帮助