Error when using gcc (minGW) to build .exe with same filename? - c

I've been trying to build another .exe file with the same name in minGW, but everytime I run the command: gcc file.c -o file.exe I run into the problem of:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe:
cannot open output file main.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
But, if I run the same command with gcc file.c -o file2.exe the command executes fine, and I can compile my C code. Is there any way to build .exe files with the same name?
My C code is a simple "hello world":
#include<stdio.h>
void main(){
printf("hello world");
}
Thank you!
Updates:
checked task manager, but the .exe is not running in the background.
I have writing permission to the folder
My antivirus doesn't seem to be the problem
I can edit and delete the file.exe "by hand". I used command line to rename it to file1.exe, but when I tried to rename it back to file.exe I got an "access denied". Even though I am running command line as an admin.
file.exe is just a generic name to ask this question instead of giving the
name of my project

Looking at this question: Command prompt access is denied
I saw a comment that helped:
Noting C:> in your question, your Windows root drive is usually write protected, you may find that simply changing directory to somewhere without that protection may also help. – Compo
And indeed, having my file in the root drive was the problem. Sorry I didn't provide enough information for those who helped. But thank you so much for the help!

Related

Notepad++, NppExec, CreateProcess() failed with error code 2, Windows 10

Hi I'm new to C Programming and Notepad++. I can't seem to find the solution to this problem when I was configuring C compiler for Windows 10.
NPP_SAVE: C:\Program Files\Notepad++\change.log
CD: C:\Program Files\Notepad++
Current directory: C:\Program Files\Notepad++
gcc -o "change.exe" "C:\Program Files\Notepad++\change.log"
Process started (PID=16420) >>>
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot open output file change.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
<<< Process finished (PID=16420). (Exit code 1)
"change.exe"
; about to start a child process: ""change.exe""
CreateProcess() failed with error code 2:
The system cannot find the file specified.
================ READY ================
The NppExec script I have taken from https://www.youtube.com/watch?v=_dGyVkPkBRI&t=88s
npp_save
cd "$(CURRENT_DIRECTORY)"
gcc-o "$(NAME_PART).exe" "$(FULL_CURRENT_PATH)"
"$(NAME_PART).exe"
Please help advice, thank you.
I'm afraid this cannot work. As far as I see, you are trying to compile the file change.log, which is almost certainly not a C module (or anything else gcc might understand.
Please re-check the FULL_CURRENT_PATH variable in the script you posted. I think there is a misunderstanding in the youtube clip (which I didn't watch), or in the way you tried to reproduce it.
Additionally, such scripts are not an ideal solution to automate the program build and execution any more. You should check out better alternatives such as an IDE (Eclipse, Netbeans, Visual Studio or whatever you prefer...), or learn to write yourself a Makefile (check out the GNU Make tool), which is much more powerful than a cmd script.
PS: Notepad++ is a nice editor, but it isn't an IDE. As soon as you are programming software that consists of several modules and/or header files, you want to surf through these efficiently in order to avoid mistakes.

lld-link.exe: error: failed to open a.exe: permission denied on windows 10

i'm using lld-link to create a .exe file from a obj file but this happen:
I already searched for this error, the common answer was that a.exe was executed and that I have to close it , but I already search for it in the process explorer and there is no a.exe running. I also read that my anti-malware could be the problem so I turned it off but that didn't work as well.
You're trying to write a.exe into C:\Program Files\LLVM\bin. Either cd to your code directory before linking, or specify an absolute path for a.exe to be saved to in the -out:a.exe part of the command.

(Kali & Ettercap) Plugin compilation error

Okay I'm having a particular issue during compilation using the command gcc -shared -o attack_test.so -fPIC attack_test.c. Specifically, when I run the command, I get the error fatal error: ec.h: No such file or directory. Any idea how to fix this issue? Thanks.
EDIT: To give a little more issue background, I'm running this command from the desktop, where my C source code is located. Perhaps there's a specific place I need to put the source and run the command?
EDIT 2: So I was able to get past the above error by running the command sudo apt-get install libssl-dev, and then changing the line #include <ec.h> to #include <openssl/ec.h>, which seemed to negate the issue. Adding the <openssl/...> to the other includes did not work the same way. So now, instead of fatal error: ec.h: No such file or directory, it's fatal error: ec_plugins.h: No such file or directory. Any ideas for possible fixes? Thanks so much!
For reference, I'm building upon the the dos_attack.c source code from this link.
TO BE CLEAR: This is for a project and tested upon in a CLOSED ENVIRONMENT. This is COMPLETELY* for EDUCATIONAL use and for the study of Denial-of-Service and Man-In-the-Middle mitigation techniques.
<ec.h> is intended to refer to a file in the Ettercap include directory, not an OpenSSL header. The same goes for the other ec_*.h headers.
Adding -I/path/to/ettercap/include to your compiler flags should fix this.

No longer have permission to compile via gcc after upgrading to Windows 10

The other day I downloaded cygwin and gcc in order to learn C on my Windows 7 machine. I made a couple "Hello World!"-style programs, compiled them, etc., everything was fine. Today I upgraded to Windows 10, and now when I try to compile, I get this error message:
$ make [FILENAME]
cc -Wall -g [FILENAME].c -o [FILENAME]
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot open output file [FILENAME].exe: Permission denied
collect2: error: ld returned 1 exit status
make: *** [<builtin>: [FILENAME]] Error 1
I've searched through a few other threads discussing this error, but have found nothing that solves my problem. Many suggestions were things I had no idea how even to do! For example, one person said in a similar thread, "Move to a directory where you are allowed to write." I don't know how to find a directory where I'm allowed to write, or if that's even my problem. One suggestion I found that seemed promising was to go to a parent directory and run "chmod a+w [DIRECTORY NAME]". I did that, and got this error:
$ chmod a+w [DIRECTORY NAME]
chmod: changing permissions of '[DIRECTORY NAME]': Permission denied
And I can't go any higher in that using "CD ../" so it looks like I've got permission denial all over the shop.
The cygwin directory itself is C:\cygwin-64\, if that matters.
Thanks for any help you can give me!
I haven't used cygwin in years (and have never used Win10), but I will give it a shot.
What you are asking for help is complicated by multiple issues. One of them is you do not know what permissions are. Another one is Windows 10 may have reset your permissions.
Operating systems have permission models that can restrict what actions a user can do or what files a user can access. On Windows, i'm betting that UAC (that annoying dialog asking for permission) may be blocking chmod from working. (I'm assuming your account is a superuser.) The error before that looks like the folder permission does not allow 'write' access for the compiler to 'open', create a file.
The easiest way to solve this would be to uninstall and reinstall cygwin. The install script should set the proper permissions.
Kudos to you for using gcc on the command line to compile a C program. You may want to consider using Eclipse or NetBeans to help you learn C programming in the future. They have user friendly debuggers that will help you track the state of your program and fix errors.
http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/neonr
https://netbeans.org/features/cpp/index.html

cannot open output file helloWorld.exe: Permission denied

When I try to compile helloWorld.c with gcc (by MinGW) via notepad++'s run feature I get the error:
cannot open output file helloWorld.exe: Permission denied
The problem only occurs when I run the compiler via notepad++'s run feature, so I get no errors when I just compile it manually via cmd.
As some others have answered on similar questions, I have tried looking in process explorer and helloWorld.exe is not running.
.
Additional details about how I run it in notepad++
I use a batch script compile.bat
gcc -o %1 %2
%1
PAUSE
and run it in notepad++ with the command
"...\compile.bat" $(NAME_PART) $(FILE_NAME)
What could be causing this error? Help would be deeply appreciated.
EDIT: Turns out it was a problem with notepad++ that it didn't display that it was working in it's own directory. Also what caused a problem when I had tried to put the directory in the batch file was that it couldn't handle scandinavian letters.
I suspect that notepad is trying to create the output file in it's own directory (ie somewhere in c:\program files\notepad++" that you don't have write permission to.
Is there a "working directory" setting in notepad++'s run command?

Resources