chrberger / libcluon

libcluon is a small and efficient, single-file and header-only library written in modern C++ to power microservices.
Mozilla Public License 2.0
100 stars 13 forks source link

Unable to compile single header on Windows #6

Closed piotrek-szczygiel closed 5 years ago

piotrek-szczygiel commented 5 years ago

I cannot get it to compile using Visual Studio 2019 with C++17 standard enabled.

Compiler messages:

1>C:\dev\raspberry-console\socket\cluon.hpp(9806,76): error C2589: 'constant': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(9806,76): error C2062: type 'unknown-type' unexpected
1>C:\dev\raspberry-console\socket\cluon.hpp(9807,19): error C2181: illegal else without matching if
1>C:\dev\raspberry-console\socket\cluon.hpp(9793): error C2317: 'try' block starting on line '9793' has no catch handlers
1>C:\dev\raspberry-console\socket\cluon.hpp(9811,11): error C2181: illegal else without matching if
1>C:\dev\raspberry-console\socket\cluon.hpp(9812,23): error C2065: 'listOfMetaMessages': undeclared identifier
1>C:\dev\raspberry-console\socket\cluon.hpp(9814,7): error C2059: syntax error: 'catch'
1>C:\dev\raspberry-console\socket\cluon.hpp(9814,31): error C2143: syntax error: missing ';' before '{'
1>C:\dev\raspberry-console\socket\cluon.hpp(9814,31): error C2447: '{': missing function header (old-style formal list?)
1>C:\dev\raspberry-console\socket\cluon.hpp(9816,5): error C2059: syntax error: 'return'
1>C:\dev\raspberry-console\socket\cluon.hpp(9818,1): error C2059: syntax error: '}'
1>C:\dev\raspberry-console\socket\cluon.hpp(9818,1): error C2143: syntax error: missing ';' before '}'
1>C:\dev\raspberry-console\socket\cluon.hpp(9833,17): error C2143: syntax error: missing ';' before '{'
1>C:\dev\raspberry-console\socket\cluon.hpp(9833,17): error C2447: '{': missing function header (old-style formal list?)
1>C:\dev\raspberry-console\socket\cluon.hpp(13507,56): error C2589: 'constant': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(13507,8): error C2059: syntax error: '=='
1>C:\dev\raspberry-console\socket\cluon.hpp(13507,90): error C2143: syntax error: missing ';' before '{'
1>C:\dev\raspberry-console\socket\cluon.hpp(14140,56): error C2589: 'constant': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(14140,8): error C2059: syntax error: '=='
1>C:\dev\raspberry-console\socket\cluon.hpp(14140,90): error C2143: syntax error: missing ';' before '{'
1>C:\dev\raspberry-console\socket\cluon.hpp(14417,73): warning C4003: not enough arguments for function-like macro invocation 'max'
1>C:\dev\raspberry-console\socket\cluon.hpp(14417,73): error C2589: '(': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(14417,73): error C2062: type 'unknown-type' unexpected
1>C:\dev\raspberry-console\socket\cluon.hpp(14417,73): error C2059: syntax error: ')'
1>C:\dev\raspberry-console\socket\cluon.hpp(14418,73): warning C4003: not enough arguments for function-like macro invocation 'min'
1>C:\dev\raspberry-console\socket\cluon.hpp(14418,73): error C2589: '(': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(14418,73): error C2062: type 'unknown-type' unexpected
1>C:\dev\raspberry-console\socket\cluon.hpp(14418,73): error C2059: syntax error: ')'
1>C:\dev\raspberry-console\socket\cluon.hpp(14420,44): error C2589: '(': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(14420,44): error C2062: type 'unknown-type' unexpected
1>C:\dev\raspberry-console\socket\cluon.hpp(14420,44): error C2059: syntax error: ')'
1>C:\dev\raspberry-console\socket\cluon.hpp(14421,44): error C2589: '(': illegal token on right side of '::'
1>C:\dev\raspberry-console\socket\cluon.hpp(14421,44): error C2062: type 'unknown-type' unexpected
1>Generating Code...
1>C:\dev\raspberry-console\socket\cluon.hpp(14421,44): error C2059: syntax error: ')'

Looks like it fails while parsing MessageParserErrorCodes::NO_ERROR for some reason.

Some code context:

9804            if (check4UniqueFieldNames(*ast, tmpPrefix, tmpMessageNames, tmpFieldNames, tmpNumericalMessageIdentifiers, tmpNumericalFieldIdentifiers)) {
9805               transform2MetaMessages(*ast, listOfMetaMessages);
9806                retVal = {listOfMetaMessages, MessageParserErrorCodes::NO_ERROR};
9807            } else {
9808                retVal = {listOfMetaMessages, MessageParserErrorCodes::DUPLICATE_IDENTIFIERS};
9809            }
chrberger commented 5 years ago

I tried C++17 with GCC 9.2 here where I could not reproduce the compiler error using libcluon v0.0.126 on a minimal example: https://wandbox.org/permlink/g3VbL5v2aYWZrHvQ

We have AppVeyor with VS2017/19.16.27032.1 running using C++14: https://ci.appveyor.com/project/chrberger/libcluon; could you try a different C++ standard to provide more details about this?

chrberger commented 5 years ago

I just tested Visual Studio 2019/C++17 on AppVeyor (https://ci.appveyor.com/project/chrberger/libcluon#L837) using this commit (https://github.com/chrberger/libcluon/commit/959e99dbf004e3a508ea3bfcac3ffbd456bfbe21) which was compiled and tested successfully.

Sopel97 commented 5 years ago

There is a problem. It collides with windows's NO_ERROR macro Same goes for min/max

barulicm commented 5 years ago

I'm getting a similar error with MinGW 7.3.0 (tried standards 14 and 17)

Minimal example:

#include <cluon/cluon-complete.hpp>
int main() {
    return 0;
}

The compilation fails with:

.../cluon/cluon-complete.hpp: In member function 'std::pair<std::vector<cluon::MetaMessage>, cluon::MessageParser::MessageParserErrorCodes> cluon::MessageParser::parse(const string&)':
.../cluon/cluon-complete.hpp:9806:76: error: expected unqualified-id before numeric constant
                     retVal = {listOfMetaMessages, MessageParserErrorCodes::NO_ERROR};
                                                                            ^
chrberger commented 5 years ago

I have prepared the changes related to NO_ERROR in MessageParser.cpp (https://github.com/chrberger/libcluon/commit/ac95c6d4989be8d6e894411869c7b6a38c1ed3c0).

Before I will make a new release, may I ask you, @barulicm, to check the header-only file that I put here into the online C++ compiler Wandbox: https://wandbox.org/permlink/0tPXbiAtmGVdp4Kx if the error has been resolved for your minimal example with MinGW?

barulicm commented 5 years ago

That seems to have addressed the NO_ERROR issue. Unfortunately, there are now errors like the following for every use of ntohll and htonll

In file included from C:\Users\matth\CLionProjects\cluontest\main.cpp:1:0:
...\cluon-complete.hpp: In member function 'void cluon::FromLCMVisitor::decodeFrom(std::istream&)':
...\cluon-complete.hpp:5631:20: error: 'ntohll' was not declared in this scope
 #define be64toh(x) ntohll(x)
                    ^
...\cluon-complete.hpp:11617:39: note: in expansion of macro 'be64toh'
 m_expectedHash = static_cast<int64_t>(be64toh(m_expectedHash));
                                       ^
...\cluon-complete.hpp:5631:20: note: suggested alternative: 'ntohl'
 #define be64toh(x) ntohll(x)
                    ^
...\cluon-complete.hpp:11617:39: note: in expansion of macro 'be64toh'
 m_expectedHash = static_cast<int64_t>(be64toh(m_expectedHash));
                                       ^
chrberger commented 5 years ago

I made another change to lines 5,620 - 5,625 here: https://wandbox.org/permlink/dpKAs1BN6MBq5b8B

Could you try again if the missing symbols are now defined on your platform?

barulicm commented 5 years ago

That new version built successfully. I was also able to build and run the time stamping and TCP server examples without any problems. Looks fixed to me!

barulicm commented 5 years ago

I may have spoken too soon. I switched my tool chain to Visual Studio (2019), just to see, and I got the following errors on the bare bones example.

main.cpp
...\cluon-complete.hpp(14499): warning C4003: not enough arguments for function-like macro invocation 'max'
...\cluon-complete.hpp(14499): error C2589: '(': illegal token on right side of '::'
...\cluon-complete.hpp(14499): error C2062: type 'unknown-type' unexpected
...\cluon-complete.hpp(14499): error C2059: syntax error: ')'
...\cluon-complete.hpp(14500): warning C4003: not enough arguments for function-like macro invocation 'min'
...\cluon-complete.hpp(14500): error C2589: '(': illegal token on right side of '::'
...\cluon-complete.hpp(14500): error C2062: type 'unknown-type' unexpected
...\cluon-complete.hpp(14500): error C2059: syntax error: ')'
...\cluon-complete.hpp(14502): error C2589: '(': illegal token on right side of '::'
...\cluon-complete.hpp(14502): error C2062: type 'unknown-type' unexpected
...\cluon-complete.hpp(14502): error C2059: syntax error: ')'
...\cluon-complete.hpp(14503): error C2589: '(': illegal token on right side of '::'
...\cluon-complete.hpp(14503): error C2062: type 'unknown-type' unexpected
...\cluon-complete.hpp(14503): error C2059: syntax error: ')'
chrberger commented 5 years ago

Thanks for testing, @barulicm ; may I ask you to check this version (https://github.com/chrberger/libcluon/commit/778f46c4cb507d854ffff62d9a3ced110a36ce53) where I changed the min/max part: https://wandbox.org/permlink/FDM8LZ4HHCMYD5Ag

barulicm commented 5 years ago

Almost worked. I had to change lines 14499 and 14500 from:

int64_t smallestSampleTimePoint = (std::numeric_limits<int64_t>::max());
int64_t largestSampleTimePoint  = (std::numeric_limits<int64_t>::min());

to:

int64_t smallestSampleTimePoint = (std::numeric_limits<int64_t>::max)();
int64_t largestSampleTimePoint  = (std::numeric_limits<int64_t>::min)();

With that small change, it worked for both mingw and visual studio.

chrberger commented 5 years ago

@barulicm, thanks for your feedback; I am happy that it does compile now for you. I will now prepare the next official release.

@piotrek-szczygiel: If you want to proceed, you can find the latest version including all patches here: https://wandbox.org/permlink/b6WpI4Y8fmuhWxdn