cygwin - 无法执行二进制文件

发布于 2024-11-28 04:43:12 字数 593 浏览 1 评论 0原文

我正在尝试从我的 C++ 代码运行这两个 .data 文件来完成我的作业。我已获得所有文件,并且仅用于实现程序的一些功能(所有内容都应该能够运行 make 命令进行编译)。

我以前运行的是 MAC,只是刚刚开始使用 Windows(win 7),因为工作给了我一台免费的笔记本电脑。无论如何...我安装了 cygwin,添加了 gcc-c++ 编译器、gdb 并将软件包添加到我的 cygwin 中。但是当我运行命令 ./file ./data 时,它会出现:

bash: ./file: cannot execute binary file

是否有某个包或我应该安装的东西?请注意,./data 是保存我的两个 .data 文件的文件夹,file1.datafile2.data

由“编译”

g++ -Wall -Werror -02 -c file.cpp
g++ -Wall -Werror -02 -c file-test.cpp
g++ -Wall -Werror -02 -o file file.o file-test.o

I am trying to run these two .data files from my c++ code for my assignment. I have been provided with all the files and are meant to only implement a few functions for the program (everything should be able to compile running the make command).

I used to run a MAC and only just started using windows (win 7) because work gave me a free laptop. Anyways...I installed cygwin, added the gcc-c++ compiler, gdb and make packages to my cygwin. But when i run the command ./file ./data it comes up with:

bash: ./file: cannot execute binary file

is there a certain package or something I am suppose to install? Please note, that ./data is the folder that holds my two .data files, file1.data and file2.data

compiled by"

g++ -Wall -Werror -02 -c file.cpp
g++ -Wall -Werror -02 -c file-test.cpp
g++ -Wall -Werror -02 -o file file.o file-test.o

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

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

发布评论

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

评论(1

甜柠檬 2024-12-05 04:43:12

首先使用 file 命令查看您拥有的二进制文件类型:

file ./file

如果它不是可执行文件,那就是一个问题。如果它是 ELF 可执行文件,那么它可能旨在在 Linux 上运行,而不是在 Windows 上运行。例如,将输出与此命令进行比较:

file /bin/bash

它应该告诉您:

/bin/bash: PE32 可执行文件(控制台)Intel 80386(剥离到外部 PDB),对于 MS Windows

现在尝试此命令:

file /cygdrive/c/windows/write.exe

其内容如下:
/cygdrive/c/windows/write.exe:PE32+可执行文件(GUI)x86-64,对于MS Windows

我在64位Windows 7安装上运行它,这就是为什么它说x86-64。尽管这是一个与 cygwin 完全无关的 Windows GUI 应用程序,但我仍然可以通过以下命令运行它:

/cygdrive/c/windows/write

你确实没有解释如何获得这个名为 ./file 的二进制文件。它是否有可能是编译后的目标文件,您尚未链接到可执行文件?如果你有 Makefile,为什么不发布它的内容呢?

Start by using the file command to see what type of binary file you have:

file ./file

If it is not an executable, that is a problem. If it is an ELF executable then it is probably intended to run on Linux, not on Windows. For example compare the output with this command:

file /bin/bash

which should tell you:

/bin/bash: PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows

Now try this command:

file /cygdrive/c/windows/write.exe

Which says the following:
/cygdrive/c/windows/write.exe: PE32+ executable (GUI) x86-64, for MS Windows

I ran this on a 64-bit Windows 7 installation, which is why it says x86-64. Even though this is a Windows GUI app totally unrelated to cygwin, I can still run it by the command:

/cygdrive/c/windows/write

You really did not explain how you got this binary file named ./file. Is it possible that it is an object file from compiling that you have not yet linked into an executable? If you have a Makefile, why not post its contents?

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