How do I compile a .cpp file on Linux? [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
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.
Anyhow, here's the file: http://pastebin.ca/2073013
Edit: Updated with verbose output from g++ file.cpp -o whatever: http://pastebin.ca/2073052

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.

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.
Also, I agree with In silico: you should always tell us what you tried and exactly what error messages you got.

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"

Related

What is wrong with the g++ command synatx? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I want to use Tensorflow shared object in my other C++ code, named as Temp_TF.cc
I am using the following command to create an executable.
g++ ../../../bazel-bin/tensorflow/cc/example/Temp_TF.so -ltensorflow_cc Temp_TF.cc -o Temp_TF
What is wrong with the following command?
I am getting the following error:
Temp_TF.cc:3:49: fatal error: tensorflow/cc/client/client_session.h: No such file or directory
compilation terminated.
I can see you're new to Stack Overflow.
Technically your question does not have enough data for us to provide an answer for sure.
However it looks to me as though you're missing a -I (capital i) directive and the compiler does not know where to find the tensorflow/cc/client/client_session.h path.
From the look of it, you could try:
g++ -I ../../../bazel-bin ../../../bazel-bin/tensorflow/cc/example/Temp_TF.so -ltensorflow_cc Temp_TF.cc -o Temp_TF
(note the -I)

C++ #include <iostream>

I'm a complete newbie to C++. I'm trying to write a simple c++
program but I got an error message. I suspect this is due to me
accidentally deleting some .h files on my mac which might have ruined
my Clang compiler. How can I fix this? Do I need to reinstall Xcode or
change a compiler?
Error message from terminal:
192:desktop ivanlee$ gcc test.cpp
In file included from test.cpp:1:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iostream:38:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ios:215:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iosfwd:90:
In file included from /usr/include/wchar.h:70:
In file included from /usr/include/_types.h:27:
/usr/include/sys/_types.h:32:10: fatal error: 'sys/cdefs.h' file not found
#include <sys/cdefs.h>
^
1 error generated.
Code:
#include <iostream>
int main(){
return 0;
std::cout << "Hey";
}
At first I ought to recommend you the definitive stackoverflow c++ books list. Read these books and get your skills grow. This also will prevent questions like this.
Your question needs very-very basic knowledges and answers may be too long and your problem can be solved by many different methods.
I can tell you one but you should not ask questions like this.
Answer
Your code contains a mistakes:
return 0 before your other instructions (it should be the last). Now your program will just do nothing.
You should always compile C++ code with C++ compiler. gcc is not a c++ compiler but c compiler - use g++ instead.
Even if you correct 2 errors above, your std::cout call may fail because it does not flush the stream. You should also add << std::endl to this call.
Execute
g++ test.cpp -o out
Instead of
gcc text.cpp
run Terminal
execute gcc -v
Read the info and copy the include path. Copy it to your IDE that allows you to add the include path.
Mine, for an example, is:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1

Internal Error in codeblocks [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
My code was compiling just fine until recently i started using a pair for stl maps and then their was some issue.
Every time i compile any file which was compiling just fine before hand i get the error
The same error comes for every file regardless of its function. Its some internal error.
Ever time i try to compile a code this file stl_functions.h automatically opens.
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_function.h|143|error: declaration of 'class _Tp'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_function.h|134|error: shadows template parm 'class _Tp'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings ===|
I got around 50 repetitive errors but i have shown only a few.
I have searched everywhere for this kind of error but i can't seem to find a solution.
Any help will be appreciated.
Did you by chance try to edit a standard header ? Reinstall MinGW/Code::Blocks and it should work again.

How to interpret g++ generated .i file [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
gcc preprocessor output
For some reason I need to investigate some .i files generated by g++ preprocessor, where I see code like this:
#1 /usr/local/include/boost/python.hpp 1 3
#11 /usr/local/include/boost/python.hpp 3
I'm an experienced C++ programmer and I know what .i file is, the problem is, I can't find a detailed explanation on how to interpret the lines in .i file.
Can someone explain what the above lines mean (especially what the numbers following the files ) or point me a place where I can find some document about this?
Thanks, after looking at the link, my problem solved. I'd like to add some background in case somebody else see the same problem.
My project uses a strict compiler check, i.e., g++ -Wall -Werror. All warnings are treated as errors. And we are using boost.python, before yesterday, boost was put in /usr/local/include, and the compilation is fine. Then we decide to move boost into our source control for easier upgrade, and a warning (treated as error) arise.
So after the investigation and the details from the link given by CrazyCasta, the problem is actually this: when boost is in /usr/local/include, it is treated as a system header, so gcc supresses some warnings; while we move boost out, gcc is not that tolerable to it.
Basically, just ignore or supress that warning by hand.
Your answer can be found here.
Basically it's remapping the line number/filename space of the input so the compiler knows where lines came from. The first number is the line number of where the source came from, the filename after that is the file it came from. The numbers thereafter are flags.

C++: debug bus error

I am trying to compile a c++ program in Linux, using the command in the shell
$ g++ -Wall *.cpp -o prog
and for some reason it keeps on giving me a weird error:
g++: Internal error: Bus error (program cc1plus) Please submit a full
bug report. See for
instructions.
I searched the net for this bus error, and it says that it has to do with something about accessing illegal memory.
Can someone maybe clarify things a bit more for me?
This error message is telling you that there's a bug in the g++ compiler itself.
Try to narrow it down by removing bits and pieces of your source file until the problem goes away. You're not trying to fix your program, you're just trying to find the part that is breaking the compiler. Once you've found it, you can either give a better bug description or you can change your code to work around it.
Or just download the latest version of the g++ compiler and hope that it's already fixed.
Your problem is not in your code, is the compiler (g++) that is crashing and producing that Bus Error, it's possible you have an outdated version of such compiler and need to update, or you're lucky and found a real bug in g++.
I would try compiling each source file separately, to check what part of the source code triggers the error.