如何在Linux上编译.cpp文件?

时间:2022-06-06 17:41:38

I'm fairly comfortable with Linux and compiling things - I normally just follow the instructions and can manage to get myself out of trouble. This time, I was given a .cpp file by a random Internet citizen and I would really like to know how to compile it. Everything I seem to try (g++, c++, gcc) doesn't seem to work.

我对Linux操作系统很熟悉,并且编译东西——我通常只是按照指令行事,并能设法让自己摆脱麻烦。这一次,我被一个随机的互联网公民给了一个。cpp文件,我很想知道如何编译它。我所尝试的一切(g+、c++、gcc)似乎都不管用。

Anyhow, here's the file: http://pastebin.ca/2073013

总之,这是文件:http://pastebin.ca/2073013

Edit: Updated with verbose output from g++ file.cpp -o whatever: http://pastebin.ca/2073052

编辑:用g++文件的详细输出进行更新。cpp - o无论:http://pastebin.ca/2073052

3 个解决方案

#1


25  

You'll need to compile it using:

您需要使用以下方法编译:

g++ inputfile.cpp -o outputbinary

The file you are referring has a missing #include <cstdlib> directive, if you also include that in your file, everything shall compile fine.

您所引用的文件有一个缺失的#include 指令,如果您在您的文件中也包含这个指令,那么所有的东西都应该编译良好。

#2


1  

The compiler is telling you that there are problems starting at line 122 in the middle of that strange FBI-CIA warning message. That message is not valid C++ code and is NOT commented out so of course it will cause compiler errors. Try removing that entire message.

编译器告诉您,在这个奇怪的FBI-CIA警告消息中间的第122行有一些问题。该消息不是有效的c++代码,并且没有注释掉,因此它当然会导致编译器错误。尝试删除整个消息。

Also, I agree with In silico: you should always tell us what you tried and exactly what error messages you got.

而且,我也同意“硅”的说法:您应该总是告诉我们您尝试了什么,以及您得到了什么错误消息。

#3


0  

Just type the code and save it in .cpp format. then try "gcc filename.cpp" . This will create the object file. then try "./a.out" (This is the default object file name). If you want to know about gcc you can always try "man gcc"

只需键入代码并将其保存为.cpp格式。然后试着“gcc文件名。cpp”。这将创建对象文件。然后尝试”。/。out(这是默认的对象文件名)。如果你想了解gcc,你可以试试“man gcc”

#1


25  

You'll need to compile it using:

您需要使用以下方法编译:

g++ inputfile.cpp -o outputbinary

The file you are referring has a missing #include <cstdlib> directive, if you also include that in your file, everything shall compile fine.

您所引用的文件有一个缺失的#include 指令,如果您在您的文件中也包含这个指令,那么所有的东西都应该编译良好。

#2


1  

The compiler is telling you that there are problems starting at line 122 in the middle of that strange FBI-CIA warning message. That message is not valid C++ code and is NOT commented out so of course it will cause compiler errors. Try removing that entire message.

编译器告诉您,在这个奇怪的FBI-CIA警告消息中间的第122行有一些问题。该消息不是有效的c++代码,并且没有注释掉,因此它当然会导致编译器错误。尝试删除整个消息。

Also, I agree with In silico: you should always tell us what you tried and exactly what error messages you got.

而且,我也同意“硅”的说法:您应该总是告诉我们您尝试了什么,以及您得到了什么错误消息。

#3


0  

Just type the code and save it in .cpp format. then try "gcc filename.cpp" . This will create the object file. then try "./a.out" (This is the default object file name). If you want to know about gcc you can always try "man gcc"

只需键入代码并将其保存为.cpp格式。然后试着“gcc文件名。cpp”。这将创建对象文件。然后尝试”。/。out(这是默认的对象文件名)。如果你想了解gcc,你可以试试“man gcc”