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.
我参加了计算机科学硕士课程。课程是用C语言的,老师希望我们使用Cygwin来编译程序,如果我们使用的是windows。
I've downloaded and installed Cygwin and I've ensured that I've installed the GCC compiler.
我下载并安装了Cygwin,并确保安装了GCC编译器。
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:
让我们假设文件在我的桌面上(它不是,但为了讨论)。如何从bash shell导航到桌面?我假设一旦导航到bash中的正确位置,我就执行:
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.
由于cygwin1,此应用程序未能启动。dll文件不存在。重新安装应用程序可以解决这个问题。
11 个解决方案
#1
14
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.
当您开始使用cygwin时,您将进入$HOME,就像在unix中一样,它默认地映射到c:/cygwin/ HOME /$YOURNAME。所以你可以把所有的东西都放在那里。
You can also access the c: drive from cygwin through /cygdrive/c/ (e.g. /cygdrive/c/Documents anb Settings/yourname/Desktop).
您还可以通过/ cygwin /cygdrive/c/(例如/cygdrive/c/ c/ document anb Settings/yourname/Desktop)访问c:驱动器。
#2
9
Regarding your updated question about the missing cygwin1.dll.
关于您更新的关于缺少cygwin1.dll的问题。
From the Cygwin terminal check,
从Cygwin终端检查,
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,
这将给出:分隔的路径列表。它必须包含/usr/bin.如果你发现这个缺失,
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).
- 我希望您正在使用Cygwin终端的Cygwin(带有Cygwin的绿色+黑色小图标)或MinTTY(如果您安装了它)。
- 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).
- 而且,您还没有将编译后的EXE移动到另一台没有安装Cygwin的机器(如果这样做,您将需要携带cygwin1。将它保存在与编译后的EXE相同的文件夹中)。
#3
4
Look for (that is, cd
to)
查找(即cd到)
/cygdrive/c/
that will usually be your C:\
通常是你的C:\
Also look at Using Cygwin, the Lifehacker introduction (June/2006) and, this biomed page at PhysioNet.
还可以看看使用Cygwin, Lifehacker的简介(2006年6月),以及物理在线上的biomed页面。
#4
4
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).
关于cygwin1。dll未找到错误,我使用了至少8年的一个解决方案是将Cygwin bin目录添加到我的计算机%路径%的末尾—>属性—>高级->环境变量。我将它们添加到路径的末尾,这样在我的正常工作中,它们被搜索到最后,尽量减少冲突的可能性(事实上,我在这段时间内一直没有遇到冲突)。
When you invoke the Cygwin Bash Shell, those directories get prepended to the %PATH%
so everything works as intended in that environment as well.
当您调用Cygwin Bash Shell时,这些目录将被预写到%PATH%,以便在该环境中一切都能正常工作。
When not running in Cygwin shell, my %PATH%
is:
当不在Cygwin shell中运行时,%PATH%是:
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.
例如,这样,当我不在Cygwin Shell中时,会首先找到ActiveState Perl的Perl,但是当我在Cygwin Shell中工作时,会找到Cygwin Perl。
#5
4
Just to summarize, here are some commands that navigate to a directory and compile code using Cygwin and Windows Vista:
总结一下,这里有一些命令可以导航到一个目录并使用Cygwin和Windows Vista编译代码:
- Start a Cygwin shell.
- 启动Cygwin壳。
-
At the prompt, use
cd
to change to the appropriate directory:在提示符处,使用cd切换到相应的目录:
$ cd /cygdrive/c/Users/nate/Desktop
$ cd / cygdrive / c /用户/内特/桌面
-
Use
ls
to list the files in the directory:使用ls列出目录中的文件:
$ ls
$ ls
prog.c
prog.c
-
Use the
gcc
command to compile a file in this directory:使用gcc命令在这个目录中编译一个文件:
$ gcc prog.c -o prog
gcc学监美元。c - o掠夺
-
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.
“Cygwin1。dll未找到的“错误,我喜欢Nik的答案。”你也可以看看这篇关于cygwin1的相关文章。未找到dll,建议将c:\cygwin\bin\程序添加到Windows路径中。
There are instructions on how to change the Windows PATH variable for Windows XP, and on Vista I think it's similar.
有关于如何改变Windows XP的Windows PATH变量的说明,我认为在Vista上也是一样的。
- Go to Control Panel -> System
- 转到控制面板->系统
- Select Advanced System Settings
- 选择高级系统设置
- Click on the Advanced tab
- 单击Advanced选项卡
- Click on Environment Variables
- 点击环境变量
- Under System Variables, find the Path entry and click Edit
- 在系统变量下,找到路径条目并单击Edit。
- Add
c:\cygwin\bin
to the list, making sure to separate it from any previous items with a semicolon - 添加c:\cygwin\bin到列表中,确保它与之前的任何项目用分号分开
#6
2
If you are not comfortable with bash, you can continue to work in a standard windows command (i.e. DOS) shell.
如果您不喜欢bash,可以继续使用标准的windows命令(即DOS) shell。
For this to work you must add C:\cygwin\bin (or your local alternative) to the Windows PATH variable.
为此,您必须向Windows PATH变量添加C:\cygwin\bin(或您的本地选择)。
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
这样做之后,您可以:1)打开一个命令(DOS) shell 2)将目录更改为您的代码的位置(c:,然后cd路径\ \file) 3) gcc myProgram。c - o myProgram
As mentioned in nik's response, the "Using Cygwin" documentation is a great place to learn more.
正如nik在回复中提到的,“使用Cygwin”文档是了解更多信息的好地方。
#7
1
Windows path C:\src
under cygwin becomes /cygdrive/c/src
Windows路径C: cygwin下的src变成/cygdrive/ C /src
#8
1
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
如果你只做gcc程序。c -o程序-mno-cygwin它会很好地编译,您不需要添加cygwin1。你可以直接将你的可执行文件分发给没有安装cygwin的电脑,它仍然会运行。希望这有助于
#9
0
Compiling your C program using Cygwin
使用Cygwin编译C程序
We will be using the gcc compiler on Cygwin to compile programs.
我们将使用Cygwin上的gcc编译器来编译程序。
1) Launch Cygwin
1)启动Cygwin
2) Change to the directory you created for this class by typing
2)通过键入更改为该类创建的目录
cd c:/windows/desktop
cd c:/ windows桌面
3) Compile the program by typing
3)通过输入编译程序
gcc myProgram.c -o myProgram
gcc myProgram。c - o myProgram
the command gcc invokes the gcc compiler to compile your C program.
gcc命令调用gcc编译器来编译您的C程序。
#10
0
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.
最好在cygwin shell中编辑一个文件。正常情况下,当你启动它时它有默认的用户目录。您可以从shell中编辑一个文件,执行类似“vi somefile”的操作。c”或“emacs somefile.c”。假设在cygwin中安装了vi或emacs。
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.
如果你想在你的桌面文件,你必须去一个类似的路径(在XP上)到“/cygwindrive/c/Documents\ and\ Settings/Frank/ desktop”(如果内存正确的话)。只需cd到该路径,并在文件上运行命令。
#11
0
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.
Cygwin非常酷!您可以从其他系统(例如Linux)编译程序,它们将工作。我说的是通信程序,甚至是网络服务器。
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.
这是一个技巧。如果您正在Windows文件资源管理器中查看文件,您可以在您的bash窗口中键入“cd”,然后从资源管理器的地址栏拖到cygwin窗口,完整的路径将被复制!顺便说一下,这在Windows命令shell中也适用。
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.
同样:虽然“cd /cygdrive/c”是正式的路径,但它也会接受“cd:”作为快捷方式。在拖拽路径的其他部分之前,您可能需要这样做。
The stdio.h file should be found automatically, as it would be on a conventional system.
的头。h文件应该是自动找到的,就像在传统的系统上一样。
#1
14
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.
当您开始使用cygwin时,您将进入$HOME,就像在unix中一样,它默认地映射到c:/cygwin/ HOME /$YOURNAME。所以你可以把所有的东西都放在那里。
You can also access the c: drive from cygwin through /cygdrive/c/ (e.g. /cygdrive/c/Documents anb Settings/yourname/Desktop).
您还可以通过/ cygwin /cygdrive/c/(例如/cygdrive/c/ c/ document anb Settings/yourname/Desktop)访问c:驱动器。
#2
9
Regarding your updated question about the missing cygwin1.dll.
关于您更新的关于缺少cygwin1.dll的问题。
From the Cygwin terminal check,
从Cygwin终端检查,
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,
这将给出:分隔的路径列表。它必须包含/usr/bin.如果你发现这个缺失,
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).
- 我希望您正在使用Cygwin终端的Cygwin(带有Cygwin的绿色+黑色小图标)或MinTTY(如果您安装了它)。
- 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).
- 而且,您还没有将编译后的EXE移动到另一台没有安装Cygwin的机器(如果这样做,您将需要携带cygwin1。将它保存在与编译后的EXE相同的文件夹中)。
#3
4
Look for (that is, cd
to)
查找(即cd到)
/cygdrive/c/
that will usually be your C:\
通常是你的C:\
Also look at Using Cygwin, the Lifehacker introduction (June/2006) and, this biomed page at PhysioNet.
还可以看看使用Cygwin, Lifehacker的简介(2006年6月),以及物理在线上的biomed页面。
#4
4
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).
关于cygwin1。dll未找到错误,我使用了至少8年的一个解决方案是将Cygwin bin目录添加到我的计算机%路径%的末尾—>属性—>高级->环境变量。我将它们添加到路径的末尾,这样在我的正常工作中,它们被搜索到最后,尽量减少冲突的可能性(事实上,我在这段时间内一直没有遇到冲突)。
When you invoke the Cygwin Bash Shell, those directories get prepended to the %PATH%
so everything works as intended in that environment as well.
当您调用Cygwin Bash Shell时,这些目录将被预写到%PATH%,以便在该环境中一切都能正常工作。
When not running in Cygwin shell, my %PATH%
is:
当不在Cygwin shell中运行时,%PATH%是:
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.
例如,这样,当我不在Cygwin Shell中时,会首先找到ActiveState Perl的Perl,但是当我在Cygwin Shell中工作时,会找到Cygwin Perl。
#5
4
Just to summarize, here are some commands that navigate to a directory and compile code using Cygwin and Windows Vista:
总结一下,这里有一些命令可以导航到一个目录并使用Cygwin和Windows Vista编译代码:
- Start a Cygwin shell.
- 启动Cygwin壳。
-
At the prompt, use
cd
to change to the appropriate directory:在提示符处,使用cd切换到相应的目录:
$ cd /cygdrive/c/Users/nate/Desktop
$ cd / cygdrive / c /用户/内特/桌面
-
Use
ls
to list the files in the directory:使用ls列出目录中的文件:
$ ls
$ ls
prog.c
prog.c
-
Use the
gcc
command to compile a file in this directory:使用gcc命令在这个目录中编译一个文件:
$ gcc prog.c -o prog
gcc学监美元。c - o掠夺
-
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.
“Cygwin1。dll未找到的“错误,我喜欢Nik的答案。”你也可以看看这篇关于cygwin1的相关文章。未找到dll,建议将c:\cygwin\bin\程序添加到Windows路径中。
There are instructions on how to change the Windows PATH variable for Windows XP, and on Vista I think it's similar.
有关于如何改变Windows XP的Windows PATH变量的说明,我认为在Vista上也是一样的。
- Go to Control Panel -> System
- 转到控制面板->系统
- Select Advanced System Settings
- 选择高级系统设置
- Click on the Advanced tab
- 单击Advanced选项卡
- Click on Environment Variables
- 点击环境变量
- Under System Variables, find the Path entry and click Edit
- 在系统变量下,找到路径条目并单击Edit。
- Add
c:\cygwin\bin
to the list, making sure to separate it from any previous items with a semicolon - 添加c:\cygwin\bin到列表中,确保它与之前的任何项目用分号分开
#6
2
If you are not comfortable with bash, you can continue to work in a standard windows command (i.e. DOS) shell.
如果您不喜欢bash,可以继续使用标准的windows命令(即DOS) shell。
For this to work you must add C:\cygwin\bin (or your local alternative) to the Windows PATH variable.
为此,您必须向Windows PATH变量添加C:\cygwin\bin(或您的本地选择)。
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
这样做之后,您可以:1)打开一个命令(DOS) shell 2)将目录更改为您的代码的位置(c:,然后cd路径\ \file) 3) gcc myProgram。c - o myProgram
As mentioned in nik's response, the "Using Cygwin" documentation is a great place to learn more.
正如nik在回复中提到的,“使用Cygwin”文档是了解更多信息的好地方。
#7
1
Windows path C:\src
under cygwin becomes /cygdrive/c/src
Windows路径C: cygwin下的src变成/cygdrive/ C /src
#8
1
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
如果你只做gcc程序。c -o程序-mno-cygwin它会很好地编译,您不需要添加cygwin1。你可以直接将你的可执行文件分发给没有安装cygwin的电脑,它仍然会运行。希望这有助于
#9
0
Compiling your C program using Cygwin
使用Cygwin编译C程序
We will be using the gcc compiler on Cygwin to compile programs.
我们将使用Cygwin上的gcc编译器来编译程序。
1) Launch Cygwin
1)启动Cygwin
2) Change to the directory you created for this class by typing
2)通过键入更改为该类创建的目录
cd c:/windows/desktop
cd c:/ windows桌面
3) Compile the program by typing
3)通过输入编译程序
gcc myProgram.c -o myProgram
gcc myProgram。c - o myProgram
the command gcc invokes the gcc compiler to compile your C program.
gcc命令调用gcc编译器来编译您的C程序。
#10
0
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.
最好在cygwin shell中编辑一个文件。正常情况下,当你启动它时它有默认的用户目录。您可以从shell中编辑一个文件,执行类似“vi somefile”的操作。c”或“emacs somefile.c”。假设在cygwin中安装了vi或emacs。
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.
如果你想在你的桌面文件,你必须去一个类似的路径(在XP上)到“/cygwindrive/c/Documents\ and\ Settings/Frank/ desktop”(如果内存正确的话)。只需cd到该路径,并在文件上运行命令。
#11
0
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.
Cygwin非常酷!您可以从其他系统(例如Linux)编译程序,它们将工作。我说的是通信程序,甚至是网络服务器。
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.
这是一个技巧。如果您正在Windows文件资源管理器中查看文件,您可以在您的bash窗口中键入“cd”,然后从资源管理器的地址栏拖到cygwin窗口,完整的路径将被复制!顺便说一下,这在Windows命令shell中也适用。
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.
同样:虽然“cd /cygdrive/c”是正式的路径,但它也会接受“cd:”作为快捷方式。在拖拽路径的其他部分之前,您可能需要这样做。
The stdio.h file should be found automatically, as it would be on a conventional system.
的头。h文件应该是自动找到的,就像在传统的系统上一样。