vendredi 30 août 2019

g++.exe ignores platform-specific-macro if-else in code

So, in my cpp project, I have a portion of code where I want to wait for some seconds. Because of platform-specific differences to sleep() or Sleep() , I use some platform-specific macros. However, g++.exe errored:

$ mkdir Debug && cd Debug
$ g++ -MM -std=c++11 ../RichmanMA.cpp
RichmanMA.o: ../RichmanMA.cpp ../libs/utils.h ../libs/cttrie.h \
 ../libs/cstr.h ../libs/getindex.h ../libs/stringview.h \
 ../libs/cttrie_sw32.tcc ../libs/cttrie_sw256.tcc
(Note: all fine here)
$ g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"RichmanMA.d" -MT"RichmanMA.o" -o "RichmanMA.o" "../RichmanMA.cpp"
(Note: this time g++.exe exited with 1)
$ g++  -o $TRAVIS_OS_NAME ./RichmanMA.o
(Note: g++.exe exited with 1 again here)



../RichmanMA.cpp:193:6: error: 'sleep' was not declared in this scope
      sleep(3);
      ^~~~~
44../RichmanMA.cpp:193:6: note: suggested alternative: 'Sleep'
      sleep(3);
      ^~~~~
      Sleep

But the place where the compiler errored was supposed to be circumvented by a macro-specific #if #else! Here's the context:

#ifdef __WIN32__
                    system("start Drumrool.mp3");
                    Sleep(7000);
#else
                    system("open Drumrool.mp3");
                    sleep(7);
#endif
                    printf("Details in https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode!\n");
#ifdef __WIN32_
                    Sleep(3000);
#else
                    sleep(3);//Error here
#endif

Now, I have two questions:

  1. Why did g++.exe error on the fourth macro?
  2. How do I make g++.exe not error?

Aucun commentaire:

Enregistrer un commentaire