FMI4cpp icon indicating copy to clipboard operation
FMI4cpp copied to clipboard

Syntax errors on windows when compiling an application

Open PucklaJ opened this issue 3 years ago • 7 comments

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.

PucklaJ avatar Apr 07 '22 09:04 PucklaJ

Compiler version and language standard?

markaren avatar Apr 07 '22 10:04 markaren

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 avatar Apr 07 '22 10:04 PucklaJ

"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

PucklaJ avatar Apr 07 '22 10:04 PucklaJ

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 avatar Apr 07 '22 10:04 markaren

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.

markaren avatar Apr 11 '22 18:04 markaren

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

ebw44 avatar May 10 '22 01:05 ebw44

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

firefall123 avatar Aug 17 '22 03:08 firefall123

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

markaren avatar Apr 19 '23 06:04 markaren