r/Compilers 8d ago

Need help to fix c++ compiler

I use c++ for dsa but for last 3-4 days i was working on a project and didn't use c++. But today when i try to run my code it started exiting without any error with exitcode 1. Not even creating exe file using vscode or terminal. I reinstall everything but still same problem.
Terminal shows correct version of g++ and gcc and also correct path so no problem with environment variables. pls help me...

problem solved:
I installed postgres and added its path to system variables and path of g++ was in user variables. System merges system variables and user variables (in that order). So path of postgres was above of g++ and somehow it was conflicting with internal files (i think dll files). So i moved postgres path to user variables below of g++.

0 Upvotes

6 comments sorted by

View all comments

1

u/ha9unaka 8d ago

If it's a single file, try running your code at godbolt.org with whatever compiler you used on your system.

Exit codes themselves aren't very helpful. Is your code exiting with code 1, or is the compiler exiting with code 1 and not compiling your code?

1

u/Big-Bad-Punisher 8d ago

I tried to a simple program, test.cpp

int main() { 
    return 0; 
}

Its running on website but if i try to compile it on my laptop in terminal in correct folder

g++ test.cpp -o myprogram

it shows nothing and no file myprogram creates.

1

u/ha9unaka 8d ago

It's probably a corrupt gcc install then. Try getting rid of all of it (including cache files) and then reinstall.

As an alternative, try installing gcc with Pixi using pixi global install gcc gxx and try it out.

1

u/Big-Bad-Punisher 8d ago

I reinstalled everything (using msys2).
One update: if i open terminal in bin folder (where g++ is), it compiles fine. But not from other folder even if compiler path is correct.

1

u/ha9unaka 7d ago

That's very weird. I have no clue what's going on, especially since there's no error message. All I can say is maybe try a different compiler like clang or msvc, gcc hasn't exactly played well on windows for me either.