"error X3501: 'main': entrypoint not found" while compiling HLSL in visual studio
I compile HLSL doing this: hr = D3DX11CompileFromFile("triSH.fx", 0, 0, "VS", "vs_4_0", 0, 0, 0, &VS_Buffer, 0, 0); hr = D3DX11CompileFromFile("triSH.fx", 0, 0, "PS", "ps_4_0", 0, 0, 0, &PS_Buffer, 0, 0); with the shader code like this: struct VS_OUTPUT { float4 Pos : SV_POSITION; float4 Color : COLOR; }; VS_OUTPUT VS(float4 inPos : POSITION, float4 inColor : COLOR) { VS_OUTPUT output; output.Pos = inPos; output.Color = inColor; return output; } float4 PS(VS_OUTPUT input) : SV_TARGET { return input.Color; } the compiler says this: "error X3501: 'main': entrypoint not found"
Sign in to comment
Chosen Answer
The reason is probably because visual studio is trying to compile the shader file with fxc.exe. what you need to do is go to solution explorer, find your fx file, right click on it and go to properties. the properties window will open up for that file. under "Configuration Properties->General" there is an option "Excluded From Build". Select "Yes" for that option and click ok. then try to compile your code again
I don't think it's the case, cuz i checked mine, it works perfectly without going into options.
Problem is just that system can't find at which function program needs to start, there's nothing wrong with HSLS code.
on Nov 26 `15
IamU4
He could instead replace the function name "VS" with main and it should compile, and in the line that he compiles the shader file use "main" instead of VS. but when you compile with fxc.exe, which is what visual studio uses to compile hlsl shaders, it needs a main function. This will happen if he adds a new item in solution explorer and chooses hlsl as the type of file. visual studio will try to compile it. if you just add an item by choosing either existing item or some other file type that does not get compiled, then it will work as expected
on Nov 26 `15
iedoc
There are of course more than one ways to fix the problem, but the problem is because the hlsl compiler is looking for the main function in his shader file. D3DX11CompileFromFile lets you tell it which function you need, while fxc.exe needs a main function. You probably didn't add the file in the solution explorer by going to add new item and choosing hlsl file, which i'm guessing is what he has done
on Nov 26 `15
iedoc
while i'm at it, you can also just change the entry point name in the properties for the shader file to whatever function you have in your shader file, which would be "VS" in the OP's question.
on Nov 26 `15
iedoc
--EDIT-- Go to project properties->Configuration Properties->Linker->Advanced and find the entry point. Right here is a problem. The system checks if there is any functions that's called main(), if not, it just breaks. I'm not sure, but i think i know how to fix it. Press on Entry Point and press a little arrow on right and then edit. Remove all text from window that has open and thats it. Why does it work? If there is nothing in EntryPoint, i think system would go thro all possible Entry Points, and finds one that has been used, in our case WinMain(...). For real tho, let me know if that works, if not, leave a comment on my post, and if I'm not fast enough to reply, check on google, maybe there's a solution. Don't worry, it happens all the time then installing Visual Studio. Peace! Happy programming!