vendredi 2 juin 2023

g++ Flag variable not seen by make

Folks, I need some help in understanding what's happening, I do not see how to pass an option to g++ compiler in a makefile. If you can just try to reproduce my stuff and get me some info, it would be valuable (for me).

Makefile content:

MYCPPFLAGS := what a surprise

%.o: %.cpp %.h
    g++ $(MYCPPFLAGS) -c $< -o $@

dumpy:
    echo $(MYCPPFLAGS)

It's not that kind of magic, isn't it??? Now I have a c++11 file named dessiner.cpp, if you need it I'll post it, but let's skip it for the moment. Please have a look at what I get in the terminal:

grenx08{lc177705}hw-m2-cpp-07-dessiner: make dumpy
echo what a surprise
what a surprise
grenx08{lc177705}hw-m2-cpp-07-dessiner: make dessiner.o
g++    -c -o dessiner.o dessiner.cpp
dessiner.cpp:18:13: warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11 [enabled by default]

[... 
a series of warnings/ errors because I did not use std=c++11 option] 

make: *** [dessiner.o] Error 1

So my question is : why can't I see anything about "what a surprise" in the g++ command-line, but just four blank spaces???? Is make smarter than me (LoL, of course!!!) and erasing stupid options passed to g++??? The real issue is that in this case, I cannot even give the good options... Please find hereby the sware versions, quite old stuff due to a constrained working environment. Any hint appreciated.

grenx08{lc177705}hw-m2-cpp-07-dessiner: make -v
GNU Make 3.82
Built for x86_64-redhat-linux-gnu
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
grenx08{lc177705}hw-m2-cpp-07-dessiner: g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Edit 1:

grenx08{lc177705}hw-m2-cpp-07-dessiner: make -d dessiner.o
GNU Make 3.82
Built for x86_64-redhat-linux-gnu
[ tons of output ]
  No need to remake target `dessiner.cpp'.
 Finished prerequisites of target file `dessiner.o'.
Must remake target `dessiner.o'.
Invoking builtin recipe to update target `dessiner.o'.
g++    -c -o dessiner.o dessiner.cpp
[ other irrelevant output ]

grenx08{lc177705}hw-m2-cpp-07-dessiner: make -r dessiner.o
make: *** No rule to make target `dessiner.o'.  Stop.

So it looks as my rule definition has a flaw? I have no .h file...

Aucun commentaire:

Enregistrer un commentaire