'C++ - can't link with a main executable file for architecture

I was compiling my program using CLion on M1 chip mac, was working on a program for a week now. Suddenly, the program stopped compiling and I can't compile anything anywhere.. Last thing I did was to change the code in CLion to include MatrixXf instead of MatrixXd in Eigen and tried a template which then removed, but I'm sure it doesnt matter..

When I try to compile ANY code in Clion OR in terminal with gcc -o test main.cpp and then trying to run gcc test (I tried basic hello world) I get

ld: can't link with a main executable file 'test' for architecture arm64

clang error: linker command failed with exit code 1

If i run it with clang , I get same error just older architecture (x86) instead (clang somehow has target x_86 while g++ and gcc have arm).

I tried deleting and reinstalling all gcc and command line tools. I am not sure what settings have changed and where, I was compiling and running programs for weeks, and it suddenly broke.

Appreciate any help, I tried to search for this problem for ages



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source