cygwin - 无法执行二进制文件
我正在尝试从我的 C++ 代码运行这两个 .data 文件来完成我的作业。我已获得所有文件,并且仅用于实现程序的一些功能(所有内容都应该能够运行 make 命令进行编译)。
我以前运行的是 MAC,只是刚刚开始使用 Windows(win 7),因为工作给了我一台免费的笔记本电脑。无论如何...我安装了 cygwin,添加了 gcc-c++ 编译器、gdb 并将软件包添加到我的 cygwin 中。但是当我运行命令 ./file ./data
时,它会出现:
bash: ./file: cannot execute binary file
是否有某个包或我应该安装的东西?请注意,./data 是保存我的两个 .data 文件的文件夹,file1.data
和 file2.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先使用
file
命令查看您拥有的二进制文件类型:如果它不是可执行文件,那就是一个问题。如果它是 ELF 可执行文件,那么它可能旨在在 Linux 上运行,而不是在 Windows 上运行。例如,将输出与此命令进行比较:
它应该告诉您:
/bin/bash: PE32 可执行文件(控制台)Intel 80386(剥离到外部 PDB),对于 MS Windows
现在尝试此命令:
其内容如下:
/cygdrive/c/windows/write.exe:PE32+可执行文件(GUI)x86-64,对于MS Windows
我在64位Windows 7安装上运行它,这就是为什么它说x86-64。尽管这是一个与 cygwin 完全无关的 Windows GUI 应用程序,但我仍然可以通过以下命令运行它:
你确实没有解释如何获得这个名为
./file
的二进制文件。它是否有可能是编译后的目标文件,您尚未链接到可执行文件?如果你有 Makefile,为什么不发布它的内容呢?Start by using the
file
command to see what type of binary file you have: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:
which should tell you:
/bin/bash: PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows
Now try this command:
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:
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?