Realuther
Realuther

Reputation: 63

How can I fix "CL.exe" exited with code 2

I have been following learnopengl.com and I was on the Transformations part of the website and it keeps saying

CL.exe" exited with code 2

This is making impossible to test anything because it will not build.

I have tried many things, I have tried copying all the code from the tutorial and then tried running it but it still was giving the same error. I Have tried restarting visual studio in case it was an intellisense error but still no success.

It says the code that's causing the issue is part of Microsoft.CppCommon.targets on line 429 and it doesn't give much more info than that but here's the line that's giving the error

<CL Condition="'%(ClCompile.PrecompiledHeader)' != 'Create' and '%(ClCompile.ExcludedFromBuild)'!='true' and '%(ClCompile.CompilerIteration)' == '' and @(ClCompile) != ''"

and here is some of the code that is underneath it

BuildingInIDE                      ="$(BuildingInsideVisualStudio)"
Sources                            ="@(ClCompile)"

but it's not telling me what's causing the error so I don't know what the problem is.

it should just compile and run completely fine but it keeps giving the same error over and over again.

Upvotes: 1

Views: 5050

Answers (1)

user2534096
user2534096

Reputation:

I have observed clear case of this. It was due to function with bool return type but function lacked return statement.

Example:

bool DontForgetToReturnBool()
{
    // Everything except return statement
    ...
    ...
    ...
}

These errors can be frustrating because the compiler is supposed to inform us of the error, however, it's usually something simple, so just comment out recent code changes and re-compile until you find it.

Upvotes: 3

Related Questions