0

in my project I would like to use the header on a raspberry pi zero. However, inside the header, this statement evaluates to false:

#if __cplusplus >= 201703L I checked the value and it is indeed just at 201402L

g++ --version returns g++ (Raspbian 10.2.1-6+rpi1) 10.2.1 20210110 and in my Makefile I specified: CXXFLAGS := -std=c++17 -Wall.

g++ -x c++ -std=c++17 -dM -E - </dev/null | less lists the value for #define __cplusplus 201703L

So I quite don't understand, why the __cplusplus value is still at the value for c++14. Is there a way to update/change/set this macro?

Edit: My Makefile

SOURCES := $(shell find ./src -name '*.cpp')
CXXFLAGS := -std=c++17 -Wall

default: 
    $(CXX) $(CXXFLAGS) -O3 -pthread -o main $(SOURCES) -lpigpio -lrt

.PHONY: clean
clean:
    rm main

Output, when I run make

g++ -std=c++17 -Wall -O3 -pthread -o main <all the cpp files here> -lpigpio -lrt
456c526f
  • 123
  • 6
  • 2
    did you try to set the [CXX_STANDARD](https://stackoverflow.com/questions/5541946/cflags-ccflags-cxxflags-what-exactly-do-these-variables-control)? – folibis Jan 20 '23 at 09:55
  • 1
    This macro is set by your compiler. You could, of course, do `undef` and then `define` before including the header, but that would be highly counter productive. It is much more likely that your makefile has a problem. – Refugnic Eternium Jan 20 '23 at 09:55
  • You have confirmed your compiler supports C++17, but it seems your project is compiling in C++14. How have you confirmed that your makefile is written correctly? What is the g++ command line when you use the makefile? – VLL Jan 20 '23 at 09:58
  • Can't reproduce here: https://gcc.godbolt.org/z/Yoaqr6cv1 Show your makefile. – HolyBlackCat Jan 20 '23 at 09:58
  • 1
    Your manually-executed command explicitly specified `-std=c++17`, but what about whatever build system you're using to compile the real code? – Sam Varshavchik Jan 20 '23 at 10:01
  • @VLL just edited my post and added the makefile and the output – 456c526f Jan 20 '23 at 10:15
  • @HolyBlackCat running the same Code in my main also produces `201703` as Output, thats a bit weird now. The macro inside the header still evaluates to false – 456c526f Jan 20 '23 at 10:20
  • 1
    How do you know what it evaluates to? – HolyBlackCat Jan 20 '23 at 10:23

0 Answers0