ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.64k stars 399 forks source link

Windows build error using msvc 142 #59

Closed YuzukiTsuru closed 3 years ago

YuzukiTsuru commented 3 years ago
D:\include\ftxui/screen/color.hpp(22): error C2059: syntax error: "("
D:\include\ftxui/screen/color.hpp(22): error C2091: function return function
D:\include\ftxui/screen/color.hpp(22): error C2143: syntax error: missing "," (before "|")
D:\include\ftxui/screen/color.hpp(22): error C2535: "ftxui::Color::Color(void)": Member function has been defined or declared
D:\include\ftxui/screen/color.hpp(17): note: see the declaration of "ftxui::Color::Color"
D:\include\ftxui/screen/color.hpp(22): error C2059: syntax error: "|"
D:\include\ftxui/screen/color.hpp(22): error C2059: syntax error: ")"
D:\include\ftxui/screen/color.hpp(22): error C2238: Unexpected mark is located before ";"
ArthurSonzogni commented 3 years ago

Thanks for reporting this. The continuous integration build it on windows and there was no problem: https://travis-ci.com/github/ArthurSonzogni/FTXUI/jobs/406888815

Are you sure this isn't caused by your usage? Are you just compiling the FTXUI library, or are you compiling your project?

YuzukiTsuru commented 3 years ago

I will confirm it and build example

robinlinden commented 3 years ago

This is caused by a conflict with a macro defined in a Windows header: https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-rgb. I ran into the same issue by including an ASIO header before including FTXUI headers.

I would open a PR fixing it, but the options are

  1. #undef RGB which could break user code if adding FTXUI includes.
  2. Change the name of the static function to something like Rgb. Breaking change, but maybe the nicer option?

If you let me know what you think, I can open a PR with a fix. :)

ArthurSonzogni commented 3 years ago

Thanks @robinlinden!

I think this window header you mentioned shouldn't have defined such a macro with this very common name. I believe option 1 might be worth it to be tried?

A windows header is breaking us, we break it in return? ;-)

robinlinden commented 3 years ago

Sounds good, will open a PR in a bit! :) If users really want the macro, they can always move the Windows header to after the line where ftxui's headers are included and everything will work.