Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 介子选择了错误的编译器(GCC而不是clang)_C++_Gcc_Clang_Clang++_Meson Build - Fatal编程技术网

C++ 介子选择了错误的编译器(GCC而不是clang)

C++ 介子选择了错误的编译器(GCC而不是clang),c++,gcc,clang,clang++,meson-build,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/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
操作系统是DebianLinux9

这是
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
                          )
##介子.build
项目(“MyPrj”、“cpp”,
版本:“0.1.0”,
介子_版本:'>=0.44',
许可证:“GPL”,
默认选项:[
“cpp_std=c++17”,
“警告级别=3”,
“buildtype=release”
]
)
#
#编译器配置
#要设置默认编译器,请从操作系统外壳:
#$CC=mycc介子
编译器=介子.get\u编译器('cpp')
警告级别=获取选项(“警告级别”)。到
if compiler.get_id()=“gcc”
消息('编译器:GCC')
libs_编译器=['-lstdc++fs']
libs_链接器=['-lstdc++fs']
elif编译器。get_id()=='clang'
消息('编译器:LLVM/clang')
libs_编译器=['-stdlib=libc++']
libs_linker=['-stdlib=libc++','-lstdc++fs']
恩迪夫
添加全局参数('-Wall','-Wextra','-Wmissing声明',
“-Wno unused”#保留此注释
libs_编译器,
语言:“cpp”)
添加全局链接参数(libs链接器,语言:“cpp”)
#“.”将引用当前生成目录
include_dirs=include_目录('.'))
src=['test.cc']
#外部依赖关系
thread\u dep=依赖关系('threads')
#建造
test_a=静态_库('test',src,
包含目录:包含目录,
)
test_exe=可执行文件('testexe',src,
包含目录:包含目录
)

如何说服介子使用clang?

设置相关的C/C++环境变量。i、 例如,
CC=clang
CXX=clang++
。然后使用
介子build-clang
运行构建


这将解决问题。

您是否设置了
env
变量?i、 例如,
CC=clang
CXX=clang++
?然后运行maybe do
meson build clang
。RiTITY-OPS,我用CC环境变量指定C++编译器,而不是CXX。现在它起作用了。如果你把你的评论作为答案,我会接受它。完成,高兴它错误地认为代码> cc/<代码>是C,而C++是代码> cc>代码,这根本没有意义,你不能在<代码>介子中指定它。