如何在 cpp 中安装头文件
How to install header files in cpp
这是一个类似于如何安装clang头文件的问题? 但我无法发表评论或提问,因为它需要50+声誉。请原谅重复。
我已经在我的MacOS上安装了clang(在/usr/bin/clang中),我认为默认情况下安装在Mac上,但是,当我尝试在cpp文件中包含clang头文件时,它说找不到它们
/Users/jzhu/go/src/github.com/codelingo/sandbox/test/cpp/main.cpp:7:10: fatal error: 'clang/AST/ASTConsumer.h' file not found #include <clang/AST/ASTConsumer.h>
^
1 error generated
问题:当 clang 已经在 MacOS 系统上安装和构建时,是否有必要(并且可能,如果是,如何)安装头文件(或者 clang 本身是否需要在安装所有所需的开发工具包及其头文件的同时重新安装)?
#include <clang/AST/ASTConsumer.h>
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Tooling/Tooling.h"
我已经使用了@numurat在如何安装clang头文件中建议的"<>",但它并不能解决问题。
clang 包可以在/Users/username/ccompiler/llvm/tools/clang/include/clang 中找到。
$ pwd
/Users/username/ccompiler/llvm/tools/clang/include/clang
$ ls
ARCMigrate Basic Driver FrontendTool Rewrite Tooling
AST CMakeLists.txt Edit Index Sema module.modulemap
ASTMatchers CodeGen Format Lex Serialization
Analysis Config Frontend Parse StaticAnalyzer
我也尝试制作这个 clang 文件夹的副本并包含在我的项目中,但是当 clang/AST/RecursiveASTVisitor.h 有一行 #include"clang/AST/Attr.h"时,它最终会出现类似的错误
我试图遵循这个例子 http://clang.llvm.org/docs/RAVFrontendAction.html
在我的项目文件夹中,我有一个 main.cpp与上面链接中的教程内容相同,还有一个 CMakeList.txt它是由 CLION 自动创建的
cmake_minimum_required(VERSION 3.8)
project(cpp)
set(CMAKE_CXX_STANDARD 17)
set(SOURCE_FILES main.cpp)
add_executable(cpp ${SOURCE_FILES})
include_directories(${LLVM_INCLUDE_DIRS})
PS:我按照 https://clang.llvm.org/get_started.html 安装了叮当声。
$ clang --version
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
您似乎在某个时候自己安装了编译器,并且无法找到库存头文件。 使用-I
标志告诉它在哪里可以找到它们:
-I/Users/username/ccompiler/llvm/tools/clang/include
https://clang.llvm.org/docs/CommandGuide/clang.html
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 我可以在 Arduino 的库文件夹之外安装库吗?
- 介子复制/安装头文件到输出目录并保持文件夹结构
- 如何更改使用 CPack 安装的可执行文件的名称?
- 我的 SDL2 程序需要哪些二进制文件,以便它在另一台未安装 SDL2 的计算机中工作
- 我应该安装 .cmake 文件来共享/cmake 还是 lib/cmake?
- OpenCV 安装错误:没有这样的文件或目录"pyopencv_generated_include.h"
- 如何在 cpp 中安装头文件
- 在 ubuntu 上安装 c++ 标准库文件
- Pybind11, cmake: 如何安装文件?
- 从 docker 映像构建中省略安装文件
- 在没有root权限的情况下安装NTL,并在生成文件中修改其构建路径
- 安装 mply 库时出错.致命错误:gsl/gsl_sf.h:没有这样的文件或目录
- 执行populate_sdk时如何使用yocto在本机系统根中安装文件?
- 应使用 CMake install 命令将可执行资源文件安装到何处?
- 代码块,添加了环境变量路径,但在安装文件夹之外出现 g++ 错误
- 有条件地提示安装文件夹对话框
- 使用qmake安装文件:如何获取可执行文件
- 在c++中使用Octave库(dll等)而不安装Octave(只是复制安装文件夹)
- 如何为c++程序创建一个安装文件