# Project compilation failed (error code: 2)

**URL:** <https://brian.discourse.group/t/project-compilation-failed-error-code-2/1507>\
**Category:** Support\
**Created:** [13 November 2025 03:27 UTC](https://brian.discourse.group/t/project-compilation-failed-error-code-2/1507 "2025-11-13T03:27:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielmk](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/danielmk/32/661_2.png) [@danielmk](https://brian.discourse.group/u/danielmk)\
**Post date:** [13 November 2025 03:27 UTC](https://brian.discourse.group/t/project-compilation-failed-error-code-2/1507/1 "2025-11-13T03:27:12Z")

</div>

# 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

```python
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:

```auto
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

```auto
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)

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [13 November 2025 08:53 UTC](https://brian.discourse.group/t/project-compilation-failed-error-code-2/1507/2 "2025-11-13T08:53:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danielmk](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/danielmk/32/661_2.png) [@danielmk](https://brian.discourse.group/u/danielmk)\
**Post date:** [14 November 2025 02:18 UTC](https://brian.discourse.group/t/project-compilation-failed-error-code-2/1507/3 "2025-11-14T02:18:31Z")

</div>

Thanks for the quick reply @mstimberg

This is the win\_makefile:

```auto
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_`

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [14 November 2025 14:34 UTC](https://brian.discourse.group/t/project-compilation-failed-error-code-2/1507/4 "2025-11-14T14:34:49Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![danielmk](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/danielmk/32/661_2.png) [@danielmk](https://brian.discourse.group/u/danielmk)\
**Post date:** [16 November 2025 02:57 UTC](https://brian.discourse.group/t/project-compilation-failed-error-code-2/1507/5 "2025-11-16T02:57:14Z")

</div>

Without `clean=True` the minimal code and my actual simulator work now.

I actually only added `clean=True` because I got a RuntimeError almost identical to the one I described above, but it told me to add `clean=True` because that might resolve the issue. So I added it, but it did not resolved the issue. Then I setup a completely new environment. I guess that solved the issue I originally had, but `clean=True` introduced a different issue.

Anyway, my simulator works again on Windows, but I guess I discovered a bug with `clean=True`
