【问题标题】:Stringify CMake preprocessor token字符串化 CMake 预处理器令牌
【发布时间】:2016-11-09 02:26:14
【问题描述】:

我正在使用 CMake 编译这个示例程序:

CMakeLists.txt

cmake_minimum_required (VERSION 3.0.0)
set(PROJECT_NAME Main)
project(${PROJECT_NAME})

add_definitions(-DSTRING=“test”)

add_executable(${PROJECT_NAME} main.c)

ma​​in.c

#include <stdio.h>

int main(void)
{
    puts(STRING);
}

编译给我以下错误:

error: expected expression
    puts(STRING);
         ^
<command line>:1:16: note: expanded from here
#define STRING "test"

如何在不修改main.c 的情况下将此预处理器令牌字符串化?

【问题讨论】:

  • 我希望您实际上并没有在 CMakeLists.txt 中使用“智能引号”,尽管您的示例显示了它们:-DSTRING=“test”

标签: c string cmake c-preprocessor token


【解决方案1】:

您使用的字符 在 C 中无效:

error: expected expression
        puts(STRING);
         ^
<command line>:1:16: note: expanded from here
#define STRING “test”
           ^
1 error generated.

您必须在 CMakeLists.txt 中将 更改为 ",您的程序才能编译。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-06-21
  • 1970-01-01
  • 1970-01-01
  • 2011-09-24
  • 2011-11-15
  • 2018-09-23
  • 2013-09-25
  • 2011-10-22
相关资源
最近更新 更多