You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用CMake的IN_LIST条件时出现“Unknown arguments specified”错误

问题原因及解决方法

你的脚本问题出在IN_LIST条件的语法使用上:

  • 错误写法:if ("two" IN_LIST ${my_list})
  • 这里的${my_list}会被CMake直接展开成列表的三个元素one two three,导致if命令收到的参数变成"two" "IN_LIST" "one" "two" "three",完全不符合IN_LIST的语法要求(正确语法是值 IN_LIST 变量名),所以触发了参数错误。

正确的用法是直接使用变量名,不需要用${}展开:

cmake_minimum_required(VERSION 3.25.0 FATAL_ERROR)
project(foo)
set(my_list one two three)
if ("two" IN_LIST my_list)
  message("two is in your list")
else()
  message("two is NOT in your list")
endif()

这样CMake会正确识别my_list是一个列表变量,检查"two"是否存在于这个列表中。

内容的提问来源于stack exchange,提问作者einpoklum

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 17:59:55