c++ - Meson 选择了错误的编译器(GCC 而不是 clang)

标签 c++ gcc clang clang++ meson-build

我正在尝试将我的项目配置为使用 LLVM/clang++ 构建,但始终选择 GCC:

$ /opt/llvm/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04/bin/clang++ --version
clang version 7.0.1 (tags/RELEASE_701/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04/bin
$ 
$ CC=/opt/llvm/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04/bin/clang++ meson ~/build
The Meson build system
Version: 0.49.1
Source dir: ~/source
Build dir: ~/build
Build type: native build
Project name: test
Project version: 0.1.0
Native C++ compiler: ccache c++ (gcc 6.3.0 "c++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516")
Build machine cpu family: x86_64
Build machine cpu: x86_64
Message: Compiler: GCC
Dependency threads found: YES 
Build targets in project: 2
Found ninja-1.8.2 at /opt/ninja

操作系统为 Debian Linux 9。

这是 meson.build 文件:

## meson.build

project('MyPrj', 'cpp',
        version: '0.1.0',
        meson_version: '>= 0.44',
        license: 'GPL',
        default_options: [
            'cpp_std=c++17',
            'warning_level=3',
            'buildtype=release'
        ]
       )

#
# Compiler configuration
# To set a default compiler, from the OS shell:
#   $ CC=mycc meson <options>

compiler = meson.get_compiler('cpp')

warning_level = get_option('warning_level').to_int()

if compiler.get_id() == 'gcc'
    message('Compiler: GCC')
    libs_compiler = ['-lstdc++fs']
    libs_linker   = ['-lstdc++fs']
elif compiler.get_id() == 'clang'
    message('Compiler: LLVM/clang')
    libs_compiler = ['-stdlib=libc++']
    libs_linker   = ['-stdlib=libc++', '-lstdc++fs']
endif

add_global_arguments('-Wall', '-Wextra', '-Wmissing-declarations',
                     '-Wno-unused', # keep this commented out
                     libs_compiler,
                     language: 'cpp')

add_global_link_arguments(libs_linker, language: 'cpp')

# '.' will refer to current build directory
include_dirs = include_directories('.')

src = [ 'test.cc' ]

# External dependencies

thread_dep = dependency('threads')

# Build

test_a = static_library('test', src,
                           include_directories : include_dirs,
                          )

test_exe = executable('testexe', src,
                           include_directories : include_dirs
                          )

如何说服 Meson 使用 clang?

最佳答案

设置相关的C/C++环境变量。即 CC=clangCXX=clang++。然后使用 meson build-clang 运行构建。

这将解决问题。

关于c++ - Meson 选择了错误的编译器(GCC 而不是 clang),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54677391/

相关文章:

c++ - 用于 32 位字循环的 ARM 内联汇编

ios - 基于 iOS Swift 的动态框架中的 Objective C 类

c++ - 测试用例 VS ASSERTION 语句

c++ - 我的代码会安全地检查下溢吗?

gcc - 错误 : Invalid character in name at (1)

Clang 集成汇编器和 "invalid operand for instruction"

c - 静态分析奇怪的结果

C++ 找到二进制数的最高有效位?

c++ - 任务栏编程

c - Pthread代码运行时中途崩溃