llvm和clang编译完成后,编译Hello.cpp失败

编译github下载最新的llvm后,clang编译测试文件报错,具体步骤和问题描述如下:
一、编译llvm

  1. git clone https://github.com/llvm/llvm-project.git
  2. cd llvm-project
  3. mkdir my-ninja-build
  4. cd my-ninja-build
  5. cmake -G Ninja -DLLVM_ENABLE_PROJECTS=“clang” -DCMAKE_BUILD_TYPE= Debug -DLLVM_ENABLE_ASSERTIONS=ON …/llvm
  6. ninja && ninja install
  7. ~/.bash_profile添加环境:
    export LLVM_HOME=/Users/falafellsl/iosreverse/llvm-project/my-ninja-build
    export PATH=$LLVM_HOME/bin:${PATH}
  8. 编译完成后 clang -v:

clang version 15.0.0 (https://github.com/llvm/llvm-project.git 890beda4e1794f8b5cf13d3fcd158c37b65c684e)

Target: x86_64-apple-darwin21.2.0

Thread model: posix

InstalledDir: /xxx/llvm-project/my-ninja-build/bin

二、编译 /llvm-project/llvm/lib/Transforms/Hello/Hello.cpp文件

  1. clang Hello.cpp
  2. 报错
> /usr/local/include/llvm/Support/Compiler.h:21:10:** **fatal error:** **'new' file not found
> #include <new>

看报错信息说是对应的搜索路径下没有new文件。

检查文件发现 在my-ninja-build 目录下两处有new文件

my-ninja-build/lib/clang/15.0.0/include/openmp_wrappers/new
my-ninja-build/lib/clang/15.0.0/include/cuda_wrappers/new

这种情况是需要修改clang的搜索路径吗,如果是要修改,那上面也是有两处new文件,请大佬指点下

李在肝肾魔

你先markdown编辑一下吧 看的头疼

我们先说清楚 新版的LLVM需要单独启用compiler-rt libcxx 和libcxxabi

好的,张总,改了

应该还是需要指定SDK

指定sdk的话 编译带 *#include<stdio.h>` 的.c文件上可以的,但是编译包含了llvm目录的cpp文件反而会报错找不到头文件

xcrun -sdk macosx12.1 clang Hello.cpp

Hello.cpp:14:10: fatal error: ‘llvm/ADT/Statistic.h’ file not found

xcrun -sdk macosx12.1 clang -v Hello.cpp

xcrun -sdk macosx12.1 /Users/falafellsl/iosreverse/llvm-project/my-ninja-build/bin/clang -v Hello.cpp
clang version 15.0.0 (https://github.com/llvm/llvm-project.git 890beda4e1794f8b5cf13d3fcd158c37b65c684e)

Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/Library/Frameworks"

#include “…” search starts here:

#include <…> search starts here:

/Users/falafellsl/iosreverse/llvm-project/my-ninja-build/bin/…/include/c++/v1

/Users/falafellsl/iosreverse/llvm-project/my-ninja-build/lib/clang/15.0.0/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks (framework directory)

End of search list.

Hello.cpp:14:10: fatal error: ‘llvm/ADT/Statistic.h’ file not found

额…重新看了下需求

二、编译 /llvm-project/llvm/lib/Transforms/Hello/Hello.cpp文件

clang Hello.cpp

Hello.cpp 这个文件不是你这样编译的啊,看 /llvm-project/llvm/lib/Transforms/Hello/ 和 /llvm-project/llvm/lib/Transforms/ 目录下面的 CMakeLists.txt。你编译整个工程的时候已经把这个 hello 库编译过了。

牛逼 我也没看清楚

LLVM有自己的编译系统的. 叫llvm-config