Project compilation failed (error code: 2)

Description of problem

My cpp_standalone compilation capabilities broke. Not sure what I did to break it. Maybe it was the Windows11 update? I get the error RuntimeError: Project compilation failed (error code: 2), consider having a look at 'winmake.log'.

Brian2 version is 2.9.0

Python is 3.11.14

Minimal code to reproduce problem

import brian2 as b2
b2.set_device('cpp_standalone', build_on_run=False)
net = b2.Network()
tau = 10*b2.ms
G = b2.NeuronGroup(2, "dv/dt = (1-v)/tau : 1")
net.add(G)
net.run(1*b2.second)
b2.device.build(run=False, directory=None, clean=True)

The complete output:

INFO       No numerical integration method specified for group 'neurongroup', using method 'exact' (took 0.03s). [brian2.stateupdaters.base.method_choice]
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[1], line 8
      6 net.add(G)
      7 net.run(1*b2.second)
----> 8 b2.device.build(run=False, directory=None, clean=True)

File ~\miniforge3\envs\sbilab\Lib\site-packages\brian2\devices\cpp_standalone\device.py:1630, in CPPStandaloneDevice.build(self, directory, results_directory, compile, run, debug, clean, with_output, additional_source_files, run_args, direct_call, **kwds)
   1620 self.generate_makefile(
   1621     self.writer,
   1622     compiler,
   (...)   1626     debug=debug,
   1627 )
   1629 if compile:
-> 1630     self.compile_source(directory, compiler, debug, clean)
   1631     if run:
   1632         self.run(directory, results_directory, with_output, run_args)

File ~\miniforge3\envs\sbilab\Lib\site-packages\brian2\devices\cpp_standalone\device.py:1162, in CPPStandaloneDevice.compile_source(self, directory, compiler, debug, clean)
   1156             if not clean:
   1157                 error_message += (
   1158                     " Consider running with "
   1159                     '"clean=True" to force a complete '
   1160                     "rebuild."
   1161                 )
-> 1162             raise RuntimeError(error_message)
   1163 else:
   1164     with std_silent(debug):

RuntimeError: Project compilation failed (error code: 2), consider having a look at 'winmake.log'.

The winmake.log ends on

synapses_classes.cpp
NMAKE : fatal error U1073: don't know how to make 'sourcefiles.txt'
Stop.

I can provide the full winmake.txt if that helps.

What you have aready tried

I created a new environment but it did not help.

I checked my Visual Studio Build Tools. I have Visual Studio Build Tools 2022. I have installed:

  • C++ Build Tools core features
  • MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest)
  • Windows 10 SDK
  • Windows 11 SDK
  • C++ CMake tools for Windows
  • C++ core features
  • Windows Universal CRT SDK

And a bunch of other stuff that I think is irrelevant to Brian2.

Expected output (if relevant)

Actual output (if relevant)

Full traceback of error (if relevant)

Hi @danielmk, this is odd indeed! Could you please share the generated win_makefile and sourcefiles.txt?

Thanks for the quick reply @mstimberg

This is the win_makefile:

all: main.exe

clean:
    del *.obj /s
    del *.exe /s
    del sourcefiles.txt

code_objects\neurongroup_stateupdater_codeobject.obj: win_makefile
    cl /c /EHsc /I. -I"C:\Users\Daniel\miniforge3\envs\sbilab\Library\include" /Ox /w /arch:AVX2 /MP  code_objects/neurongroup_stateupdater_codeobject.cpp /Focode_objects\neurongroup_stateupdater_codeobject.obj 
    
main.obj: win_makefile
    cl /c /EHsc /I. -I"C:\Users\Daniel\miniforge3\envs\sbilab\Library\include" /Ox /w /arch:AVX2 /MP  main.cpp /Fomain.obj 
    
network.obj: win_makefile
    cl /c /EHsc /I. -I"C:\Users\Daniel\miniforge3\envs\sbilab\Library\include" /Ox /w /arch:AVX2 /MP  network.cpp /Fonetwork.obj 
    
objects.obj: win_makefile
    cl /c /EHsc /I. -I"C:\Users\Daniel\miniforge3\envs\sbilab\Library\include" /Ox /w /arch:AVX2 /MP  objects.cpp /Foobjects.obj 
    
run.obj: win_makefile
    cl /c /EHsc /I. -I"C:\Users\Daniel\miniforge3\envs\sbilab\Library\include" /Ox /w /arch:AVX2 /MP  run.cpp /Forun.obj 
    
synapses_classes.obj: win_makefile
    cl /c /EHsc /I. -I"C:\Users\Daniel\miniforge3\envs\sbilab\Library\include" /Ox /w /arch:AVX2 /MP  synapses_classes.cpp /Fosynapses_classes.obj 
    

main.exe: code_objects\neurongroup_stateupdater_codeobject.obj main.obj network.obj objects.obj run.obj synapses_classes.obj  win_makefile sourcefiles.txt
    link @sourcefiles.txt /LIBPATH:"C:\Users\Daniel\miniforge3\envs\sbilab\Library\lib" advapi32.lib /LIBPATH:. /OUT:main.exe 

I don’t know where sourcefiles.txt is. It’s not in brian_standalone_

Hmm, well this explains the error. There should be a sourcefiles.txt file in the same folder as the win_makefile. I think there is a bug when you use clean=True on Windows. From the makefile, it seems that clean deletes sourcefiles.txt which I think it shouldn’t. Could you try running it without clean=True?

Building the code with clean=True is meant to call something make clean && make instead of a simple make. But if make clean removes a file that is necessary for the following make, this is not going to work…