g++在 cygwin 中不创建 .exe 文件
我刚刚在运行 Windows 7 的新 Windows 机器上安装了 cygwin,当我编译 C++ 程序时,我得到了有趣的行为。这是我输入的内容:
g++ test.gpp -o test
在我的其他 Windows 机器上,这会创建一个 exe 文件 test.exe,当然它是一个可执行文件。但在此安装中,会创建文件 test。令我惊讶的是,它不是一个可执行文件,而是看起来像一个调试文件(以 ascii 打印格式)。如果我输入:
g++ test.gpp -o test.exe
那么我就会得到可执行文件 test.exe。 (1) 为什么在我的所有其他实现中我都得到了可执行文件,但最近的尝试却没有得到可执行文件? (2)我为什么关心?嗯,我也在 Linux 机器上工作,不习惯输入扩展名“.exe”。 (我讨厌非linux文件的这一方面!)我猜测我可以设置某种一次性标志来使g ++创建的默认文件成为.exe文件。
这个问题的问题是你们可能都无法重现它! (我不能在我的其他机器上!)
I just installed cygwin on a new Windows box running Windows 7 and I am getting funny behavior when I compile a c++ program. Here's what I type:
g++ test.gpp -o test
On my other Windows boxes, this creates an exe file, test.exe, and it is, of course an executable. But on this installation, the file test is created. To my surprise, it is not an executable, but rather looks like a debug file (in ascii printables). If I instead type:
g++ test.gpp -o test.exe
Then I do get the executable test.exe. (1) why in all my other implementations do I get the executable, but not with this most recent attempt? (2) Why do I care? Well, I also work on linux boxes and am not accustomed to typing the extension ".exe". (I hate that aspect of non-linux files!) I am guessing that there is some sort of one-time flag I can set to make the default file that g++ creates be a .exe file.
The problem with this problem is that none of you may be able to reproduce it! (I can't on my other machines!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,
g++
无法识别.gpp
扩展名。将文件从test.gpp
重命名为test.cpp
,然后重试。在我的 Cygwin 系统上,
g++ test.gpp
给我一条错误消息:Cygwin 编译器确实创建带有
.exe
扩展名的可执行文件(因为 Windows 需要它),但它也让您可以引用不带后缀的此类文件。因此,例如:和
应该都显示相同的文件。 (如果您碰巧有两个名称的文件,事情可能会变得有点混乱——所以不要这样做。)
g++
的-s
选项也处理.exe
后缀特殊,因此-o test
和-o test.exe
应该做同样的事情。我不知道你为什么会看到你所描述的行为。也许您碰巧在
test.gpp
中有一些看起来像有效链接器脚本的东西?As far as I can tell,
g++
doesn't recognize the.gpp
extension. Rename the file fromtest.gpp
totest.cpp
and try again.On my Cygwin system,
g++ test.gpp
gives me an error message:Cygwin compilers do create executable files with a
.exe
extension (because Windows requires it), but it also lets you refer to such files without the suffix. So, for example:and
should both show you the same file. (If you happen to have files with both names, things can get a bit confusing -- so don't do that.)
g++
's-s
option also treats the.exe
suffix specially, so-o test
and-o test.exe
should do the same thing.I don't know why you're seeing the behavior you describe. Perhaps you happen to have something in
test.gpp
that looks like a valid linker script?这应该创建一个名为 test 的文件(没有扩展名)。如果创建该文件,则使用 chmod +x test 授予该文件可执行权限,
而不是使用 ./test 来运行它。看看是否有效。
This should create a file called test (with no extension). If that file is created than give executable permission the file using
chmod +x test
than use
./test
to run it. see if it works.