Code builds for roboRio but not for Simulation

Hi,
I am from team 2135 and I am trying to run simulation on VSCode with wpilib-plugin v2022.1.1 on Windows, but it keeps failing to compile at 44% completion. I can buildthe code for the roboRio, but not for simulation. I have tried rebooting the laptop, removing the cache and build files, scanning for malware, and re-cloning the repos.

I am able to run simulation on the example project, but not on my competition code. I have also compared all of the WPILib Commands and Preferences files from our project to an example project for discrepancies. Here is our code for reference https://github.com/usfirst-frc-2135/robot2022/tree/main/Comp2022

The problem seems to lie in the .gradle file as all of the error messages look along the lines of this:

C:\Users\PHS_User\.gradle\caches\transforms-3\dbaef2bf8366466ac56a33ca3a8600e5\transformed\wpimath-cpp-2022.1.1-headers\units/pressure.h(44): error C2059: syntax error: ';'
C:\Users\PHS_User\.gradle\caches\transforms-3\dbaef2bf8366466ac56a33ca3a8600e5\transformed\wpimath-cpp-2022.1.1-headers\units/pressure.h(44): error C2923: 'fmt::v8::formatter': '__stdcall_t' is not a valid template type argument for parameter 'T'
C:\Users\PHS_User\.gradle\caches\transforms-3\dbaef2bf8366466ac56a33ca3a8600e5\transformed\wpimath-cpp-2022.1.1-headers\units/pressure.h(44): note: see declaration of '__stdcall_t'
C:\Users\PHS_User\.gradle\caches\transforms-3\dbaef2bf8366466ac56a33ca3a8600e5\transformed\wpimath-cpp-2022.1.1-headers\units/pressure.h(44): error C2976: 'fmt::v8::formatter': too few template arguments

My team has run simulation on both Windows and Mac, but only Windows (regardless of what version) seems to be experiencing this problem. If anyone else is experiencing this and is willing to offer insight, help would be much appreciated!

Do you have the full error message handy? That will give us which of your files is including that and failing.

If I had to guess, I imagine its because youre using spdlog, which includes its own copy of fmt. For 2022, wpilib also includes fmt. It looks like you can force spdlog to use an external format by commenting out line 74 of tweakme.h, or defining SPDLOG_FMT_EXTERNAL. That should force use of our fmt, which might fix the issues.

WPILib 2021.1.1 ships with fmt 8.0.1, fyi. A future release will ship with fmt 8.1.1.

Here is the full error message: See file:///C:/Users/amull/Documents/github2/robot2022/Comp2022/build/tmp/compil - Pastebin.com

There’s a couple different issues here. But here’s the patch to get it to work in simulation.

fixes.diff.txt (1.8 KB)

What this patch does:

  • Defines SPDLOG_COMPILED_LIB for your robot code as well (this is what was causing the error messages, because without this defined, spdlog pulls in windows.h, which breaks all kinds of things). I really really dislike spdlog’s defaults here, because windows.h is very breaking.
  • Defines SPDLOG_FMT_EXTERNAL for both the spdlog library and your robot code (otherwise you get duplicate symbols on link as its embedded ones conflict with ours)
  • Compiles the spdlog library with wpilib as a dependency, so it picks up our fmt headers
  • Adds a pragma to pull in the winsock library (otherwise you get an unresolved symbol)

Thank you, the patch fixed the simulation build but we are still seeing an error in the Google Test Task file in C:\Users\amull\Documents\github2\robot2022\Comp2022\build\tmp\compileFrcUserProgramTestWindowsx86-64ReleaseGoogleTestExeFrcUserProgramCpp. We were able to disable the test task, so the issue is non-critical. Here is the error:

Thank you!

Nevermind, we figured it out. We had to add the SPDLOG lines to our test task as well as the robot task:

binaries.all {

            cppCompiler.define 'SPDLOG_COMPILED_LIB'

            cppCompiler.define 'SPDLOG_FMT_EXTERNAL'

        }