Building under Windows using MSVC
- Dominant language
- C++
- Stars
- 955
- Forks
- 207
- Avg merge
- 10h 4m
- Merged PRs (30d)
- 4
Description
## tl;dr
There are some gcc specific copts in the BUILD files. If I remove them I get errors like `error C2491: 'antlr4::dfa::Vocabulary::EMPTY_VOCABULARY': definition of dllimport static data member not allowed` and the build fails.
Is building this project under Windows using MSVC supported. Does anyone have any pointers how to make it work?
## Full example
If I try to build e.g. the r4 json_format C++ library using `bazel build //cc/google/fhir/r4:json_format` I get the following errors
```bazel
PS C:\git\fhir> bazel build //cc/google/fhir/r4:json_format
INFO: Analyzed target //cc/google/fhir/r4:json_format (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: C:/users/mathias.kogler/_bazel_mathias.kogler/ee5vwmtg/external/antlr_cc_runtime/BUILD.bazel:3:11: Compiling atn/LL1Analyzer.cpp failed: (Exit 2): cl.exe failed: error executing command C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.31.31103\bin\HostX64\x64\cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE ... (remaining 40 arguments skipped)
cl : Command line error D8021 : invalid numeric argument '/Wno-implicit-fallthrough'
Target //cc/google/fhir/r4:json_format failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.672s, Critical Path: 0.19s
INFO: 13 processes: 13 internal.
FAILED: Build did NOT complete successfully
```
If I remove the `-Wno-implicit-falltrough` from the `copts` in bazel/antlr.BUILD and change the `-cxxopt` in `.bazelrc` from `build --cxxopt=-std=c++17` to the msvc format `build --cxxopt=/std:c++17` I get the following errors
```bazel
PS C:\git\fhir> bazel build //cc/google/fhir/r4:json_format
INFO: Build option --cxxopt has changed, discarding analysis cache.
INFO: Analyzed target //cc/google/fhir/r4:json_format (0 packages loaded, 3011 targets configured).
INFO: Found 1 target...
ERROR: C:/users/mathias.kogler/_bazel_mathias.kogler/ee5vwmtg/external/antlr_cc_runtime/BUILD.bazel:3:11: Compiling Vocabulary.cpp failed: (Exit 2): cl.exe failed: error executing command C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.31.31103\bin\HostX64\x64\cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE ... (remaining 39 arguments skipped)
cl : Command line warning D9002 : ignoring unknown option '-fexceptions'
external/antlr_cc_runtime/Vocabulary.cpp(12): warning C4273: 'EMPTY_VOCABULARY': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\Vocabulary.h(27): note: see previous definition of 'public: static antlr4::dfa::Vocabulary const antlr4::dfa::Vocabulary::EMPTY_VOCABULARY'
external/antlr_cc_runtime/Vocabulary.cpp(12): error C2491: 'antlr4::dfa::Vocabulary::EMPTY_VOCABULARY': definition of dllimport static data member not allowed
external/antlr_cc_runtime/Vocabulary.cpp(14): warning C4273: 'antlr4::dfa::Vocabulary::Vocabulary': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\Vocabulary.h(42): note: see previous definition of '{ctor}'
external/antlr_cc_runtime/Vocabulary.cpp(18): warning C4273: 'antlr4::dfa::Vocabulary::Vocabulary': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\Vocabulary.h(60): note: see previous definition of '{ctor}'
external/antlr_cc_runtime/Vocabulary.cpp(25): warning C4273: 'antlr4::dfa::Vocabulary::~Vocabulary': inconsistent
dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\Vocabulary.h(18): note: see previous definition of '{dtor}'
external/antlr_cc_runtime/Vocabulary.cpp(28): warning C4273: 'antlr4::dfa::Vocabulary::fromTokenNames': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\Vocabulary.h(76): note: see previous definition of 'fromTokenNames'
external/antlr_cc_runtime/Vocabulary.cpp(61): warning C4273: 'antlr4::dfa::Vocabulary::getMaxTokenType': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\Vocabulary.h(82): note: see previous definition of 'getMaxTokenType'
external/antlr_cc_runtime/Vocabulary.cpp(65): warning C4273: 'antlr4::dfa::Vocabulary::getLiteralName': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\Vocabulary.h(119): note: see previous definition of 'getLiteralName'
external/antlr_cc_runtime/Vocabulary.cpp(73): warning C4273: 'antlr4::dfa::Vocabulary::getSymbolicName': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\Vocabulary.h(163): note: see previous definition of 'getSymbolicName'
external/antlr_cc_runtime/Vocabulary.cpp(85): warning C4273: 'antlr4::dfa::Vocabulary::getDisplayName': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\Vocabulary.h(184): note: see previous definition of 'getDisplayName'
ERROR: C:/users/mathias.kogler/_bazel_mathias.kogler/ee5vwmtg/external/antlr_cc_runtime/BUILD.bazel:3:11: Compiling atn/ATNDeserializationOptions.cpp failed: (Exit 2): cl.exe failed: error executing command C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.31.31103\bin\HostX64\x64\cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE ... (remaining 39 arguments skipped)
cl : Command line warning D9002 : ignoring unknown option '-fexceptions'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(10): warning C4273: 'defaultOptions': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(15): note: see previous definition of 'private: static antlr4::atn::ATNDeserializationOptions antlr4::atn::ATNDeserializationOptions::defaultOptions'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(10): error C2491: 'antlr4::atn::ATNDeserializationOptions::defaultOptions': definition of dllimport static data member not allowed
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(12): warning C4273: 'antlr4::atn::ATNDeserializationOptions::ATNDeserializationOptions': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(22): note: see previous definition of '{ctor}'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(16): warning C4273: 'antlr4::atn::ATNDeserializationOptions::ATNDeserializationOptions': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(23): note: see previous definition of '{ctor}'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(21): warning C4273: 'antlr4::atn::ATNDeserializationOptions::~ATNDeserializationOptions': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(25): note: see previous definition of '{dtor}'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(24): warning C4273: 'antlr4::atn::ATNDeserializationOptions::getDefaultOptions': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(28): note: see previous definition of 'getDefaultOptions'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(28): warning C4273: 'antlr4::atn::ATNDeserializationOptions::isReadOnly': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(30): note: see previous definition of 'isReadOnly'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(32): warning C4273: 'antlr4::atn::ATNDeserializationOptions::makeReadOnly': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(32): note: see previous definition of 'makeReadOnly'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(36): warning C4273: 'antlr4::atn::ATNDeserializationOptions::isVerifyATN': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(34): note: see previous definition of 'isVerifyATN'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(40): warning C4273: 'antlr4::atn::ATNDeserializationOptions::setVerifyATN': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(36): note: see previous definition of 'setVerifyATN'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(45): warning C4273: 'antlr4::atn::ATNDeserializationOptions::isGenerateRuleBypassTransitions': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(38): note: see previous definition of 'isGenerateRuleBypassTransitions'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(49): warning C4273: 'antlr4::atn::ATNDeserializationOptions::setGenerateRuleBypassTransitions': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(40): note: see previous definition of 'setGenerateRuleBypassTransitions'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(54): warning C4273: 'antlr4::atn::ATNDeserializationOptions::throwIfReadOnly': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(43): note: see previous definition of 'throwIfReadOnly'
external/antlr_cc_runtime/atn/ATNDeserializationOptions.cpp(60): warning C4273: 'antlr4::atn::ATNDeserializationOptions::InitializeInstanceFields': inconsistent dll linkage
C:\users\mathias.kogler\_bazel_mathias.kogler\ee5vwmtg\execroot\com_google_fhir\external\antlr_cc_runtime\atn/ATNDeserializationOptions.h(46): note: see previous definition of 'InitializeInstanceFields'
Target //cc/google/fhir/r4:json_format failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 3.173s, Critical Path: 2.43s
INFO: 15 processes: 11 internal, 4 local.
FAILED: Build did NOT complete successfully
```
Contributor guide
Assessment
This issue has not been assessed yet.