syb0rg
syb0rg

Reputation: 8247

Stringify CMake preprocessor token

I'm using CMake to compile this example program:

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)

main.c:

#include <stdio.h>

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

Compiling gives me the following error:

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

How can I stringify this preprocessor token without modifying main.c?

Upvotes: 3

Views: 795

Answers (1)

chema989
chema989

Reputation: 4182

You are using the characters and that are not valid in C:

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

You must change and for " in your CMakeLists.txt and your program will compile.

Upvotes: 3

Related Questions