The -D option is incorrectly expanded from the g ++ command line

In the C ++ CodeBlocks project, I added the following definitions to the project settings, compiler settings, #define:

_DEBUG
DATA_DIR = \ "/ media / Shared / SiX / Data \"

This creates the following g ++ command line:

g ++ -Wall -g -fPIC -save-temps -D_DEBUG -DDATA_DIR = \ "/ media / Shared / SiX / Data \" -I ../ Includes -c /media/Shared/SiX/SiXConfiguration/PathManager.cpp -o obj / Debug / PathManager.o

This code does not compile:

char * commonDataDir;
#ifdef DATA_DIR
commonDataDir = DATA_DIR;
#endif

Looking at the output file of the preprocessor, I see that the line of source code is expanded as follows:

commonDataDir = / media / Shared / SiX / Data;

I expect:

commonDataDir = "/ media / Shared / SiX / Data";

The same code compiled correctly from the Eclipse CDT:

g++ -D_DEBUG -DDATA_DIR=\"/media/Shared/SiX/Data\" -I"/media/Shared/SiX (copy)/Includes" -O3 -Wall -c -fmessage-length=0 -fPIC -ggdb -MMD -MP -MF"PathManager.d" -MT"PathManager.d" -o"PathManager.o" "../PathManager.cpp"

, - g++. ?

+3
4

, .
.

#define DO_QUOTE(X)       #X
#define QUOTE(X)          DO_QUOTE(X)

#ifndef DATA_DIR
#define DATA_DIR       /tmp
#endif

char commonDataDir[] = QUOTE(DATA_DIR);
+4

Code:: Blocks - > → #

DATA_DIR=\\"/media/Shared/SiX/Data\\"

( , , )

+2

"

-DDATA_DIR="\"/media/Shared/SiX/Data\""
           ^                          ^
0
source

It seems to fix this.

g++ -DDATA_DIR='"/media/Shared/SiX/Data"' ...
0
source

Source: https://habr.com/ru/post/1770104/


All Articles