C++ 尝试从命令行使用 g++ 进行编译时出现“访问被拒绝”。赛格温

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5033463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 17:13:48  来源:igfitidea点击:

Get "Access is denied" when trying to compile with g++ from command line. Cygwin

c++gccg++cygwin

提问by sighol

I have installed all packages in cygwin. I have also added C:\cygwin\bin to my PATH variable. But when I try to compile a c++ file in command line I get the error 'Access is denied'. The same commands work in the cygwin batch window. Does anyone know what's wrong?

我已经在 cygwin 中安装了所有软件包。我还将 C:\cygwin\bin 添加到我的 PATH 变量中。但是当我尝试在命令行中编译 C++ 文件时,我收到错误“访问被拒绝”。相同的命令在 cygwin 批处理窗口中起作用。有谁知道出了什么问题?

Edit:I changed the permissions for gcc and g++. I no longer get the 'Access Denied' error, but get a new one: "This version of C:\cygwin\bin\g++.exe is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.".

编辑:我更改了 gcc 和 g++ 的权限。我不再收到“拒绝访问”错误,而是收到一个新错误:“此版本的 C:\cygwin\bin\g++.exe 与您运行的 Windows 版本不兼容。请检查您计算机的系统信息以查看您是否需要 x86(32 位)或 x64(64 位)版本的程序,然后联系软件发行商。”。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Ben Voigt

Because c:\cygwin\bin\gcc.exeisn't an executable file, it's a cygwin symbolic link.

因为c:\cygwin\bin\gcc.exe它不是一个可执行文件,它是一个 cygwin 符号链接。

$ file /bin/gcc
/bin/gcc: symbolic link to `/etc/alternatives/gcc'
$ file /etc/alternatives/gcc
/etc/alternatives/gcc: symbolic link to `/usr/bin/gcc-4.exe'

The underlying file runs just fine.

底层文件运行得很好。

C:\cygwin\home\Ben>gcc-4 --version
gcc-4 (GCC) 4.5.0
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

回答by heftyfunseeker

I just deleted gcc and g++ and renamed the g++/cc-4.

我刚刚删除了 gcc 和 g++ 并重命名了 g++/cc-4。

回答by David Harris

Unless you're a masochist, always use a Cygwin batch window with Cygwin executables. Also if you're using the Cygwin compiled gcc, you'll need the Cygwin DLL to run the results. The Cygwin websiteexplains why. If you need executables without the Cygwin dll, I'd explore MinGW.

除非您是受虐狂,否则请始终使用带有 Cygwin 可执行文件的 Cygwin 批处理窗口。此外,如果您使用的是 Cygwin 编译的 gcc,您将需要 Cygwin DLL 来运行结果。在Cygwin的网站解释了为什么。如果您需要没有 Cygwin dll 的可执行文件,我会探索MinGW

回答by Felipe Rojo Amadeo

I got the same issue and was because I had pending the reboot after Cygwin installation. After the reboot works for me.

我遇到了同样的问题,因为我在 Cygwin 安装后等待重新启动。重新启动后对我有用。