使用Cygwin编译C程序; 执行错误

发布于 2024-07-24 20:06:40 字数 711 浏览 0 评论 0原文

我正在攻读计算机科学硕士课程。 课程使用C语言,如果我们使用Windows,老师希望我们使用Cygwin来编译程序。

我已下载并安装了 Cygwin 并且我已确保已安装 GCC 编译器

但我不知道从这里该去哪里。 我需要编译一个具有基本包含的单个源文件。

#include <stdio.h> 

让我们假设该文件位于我的桌面上(实际上不是,但为了争论)。 如何从 bash shell 导航到桌面? 我假设一旦我导航到 bash 中的正确位置,我只需执行:

gcc myProgram.c -o myProgram

更新:按照下面发布的不同说明,我能够编译该程序; 我为此感谢你。 但是当我执行生成的二进制文件时,我得到以下结果。 如何编译或执行该程序才不会出现错误? 再次谢谢你。

此应用程序无法启动,因为找不到 cygwin1.dll。 重新安装应用程序可能会解决此问题。

I'm enrolled in a masters computer science course. The course is using C and the instructor wants us to use Cygwin to compile programs if we are using windows.

I've downloaded and installed Cygwin and I've ensured that I've installed the GCC compiler.

But I don't know where to go from here. I need to compile a single source file that has a basic include.

#include <stdio.h> 

Lets assume the file is on my desktop (it is not, but for the sake of argument). How do I navigate to the desktop from the bash shell? I assume once I've navigated to the correct location in bash, I simply execute:

gcc myProgram.c -o myProgram

Update: Following different instructions posted below, I was able to compile the program; I thank you for that. But when I execute the resulting binary I get the following. How can I compile or execute this program so I don't get the error? Again, thank you.

This application has failed to start because cygwin1.dll was not found. Re-installing the application may fix this problem.

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

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

发布评论

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

评论(12

℡寂寞咖啡 2024-07-31 20:06:41

此文件(cygwin1.dll)是类似于 qt 依赖项的 cygwin 依赖项。您必须将此文件和此类消息错误中出现的类似文件从“cygwin/bin”复制到您的程序的文件夹中。这也是运行所必需的另一台没有 cygwin 的计算机!

This file (cygwin1.dll) is cygwin dependency similar to qt dependency.you must copy this file and similar files that appear in such messages error, from "cygwin/bin" to folder of the your program .Also this is necessary to run in another computer that have NOT cygwin!

酸甜透明夹心 2024-07-31 20:06:40

当您在 cygwin 中启动时,您位于 $HOME 中,就像在 UNIX 中一样,默认情况下它映射到 c:/cygwin/home/$YOURNAME。 所以你可以把所有东西都放在那里。

您还可以通过 /cygdrive/c/ 从 cygwin 访问 c: 驱动器(例如 /cygdrive/c/Documents anb Settings/yourname/Desktop)。

when you start in cygwin, you are in your $HOME, like in unix generally, which maps to c:/cygwin/home/$YOURNAME by default. So you could put everything there.

You can also access the c: drive from cygwin through /cygdrive/c/ (e.g. /cygdrive/c/Documents anb Settings/yourname/Desktop).

孤者何惧 2024-07-31 20:06:40

关于您关于缺少 cygwin1.dll 的更新问题。

从 Cygwin 终端检查,

ls /usr/bin/cygwin1.dll

如果它不存在(我对此表示怀疑),则您的安装未正确完成。

然后,检查您的路径,

echo $PATH

这将给出 : 分隔的路径列表。 它必须包含 /usr/bin。 如果您发现缺少添加它,

export PATH=/usr/bin:$PATH

最后,

  • 我希望您从 cygwin 终端(随 Cygwin 安装的绿色+黑色小图标)或 MinTTY(如果您安装了它)使用 Cygwin。
  • 并且,您还没有将已编译的 EXE 移动到未安装 Cygwin 的其他计算机(如果这样做,您将需要将 cygwin1.dll 移动到该计算机 - 将其与已编译的 EXE 保存在同一文件夹中) 。

Regarding your updated question about the missing cygwin1.dll.

From the Cygwin terminal check,

ls /usr/bin/cygwin1.dll

If it is not present (I doubt that), your installation is not properly done.

Then, check your path with,

echo $PATH

This will give : separated list of paths. It MUST contain /usr/bin. If you find that missing add it with,

export PATH=/usr/bin:$PATH

Finally,

  • I hope you are using Cygwin from the cygwin terminal (the little green+black icon installed with Cygwin), or MinTTY (if you installed that).
  • And, you have not moved the compiled EXE to a different machine which does not have Cygwin installed (if you do that, you will need to carry the cygwin1.dll to that machine -- keep it in the same folder as the compiled EXE).
故笙诉离歌 2024-07-31 20:06:40

总而言之,以下是一些使用 Cygwin 和 Windows Vista 导航到目录并编译代码的命令:

  1. 启动 Cygwin shell。
  2. 在提示符下,使用cd更改到适当的目录:

    $ cd /cygdrive/c/Users/nate/Desktop

  3. 使用ls列出目录中的文件:

    $ls

    prog.c

  4. 使用gcc命令编译文件在此目录中:

    $ gcc prog.c -o prog

  5. 如果不这样做看到任何错误,您应该能够运行生成的程序:

    $ ./prog

更新:

对于“Cygwin1 .dll 未找到”错误,我喜欢 Nik 的回答。 您还可以查看 找不到有关 cygwin1.dll 的相关帖子,建议将 c:\cygwin\bin\ 添加到您的 Windows 路径。

对于 Windows XP 和 Vista,有有关如何更改 Windows PATH 变量的说明我认为这是相似的。

  1. 进入控制面板-> 系统
  2. 选择高级系统设置
  3. 单击高级选项卡
  4. 单击环境变量
  5. 系统变量下,找到 >路径条目并单击编辑
  6. c:\cygwin\bin添加到列表中,确保用分号将其与之前的任何项目分隔开

Just to summarize, here are some commands that navigate to a directory and compile code using Cygwin and Windows Vista:

  1. Start a Cygwin shell.
  2. At the prompt, use cd to change to the appropriate directory:

    $ cd /cygdrive/c/Users/nate/Desktop

  3. Use ls to list the files in the directory:

    $ ls

    prog.c

  4. Use the gcc command to compile a file in this directory:

    $ gcc prog.c -o prog

  5. If you don't see any errors, you should be able to run the resulting program:

    $ ./prog

Update:

For the "Cygwin1.dll not found" error, I like Nik's answer. You might also check out this related post about cygwin1.dll not found, which suggests adding c:\cygwin\bin\ to your Windows PATH.

There are instructions on how to change the Windows PATH variable for Windows XP, and on Vista I think it's similar.

  1. Go to Control Panel -> System
  2. Select Advanced System Settings
  3. Click on the Advanced tab
  4. Click on Environment Variables
  5. Under System Variables, find the Path entry and click Edit
  6. Add c:\cygwin\bin to the list, making sure to separate it from any previous items with a semicolon
如何视而不见 2024-07-31 20:06:40

查找(即 cd 到)

/cygdrive/c/

通常是您的 C:\


另请参阅 使用 CygwinLifehacker 介绍(2006 年 6 月) 以及PhysioNet 上的生物医学页面

Look for (that is, cd to)

/cygdrive/c/

that will usually be your C:\


Also look at Using Cygwin, the Lifehacker introduction (June/2006) and, this biomed page at PhysioNet.

盗梦空间 2024-07-31 20:06:40

关于 cygwin1.dll not found 错误,我使用了至少 8 年的解决方案是将 Cygwin bin 目录添加到 My 中的 %PATH% 的末尾电脑-> 属性-> 高级-> 环境变量。 我将它们添加到路径的末尾,因此在我的正常工作中,最后搜索它们,最大限度地减少冲突的可能性(事实上,我一直没有遇到冲突问题)。

当您调用 Cygwin Bash Shell 时,这些目录会被添加到 %PATH% 之前,因此一切都可以在该环境中按预期运行。

当不在 Cygwin shell 中运行时,我的 %PATH% 是:

Path=c:\opt\perl\bin; \
     ...
     C:\opt\cygwin\bin; \
     C:\opt\cygwin\usr\bin; \
     C:\opt\cygwin\usr\local\bin;

这样,例如,当我不在 Cygwin Shell 中时,首先找到 ActiveState Perl 的 perl,但是当我在 Cygwin Shell 中时,首先找到 Cygwin perl在 Cygwin Shell 中工作。

Regarding the cygwin1.dll not found error, a solution I have used for at least 8 years is to add the Cygwin bin directories to the end of my %PATH% in My Computer -> Properties -> Advanced -> Environment Variables. I add them to the end of the path so in my normal work, they are searched last, minimizing the possibility of conflicts (in fact, I have had no problems with conflicts in all this time).

When you invoke the Cygwin Bash Shell, those directories get prepended to the %PATH% so everything works as intended in that environment as well.

When not running in Cygwin shell, my %PATH% is:

Path=c:\opt\perl\bin; \
     ...
     C:\opt\cygwin\bin; \
     C:\opt\cygwin\usr\bin; \
     C:\opt\cygwin\usr\local\bin;

This way, for example, ActiveState Perl's perl is found first when I am not in a Cygwin Shell, but the Cygwin perl is found when I am working in the Cygwin Shell.

嗳卜坏 2024-07-31 20:06:40

如果您不熟悉 bash,您可以继续在标准 Windows 命令(即 DOS)shell 中工作。

为此,您必须将 C:\cygwin\bin (或您的本地替代项)添加到 Windows PATH 变量。

完成此操作后,您可以:
1) 打开命令 (DOS) shell
2) 将目录更改为代码所在位置(c:,然后 cd path\to\file)
3) gcc myProgram.c -o myProgram

正如 nik 的回复中提到的,“使用 Cygwin”文档是了解更多信息的好地方。

If you are not comfortable with bash, you can continue to work in a standard windows command (i.e. DOS) shell.

For this to work you must add C:\cygwin\bin (or your local alternative) to the Windows PATH variable.

With this done, you may:
1) Open a command (DOS) shell
2) Change the directory to the location of your code (c:, then cd path\to\file)
3) gcc myProgram.c -o myProgram

As mentioned in nik's response, the "Using Cygwin" documentation is a great place to learn more.

離殇 2024-07-31 20:06:40

如果你只是执行 gcc program.c -o program -mno-cygwin ,它会编译得很好,你不需要将 cygwin1.dll 添加到你的路径中,你可以继续将可执行文件分发到不支持的计算机上没有安装 cygwin,它仍然会运行。 希望这可以帮助

If you just do gcc program.c -o program -mno-cygwin it will compile just fine and you won't need to add cygwin1.dll to your path and you can just go ahead and distribute your executable to a computer which doesn't have cygwin installed and it will still run. Hope this helps

绮烟 2024-07-31 20:06:40

cygwin 下的 Windows 路径 C:\src 变为 /cygdrive/c/src

Windows path C:\src under cygwin becomes /cygdrive/c/src

北风几吹夏 2024-07-31 20:06:40

使用 Cygwin 编译 C 程序

我们将使用 Cygwin 上的 gcc 编译器来编译程序。

1) 启动 Cygwin

切换到您为此类创建的目录

2) 通过输入cd c:/windows/desktop

来编译程序

3) 通过输入gcc myProgram.c -o myProgram

gcc 命令调用 gcc 编译器来编译您的 C 程序。

Compiling your C program using Cygwin

We will be using the gcc compiler on Cygwin to compile programs.

1) Launch Cygwin

2) Change to the directory you created for this class by typing

cd c:/windows/desktop

3) Compile the program by typing

gcc myProgram.c -o myProgram

the command gcc invokes the gcc compiler to compile your C program.

笛声青案梦长安 2024-07-31 20:06:40

您最好在 cygwin shell 内编辑文件。 通常启动时它有默认的用户目录。 您可以从 shell 编辑文件,执行“vi somefile.c”或“emacs somefile.c”等操作。 假设 vi 或 emacs 安装在 cygwin 中。

如果您想在桌面上归档,则必须转到类似于(在 XP 上)“/cygwindrive/c/Documents\ and\ Settings/Frank/Desktop”的路径(如果内存正常)。 只需 cd 到该路径,然后对该文件运行命令即可。

You might be better off editing a file inside of cygwin shell. Normally it has default user directory when you start it up. You can edit a file from the shell doing something like "vi somefile.c" or "emacs somefile.c". That's assuming vi or emacs are installed in cygwin.

If you want to file on your desktop, you'll have to go to a path similar (on XP) to "/cygwindrive/c/Documents\ and\ Settings/Frank/Desktop" (If memory serves correctly). Just cd to that path, and run your command on the file.

阳光的暖冬 2024-07-31 20:06:40

CYGWIN 非常酷! 您可以从其他系统(例如 Linux)编译程序,它们会工作。 我指的是通信程序,甚至是网络服务器。

这是一个技巧。 如果您正在 Windows 文件资源管理器中查看文件,则可以在 bash 窗口中键入“cd”,然后从资源管理器的地址栏拖动到 cygwin 窗口,完整路径将被复制! 顺便说一句,这也适用于 Windows 命令 shell。

另外:虽然“cd /cygdrive/c”是正式路径,但它也接受“cd c:”作为快捷方式。 您可能需要在拖入路径的其余部分之前执行此操作。

应该会自动找到 stdio.h 文件,就像在传统系统上一样。

Cygwin is very cool! You can compile programs from other systems (Linux, for example), and they will work. I'm talking communications programs, or web servers, even.

Here is one trick. If you are looking at your file in the Windows File Explorer, you can type "cd " in your bash windows, then drag from explorer's address bar into the cygwin window, and the full path will be copied! This works in the Windows command shell as well, by the way.

Also: While "cd /cygdrive/c" is the formal path, it will also accept "cd c:" as a shortcut. You may need to do this before you drag in the rest of the path.

The stdio.h file should be found automatically, as it would be on a conventional system.

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