C++ make后如何运行.o文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22251571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 00:00:48  来源:igfitidea点击:

how to run the .o file after make

c++cmakefile

提问by user3293434

I have been trying to run a c++ program from https://github.com/rinon/Simple-Homomorphic-Encryption

我一直在尝试从https://github.com/rinon/Simple-Homomorphic-Encryption运行 C++ 程序

As specified in the READMEI have run the following commands,

正如README我已经运行了以下命令中指定的那样,

make

make test

make demo

Now, I have the following files in my directory,

现在,我的目录中有以下文件,

zakirhussain@zakirhussain-K52F:~/Simple-Homomorphic-Encryption$ ls
circuit.cpp             demo_vote_counter.cpp  fully_homomorphic.cpp  main.o                 security_settings.h     test_suite.o  utilities.o
circuit.h               demo_vote_counter.h    fully_homomorphic.h    makefile               security_settings.o     type_defs.h
circuit.o               demo_vote_counter.o    fully_homomorphic.o    README                 test_fully_homomorphic  utilities.c
demo_fully_homomorphic  fully_homomorphic      main.cpp               security_settings.cpp  test_suite.cpp          utilities.h

Could someone help me with running demo_vote_counter.ofile?

有人可以帮我运行demo_vote_counter.o文件吗?

回答by Marc Claesen

An object file(.o) is not executable. You want to be running ./demo_fully_homomorphic(e.g. the file without extension). Make sure you have execute permissions (chmod a+x demo_fully_homomorphic).

一个目标文件.o)是不可执行的。您想要运行./demo_fully_homomorphic(例如没有扩展名的文件)。确保您具有执行权限 ( chmod a+x demo_fully_homomorphic)。

回答by Devolus

You can not run a .ofile. This is an object file and has to be linked into the final executable. A .ofile is usually lacking additional libraries, which are added at the linking stage.

你不能运行一个.o文件。这是一个目标文件,必须链接到最终的可执行文件中。甲.o文件通常缺乏附加的库,其在该连接阶段加入。

Looking at your outoput I would assume that one of demo_fully_homomorphic, test_fully_homomorphicor fully_homomorphicare the executables that you can run.

查看您的输出,我会假设其中之一demo_fully_homomorphictest_fully_homomorphic或者fully_homomorphic是您可以运行的可执行文件。

回答by KedarX

As already mentioned in several other answers, you can execute a binary file and not the object file. However, Just in case, if what you want is to display the contents of object file in readable format?

正如其他几个答案中已经提到的,您可以执行二进制文件而不是目标文件。但是,以防万一,如果您想要以可读格式显示目标文件的内容?

$>objdump -d object_filename.o 

回答by tebe

You can't run the object file. It has to be linked first to make an executable.

您无法运行目标文件。必须先链接它才能生成可执行文件。

As I see there is a "demo_fully_homomorphic" "fully_homomorphic" and a "test_fully_homomorphic" in your directory. Those are your linked executables, you may execute them with ./[executable_name]

正如我所看到的,您的目录中有一个“demo_fully_homomorphic”、“fully_homomorphic”和一个“test_fully_homomorphic”。这些是您链接的可执行文件,您可以使用 ./[executable_name] 执行它们

回答by Dan

In this case the executable is called demo_fully_homomorphic, try

在这种情况下,可执行文件被调用demo_fully_homomorphic,尝试

./demo_fully_homomorphic

回答by Cuong Vo

I think I am late, but the code below maybe helpful for someone, I guess.

我想我迟到了,但我猜下面的代码可能对某人有帮助。

Using cd into your folder contains the c/c++ file, then compile it.

使用 cd 进入包含 c/c++ 文件的文件夹,然后编译它。

gcc my_test.c -o my_test

Complied file will be generated. Then still in same folder. Run the command.

将生成编译文件。然后仍然在同一个文件夹中。运行命令。

./my_test