LLVM-clang之win10安装

系统win10

软件LLVM

,一种C/Cpuls的编译器,与GCC异曲同工
说明:网上大部分说明都是LLVM/clang需要与VS2015+一起使用,但是最讨厌就是VS,MATLAB这种大软件,仗着功能多,随便写一个小脚本都要运行一下大软件,为此我所有的程序都是使用命令行编译,此次也不例外,为此必须在命令行中使用clang编译程序

目标:

在win10上安装LLVM,使用clang编译程序

问题:安装完成后,命令行运行clang test.c找不到头文件

1 下载安装LLVM,这个百度就好了
2 下载mingw64压缩包(因为我的是64位系统,而且mingw64与mingw有很大的不同)
3 将mingw64解压到LLVM环境中
在这里插入图片描述
mingw64如果放到其他目录中,运行clang test.c出现no find header

当然放进去了也出现找不到头文件的问题,未解决

查看了大部分百度问题,
https://stackoverflow.com/questions/39871656/how-to-use-clang-with-mingw-w64-headers-on-windows
这篇还有点意思
于是就运行成功了

首先写一个helloword
文件名字test.c

#include <stdio.h>

int main(int argc, char *argv[]) {
    printf("Hello World!");    

    return 0;
}

使用clang test.c
在这里插入图片描述
使用命令

clang test.c -o hello.exe --verbose -target x86_64-pc-windows-gnu

编译成功
运行程序
./hello.exe
别问我后面那个目标是啥意思,百度了也没明白,但是确实是可以编译成功了

python使用clang

win10
python3.6

首先安装clang

pip install clang

声明

import sys

import clang.cindex
import os
import json
from clang.cindex import Index
from clang.cindex import Config

配置

python
# clang.cindex需要用到libclang.so共享库,所以先配置共享库
libclangPath = r'D:/Program Files/LLVM/bin/libclang.dll'
#这个路径需要自己先在笔记本上安装	
if Config.loaded == True:
	print("Config.loaded == True:")
#     pass
else:
    Config.set_library_file(libclangPath)
index_ = Index.create()
发布了97 篇原创文章 · 获赞 18 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_32460819/article/details/102621959