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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With