Using GCC to compile C code

不羁的心 提交于 2020-06-11 05:10:22

问题


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.


回答1:


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




回答2:


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!




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/24819206/using-gcc-to-compile-c-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!