VS2019 CMake linux项目指定gcc版本

2 篇文章 0 订阅
1 篇文章 0 订阅
本文介绍了如何在Visual Studio 2019的CMake Linux项目中指定GCC版本,提供了三种方法:通过命令行参数、设置编译器变量和修改缓存区。同时警告了直接修改缓存区可能会破坏编译器检查和配置,影响后续的工具探测。详细步骤和注意事项帮助开发者正确指定GCC版本。
摘要由CSDN通过智能技术生成

VS2019 CMake linux项目指定gcc版本

在项目顶层的CmakeLists.txt中 设置
1、

CC=gcc-4.2 CXX=/usr/bin/g++-4.2 cmake -G "Your Generator" path/to/your/source

2、

cmake -G "Your Generator" -D CMAKE_C_COMPILER=gcc-4.2 -D CMAKE_CXX_COMPILER=g++-4.2 path/to/your/source
cmake -D CMAKE_C_COMPILER=/usr/bin/gcc -D CMAKE_CXX_COMPILER=/usr/bin/g++ . -DRUN_IN_PLACE=TRUE

3、设置缓存区

set(CMAKE_C_COMPILER /usr/bin/clang CACHE PATH "" FORCE)
set(CMAKE_CXX_COMPILER /usr/bin/clang++ CACHE PATH "" FORCE)

会破坏编译器检查和配置

This is almost the same as the “normal” variable version, the only difference is your value will be set in the cache, so users can see it. But any change will be overwritten by the set command.

Breaking compiler checks and tooling

Early in the configuration process, CMake performs checks on the
compiler: Does it work? Is it able to produce executables? etc. It
also uses the compiler to detect related tools, like ar and ranlib.
When you override the compiler value in a script, it’s “too late”, all
checks and detections are already done.

For instance, on my machine with gcc as default compiler, when using
the set command to /usr/bin/clang, ar is set to /usr/bin/gcc-ar-7.
When using an export before running CMake it is set to
/usr/lib/llvm-3.8/bin/llvm-ar.
设置详解
cmake 设置 gcc 版本 官方

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值