CMake列表获取命令 [英] Cmake list-get command

查看:41
本文介绍了CMake列表获取命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下命令为什么不起作用?

Why doesn't the following command work?

SET(MY_LIST a b c d)
LIST(GET ${MY_LIST} 0 HEAD)
MESSAGE("HEAD = ${HEAD}")

I希望它将 a 分配给 HEAD ,但是我却得到了 NOTFOUND

I want it to assign a to HEAD but instead I'm getting NOTFOUND.

我已经尝试将 $ {MY_LIST} 括在双引号中并将索引更改为1而不是0(不知道为什么有人会这样做,但是尝试尝试并没有伤害)。

I have already tried surrounding ${MY_LIST} with double quotes and changing the index to 1 instead of 0 (don't know why someone would do that but it didn't hurt to try).

推荐答案

href = https://cmake.org/cmake/help/latest/command/list.html rel = noreferrer>列表命令需要未取代变量作为第二个参数,即:

The list commands require an unsubstituted variable as the second argument, i.e.:

set (MY_LIST a b c d)
list (GET MY_LIST 0 HEAD)
message ("HEAD = ${HEAD}") 

这篇关于CMake列表获取命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆