分享

在windows上设置llvm+mingw环境变量

 quasiceo 2018-01-16

 发表于 2017-01-22 19:45                       

从网上下载了一个压缩文件-CODEBLOCKS20161122.rar-,解压缩后目录结构如下:

D:\CODEBLOCKS20161122
└─LLVM
    ├─bin
    ├─etc
    ├─i686-w64-mingw32
    │  ├─bin
    │  ├─include
    │  │  ├─c++
    │  │  │  ├─backward
    │  │  │  ├─bits
    │  │  │  ├─debug
    │  │  │  ├─decimal
    │  │  │  ├─experimental
    │  │  │  ├─ext
    │  │  │  │  └─pb_ds
    │  │  │  │      └─detail
    │  │  │  │          ├─binary_heap_
    │  │  │  │          ├─binomial_hea
    │  │  │  │          ├─binomial_hea
    │  │  │  │          ├─bin_search_t
    │  │  │  │          ├─branch_polic
    │  │  │  │          ├─cc_hash_tabl
    │  │  │  │          ├─eq_fn
    │  │  │  │          ├─gp_hash_tabl
    │  │  │  │          ├─hash_fn
    │  │  │  │          ├─left_child_n
    │  │  │  │          ├─list_update_
    │  │  │  │          ├─list_update_
    │  │  │  │          ├─ov_tree_map_
    │  │  │  │          ├─pairing_heap
    │  │  │  │          ├─pat_trie_
    │  │  │  │          ├─rb_tree_map_
    │  │  │  │          ├─rc_binomial_
    │  │  │  │          ├─resize_polic
    │  │  │  │          ├─splay_tree_
    │  │  │  │          ├─thin_heap_
    │  │  │  │          ├─tree_policy
    │  │  │  │          ├─trie_policy
    │  │  │  │          └─unordered_it
    │  │  │  ├─i686-w64-mingw32
    │  │  │  │  ├─bits
    │  │  │  │  └─ext
    │  │  │  ├─parallel
    │  │  │  ├─profile
    │  │  │  │  └─impl
    │  │  │  ├─tr1
    │  │  │  └─tr2
    │  │  ├─ddk
    │  │  ├─gdiplus
    │  │  ├─GL
    │  │  ├─psdk_inc
    │  │  ├─sdks
    │  │  ├─sec_api
    │  │  │  └─sys
    │  │  └─sys
    │  └─lib
    │      └─ldscripts
    ├─include
    │  ├─clang-c
    │  ├─gdb
    │  └─llvm-c
    ├─lib
    │  ├─clang
    │  │  └─3.6.0
    │  │      ├─include
    │  │      │  └─sanitizer
    │  │      └─lib
    │  │          └─windows
    │  └─gcc
    │      └─i686-w64-mingw32
    │          ├─4.9.1
    │          │  ├─adainclude
    │          │  ├─adalib
    │          │  ├─finclude
    │          │  ├─include
    │          │  │  ├─objc
    │          │  │  └─ssp
    │          │  ├─include-fixed
    │          │  └─install-tools
    │          │      └─include
    │          └─lib
    ├─libexec
    │  └─gcc
    │      └─i686-w64-mingw32
    │          └─4.9.1
    │              └─install-tools
    ├─msbuild-bin
    ├─share
    │  └─clang
    └─tools
        └─msbuild
            ├─Win32
            └─x64

编辑一个批处理文件如下:

set MINGW_HOME=D:\CodeBlocks20161122\LLVM
set MINGW_VERSION=4.9.1
set "PATH=%MINGW_HOME%\bin;%PATH%"
set SS=i686-w64-mingw32
set "C_INCLUDE_PATH=%MINGW_HOME%\include;%MINGW_HOME%\%SS%\include"
set "CPLUS_INCLUDE_PATH=%C_INCLUDE_PATH%;%MINGW_HOME%\%SS%\include;%MINGW_HOME%\%SS%\include\c++;%MINGW_HOME%\%SS%\include\c++\%SS%;%MINGW_HOME%\%SS%\include\c++\backward"
set  LLVM_HOME=D:\CodeBlocks20161122\LLVM
set "PATH=%LLVM_HOME%\bin;%PATH%"

执行之后,就可以既用g++编译,又用clang++编译了。

D:\>g++ --version
g++ (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 4.9.1
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

D:\>g++ p586_4a.cpp -o acpp1.exe
p586_4a.cpp: In function 'int f(int, int)':
p586_4a.cpp:59:17: warning: name lookup of 'a' changed
             fct(a,i);
                 ^
p586_4a.cpp:8:5: warning:   matches this 'a' under ISO standard rules
 int a[]= {
     ^
p586_4a.cpp:46:14: warning:   matches this 'a' under old rules
     for (int a=1; a<=sqrtn; a++)
              ^

D:\>acpp1
16 :2 2 2 2
25 :5 5
f(10000,2)=2
cpp
D:\>clang++ --version
clang version 3.6.0 (216184)
Target: i686-pc-windows-gnu
Thread model: posix
D:\>clang++ p586_4a.cpp -o acpp.exe
p586_4a.cpp:63:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
1 warning generated.

D:\>acpp
16 :2 2 2 2
25 :5 5
f(10000,2)=2

换了一个mingw版本,能编译,但最后出“无法定位程序输入点”错

D:\>g++ --version
g++ (tdm-1) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


D:\>clang++ --version
clang version 3.9.0 (branches/release_39)
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: D:\LLVM\bin

D:\>g++ p530.cpp

D:\>g++ p586_4a.cpp
p586_4a.cpp: In function 'int f(int, int)':
p586_4a.cpp:59:17: warning: name lookup of 'a' changed
             fct(a,i);
                 ^
p586_4a.cpp:8:5: warning:   matches this 'a' under ISO standard rules
 int a[]= {
     ^
p586_4a.cpp:46:14: warning:   matches this 'a' under old rules
     for (int a=1; a<=sqrtn; a++)
              ^
---------------------------
as.exe - 无法找到入口
---------------------------
无法定位程序输入点 libiconv 于动态链接库 libiconv-2.dll 上。 
---------------------------
确定   
---------------------------

我觉得已经接近真相了,问题出在3.8以上版本的llvm的官方编译目标是 i686-pc-windows-msvc,
如果是i686-pc-windows-gnu,则能够配合mingw

D:\>clang++ --version
clang version 4.0.0 (trunk)
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: D:\LLVM\bin

D:\>cd \llvm391

D:\LLVM391>bin\clang++ --version
clang version 3.9.1 (branches/release_39)
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: D:\LLVM391\bin

D:\LLVM391>cd \LLVM381

D:\LLVM381>bin\clang++ --version
clang version 3.8.1 (branches/release_38)
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: D:\LLVM381\bin

D:\LLVM381>cd \llvm371

D:\LLVM371>bin\clang++ --version
clang version 3.7.1 (tags/RELEASE_371/final)
Target: i686-pc-windows-gnu
Thread model: posix
----
set MINGW_HOME=D:\win32sj\mingw32
set MINGW_VERSION=6.3.0
set "PATH=%MINGW_HOME%\bin;%PATH%"
set SS=i686-w64-mingw32
set "C_INCLUDE_PATH=%MINGW_HOME%\include;%MINGW_HOME%\%SS%\include"
set "CPLUS_INCLUDE_PATH=%C_INCLUDE_PATH%;%MINGW_HOME%\%SS%\include;%MINGW_HOME%\%SS%\include\c++;%MINGW_HOME%\%SS%\include\c++\%SS%;%MINGW_HOME%\%SS%\include\c++\backward"
set GCC_INCPATH=%MINGW_HOME%\lib\gcc\%SS%\%MINGW_VERSION%\include
set "CPLUS_INCLUDE_PATH=%CPLUS_INCLUDE_PATH%;%GCC_INCPATH%;%GCC_INCPATH%\c++;%GCC_INCPATH%\c++\%SS%;%GCC_INCPATH%\c++\backward"
set  LLVM_HOME=D:\LLVM371
set "PATH=%LLVM_HOME%\bin;%PATH%"

D:\>g++ --version
g++ (i686-win32-sjlj-rev1, Built by MinGW-W64 project) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


D:\>clang++ --version
clang version 3.7.1 (tags/RELEASE_371/final)
Target: i686-pc-windows-gnu
Thread model: posix

D:\>clang++ test.c
clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated

D:\>clang++ test.cpp


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多