在 cygwin 中运行 gcc

发布于 2024-09-04 04:58:25 字数 140 浏览 1 评论 0原文

我已经在我的系统上安装了Cygwin。但是当我尝试使用 gcc 命令时,它显示:

bash: gcc: command not find

谁能给我提供解决方案吗?

I have installed Cygwin on my system. But when I try to use the gcc command it says:

bash: gcc: command not found

Can anyone provide me the solution, please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

海夕 2024-09-11 04:58:25

在我的安装中也没有通用的 gcc 命令,所以我为它创建了一个符号链接:

cd /usr/bin
ln -s i686-pc-cygwin-gcc-3.4.4.exe gcc

现在通过执行 which gcc 来检查它是否有效,它应该给你 / usr/bin/gcc 然后 gcc 应该给你 gcc: no input files。请注意,您的 i686-pc-cygwin-gcc-3.4.4.exe 版本可能不同。检查 /usr/bin 中的内容。

In my installation there was no generic gcc command either, so I made a symlink for it:

cd /usr/bin
ln -s i686-pc-cygwin-gcc-3.4.4.exe gcc

Now check if it worked by doing which gcc which should give you /usr/bin/gcc and then gcc should give you gcc: no input files. Note that your version of i686-pc-cygwin-gcc-3.4.4.exe may be different. Check in /usr/bin for it.

在梵高的星空下 2024-09-11 04:58:25

也许在安装 Cygwin 时您没有选择 gcc、gdb 和 make 软件包。

我也遇到了同样的问题,选择上述软件包后就解决了。

Maybe during installation of Cygwin you have not selected gcc, gdb and make packages.

I had the same problem and it was resolved after I selected above-mentioned packages.

风铃鹿 2024-09-11 04:58:25

有几点:

  • 我总是安装整个 Cygwin 软件包。我相信,早期版本存在依赖关系问题,现在已修复,但这仍然是一个好习惯。您永远不知道什么时候可能需要 Cygwin 最深奥的部分。

  • 您可能必须改变您的路径。如果您在 Cygwin bash shell 中运行,通常可以找到所有工具,但在 cmd.exe 中则不一定如此。

它不太可能是最后一个,因为您的错误消息来自 bash 本身,所以我很确定这就是您运行它的方式。

检查一下,确保您在 bash 中拥有 /usr/bin/gcc,并且您的路径在某处包含 /usr/bin

pax> echo $PATH
/usr/local/bin:/usr/bin:/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS

pax> which gcc
/usr/bin/gcc

如果它不在那里,请返回并重新安装所有内容(如果您不需要所有内容,则重新安装相关的开发包)。如果它在那里并且您的路径没有其位置,请在 /etc/profile 或主目录中的等效目录中更改您的路径。

A couple of things:

  • I always install the whole Cygwin package. Earlier versions had troubles with dependencies that are fixed now, I believe, but it's still a good habit. You never know when you may need the most esoteric bit of Cygwin.

  • You may have to change your path. All the tools can generally be found okay if you're running inside the Cygwin bash shell but that's not necessarily the case from cmd.exe.

It's unlikely to be that last one since your error message is coming from bash itself, so I'm pretty certain that's how you're running it.

Have a look to make sure you have /usr/bin/gcc from within bash and that your path includes /usr/bin somewhere:

pax> echo $PATH
/usr/local/bin:/usr/bin:/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS

pax> which gcc
/usr/bin/gcc

If it's not there, go back and re-install everything (or the relevant development package if you don't want everything). If it is there and your path doesn't have its location, change your path, in either /etc/profile or the equivalent in your home directory.

南七夏 2024-09-11 04:58:25

此处未提及的另一个相关问题是,从命令行,编译器需要更新环境路径变量以查找 C++ 头文件的位置。在 Windows 中,您只需使用“高级系统属性”GUI 更新路径环境并添加 C++ 包含文件的位置。这将更新 Windows cmd 中的 PATH 环境变量Cygwin 在重新启动 shell 时自动运行。

要从 Linux 或 Cygwin shell 更新您的 PATH,请键入... PATH=$PATH:/your_path_here 示例:PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include /c++ 也最好只添加包含目录: PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/ ...或检查正确的目录作为安装包含文件的位置,我建议安装 mingw 以与 Cygwin 一起使用,Cygwin 是通过 g++ 调用的。

要在 Cygwin 中安装其他所需的软件包,请重新运行 Cygwin 安装实用程序 &检查从 Internet 安装以从 Web 存储库添加软件包并添加 mingw-gcc-g++ 和 mingw-gcc-g++。 mingw-binutils。编译代码: g++ hello.cpp -o hello

如果使用 gcc 实用程序,则使用以下命令进行编译: gcc hello.cpp -o hello -lstdc++ ... 以获得可执行文件。

只要您安装了 gcc 或 mingw,并且 c++ 包含文件的路径位于您的路径环境中,这些命令就可以工作。

Another related issue that wasn't mentioned here, is from the command line the compiler needs the environment path variable updated to find the location of the c++ header files. In windows you can just update the path environment using the 'advanced system properties' GUI and add the location of the c++ include files. This will update the PATH environment variable in Windows cmd & Cygwin automatically upon restarting the shell.

To update your PATH from Linux or the Cygwin shell type... PATH=$PATH:/your_path_here Example:PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/c++ Also a good idea to add just the include directory as well: PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/ ...or check the proper directories for the location of your installation's include files, I recommend installing mingw for use with Cygwin, which is envoked with g++.

To install additional needed packages in Cygwin re-run the Cygwin install utility & check install from Internet to add packages from web repositories and add mingw-gcc-g++ & mingw-binutils. To compile your code: g++ hello.cpp -o hello

If using the gcc utility instead compile with the command: gcc hello.cpp -o hello -lstdc++ ... to get your executable.

As long as you have either gcc or mingw installed and the path to the c++ include files is in your path environment, the commands will work.

再见回来 2024-09-11 04:58:25

还有一个难以发现的错误也可能导致此错误,

如果您的 Makefile 使用 PATH 作为变量,则可能会发生 gcc not found 错误。
这是因为它临时更改了系统路径。

我花了很多时间检查 cygwin 环境设置来发现这一点,所以我将其留在这里,以防万一这可以帮助任何人找到这里的方法。

There is another hard to spot mistake could also cause this error,

If your Makefile uses PATH as variable, the gcc not found error could happen.
This is because it changes the system path temporarily.

I took a lot of time checking the cygwin environment setting to discover this, so I'll leave it here in case this helps anyone finding their way here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文