Using GCC to compile C code

2020-07-17 06:23发布

I installed MinGW on my Windows 8 laptop and tried to compile a C code file with

gcc test.c -o test.exe

the compiler gave no warnings or errors but it did not create test.exe

how do i get the compiler to create the file

test.c

test.c

My terminal session this is what i tried on terminal

An interesting observation:

When I deliberately introduce an error in the code and try to compile the compiler shows the error

Code with error enter image description here Compiler output enter image description here

When I try compiling the same code using Command Prompt

This is what it shows enter image description here

But the file does exist in the MinGW\bin directory enter image description here

I moved the

test.c

file to

C:\

and started the command prompt in the

C:\MinGW\bin

directory

and here is what it outputs enter image description here

Problem partially solved:

I disabled hybrid boot in windows 8 and restarted the computer. The compiler now works in Command Prompt but not in PowerShell.

4条回答
Bombasti
2楼-- · 2020-07-17 06:58

One possibility is Microsoft's use of VirtualStore.

This can cause problems with "missing" files with Cygwin. See for example, Cygwin sees a file that windows can't--I want to access this file from python and https://superuser.com/questions/400600/file-only-visible-to-cygwin-not-windows.

To verify whether this is the case, try doing a search of your entire hard drive for the file test.exe. Or try MinGW's ls rather than dir.

And since the OP "partially solved" the problem by moving to another directory, this could be the cause.

查看更多
Juvenile、少年°
3楼-- · 2020-07-17 07:03

I would suggest you go through this compilation instruction :-

gcc -o test.exe test.c

I believe this code runs perfectly on your windows system.Please inform if it doesn't!

查看更多
太酷不给撩
4楼-- · 2020-07-17 07:12

Try to compile your code normally as

gcc test.c

If you get default output file a.exe,then go for

gcc test.c -o test.exe

查看更多
疯言疯语
5楼-- · 2020-07-17 07:17

I know this is an old question, but I came across this after having this same issue and managed to solve it.

When I installed MinGW on my computer, I didn't add the MinGW bin directory to my PATH (<mingw install dir>\bin). I had written some code that referred to the GNU compiler binaries by their full path, and when I tried to compile something I experienced the same behavior you described.

So it seems like MinGW won't work properly unless it is added to your PATH. I think it's weird that gcc didn't complain about it though.

查看更多
登录 后发表回答