NTNU-IHB / FMI4cpp

FMI 2.0 implementation written in modern C++.
MIT License
93 stars 34 forks source link

Syntax errors on windows when compiling an application #127

Closed PucklaJ closed 1 year ago

PucklaJ commented 2 years ago

I am trying to add FMI4cpp to the xmake-repo. Link to PR. After solving some other issues I stumbled over some syntax errors.

C:\Users\runneradmin\AppData\Local\.xmake\packages\f\fmi4cpp\0.8.0\334f1334676140cab16485e916dbec1e\include\fmi4cpp/fmi2/xml/typed_scalar_variable.hpp(115): error C2059: syntax error: ')'
C:\Users\runneradmin\AppData\Local\.xmake\packages\f\fmi4cpp\0.8.0\334f1334676140cab16485e916dbec1e\include\fmi4cpp/fmi2/xml/typed_scalar_variable.hpp(129): note: see reference to class template instantiation 'fmi4cpp::fmi2::bounded_scalar_variable<T,U>' being compiled
C:\Users\runneradmin\AppData\Local\.xmake\packages\f\fmi4cpp\0.8.0\334f1334676140cab16485e916dbec1e\include\fmi4cpp/fmi2/xml/typed_scalar_variable.hpp(115): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
C:\Users\runneradmin\AppData\Local\.xmake\packages\f\fmi4cpp\0.8.0\334f1334676140cab16485e916dbec1e\include\fmi4cpp/fmi2/xml/typed_scalar_variable.hpp(129): error C2143: syntax error: missing ')' before ';'
C:\Users\runneradmin\AppData\Local\.xmake\packages\f\fmi4cpp\0.8.0\334f1334676140cab16485e916dbec1e\include\fmi4cpp/fmi2/xml/typed_scalar_variable.hpp(129): error C2059: syntax error: ')'
C:\Users\runneradmin\AppData\Local\.xmake\packages\f\fmi4cpp\0.8.0\334f1334676140cab16485e916dbec1e\include\fmi4cpp/fmi2/xml/typed_scalar_variable.hpp(129): error C2238: unexpected token(s) preceding ';'
C:\Users\runneradmin\AppData\Local\.xmake\packages\f\fmi4cpp\0.8.0\334f1334676140cab16485e916dbec1e\include\fmi4cpp/fmi2/xml/typed_scalar_variable.hpp(129): fatal error C1201: unable to continue after syntax error in class template definition

Could someone help me determine what the issue is. I can't see any error in the code.

markaren commented 2 years ago

Compiler version and language standard?

PucklaJ commented 2 years ago

You can look at the complete build process if you look at the PR mentioned above. This syntax error occurs on MSVC 2022 and 2019 versions. The language standard is set to C++17 using the -std:c++17 flag (I also tried /std:c++17 but this changed nothing).

PucklaJ commented 2 years ago
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX64\\x64\\cl.exe" -c /EHsc -nologo /MT -std:c++17 -DBOOST_ALL_NO_LIB -external:W0 -external:IC:\Users\runneradmin\AppData\Local\.xmake\packages\f\fmi4cpp\0.8.0\334f1334676140cab16485e916dbec1e\include -external:W0 -external:IC:\Users\runneradmin\AppData\Local\.xmake\packages\b\boost\1.78.0\e7f230f8b6e74f199a0c2484f358c00c\include -external:W0 -external:IC:\Users\runneradmin\AppData\Local\.xmake\packages\l\libzip\1.8.0\4fbc31ec5b664147aa73660680c2d2ba\include -external:W0 -external:IC:\Users\runneradmin\AppData\Local\.xmake\packages\z\zlib\v1.2.11\a593fa3f71e64cf790ec96898b34de8a\include -FoC:\Users\RUNNER~1\AppData\Local\Temp\.xmake\220407\_B65BA9F833D04C7086C8034C023CCBA0.o C:\Users\RUNNER~1\AppData\Local\Temp\.xmake\220407\_43FD57E494514C708E3879676CE133D0.cpp

This is the entire compiler call for Windows MSVC 2019 static x64 MT

markaren commented 2 years ago

I will update the windows CI and see if there are any issues with the new compilers. VS2016 is deprecated in GitHub Actions anyway.

markaren commented 2 years ago

I've updated the CI workflow and VS2019 should work fine. VS2022 wasn't happy with boost and pre-built binaries for conan don't seem to be available for that compiler yet. Updating boost and libzip led to issues with bzip and I rather not open that can of worms as it works fine for VS2016, VS2019, gcc 7 and 9. As long as conan works, I'm kinda satisfied.

ebw44 commented 2 years ago

I had a similar problem with vcpkg distribution of fmi4cpp. In my case it was related to the definition of min and max functions in windows. Adding add_definitions(-DNOMINMAX) in CMakeLists.txt or the following in the file(s) that includes fmi4cpp fixed the issue

#ifndef NOMINMAX
#define NOMINMAX
#endif
firefall123 commented 1 year ago

I have the same problem as you. How can I solve this problem?

markaren commented 1 year ago

Closing this one. The issue is related to external macros (min/max) and not fmi4cpp itself.