Hack Forums
[Mint] Help with compiling C++ - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Computing (https://hackforums.net/forumdisplay.php?fid=88)
+---- Forum: Linux (https://hackforums.net/forumdisplay.php?fid=85)
+---- Thread: [Mint] Help with compiling C++ (/showthread.php?tid=4968778)



[Mint] Help with compiling C++ - Paul Wilson - Aug 29, 2015

Hi guys

I installed mint today, and I made a hello world program in c++. I would like to compile it.

I installed all of the things (build essential, g++, etc...) and when I try to compile it it gives me various errors:

Here is the code I would like to compile:
Code
#include <iostream>
using namespace std;

int main() {
    cout << "Hello world";
    return 0;
}

It is saved as helloworld.cpp, and I am compiling it with this command: gcc helloworld.cpp -o helloworld

And I get this error:
Code
/tmp/ccssFjje.o: In function `main':
helloworld.cpp:(.text+0x14): undefined reference to `std::cout'
helloworld.cpp:(.text+0x19): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccssFjje.o: In function `__static_initialization_and_destruction_0(int, int)':
helloworld.cpp:(.text+0x41): undefined reference to `std::ios_base::Init::Init()'
helloworld.cpp:(.text+0x58): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status

Could someone help me solve this issue? Thanks


* - scam. - Aug 29, 2015

Use g++ to compile c++. There is no errors in that code, although there is no point having 'int integer;' but I assume that was left over from something you were doing before.


* - Paul Wilson - Aug 29, 2015

(Aug 29, 2015 10:50 PM)Mael Wrote:  Use g++ to compile c++. There is no errors in that code, although there is no point having 'int integer;' but I assume that was left over from something you were doing before.

Ah, so g++ is for c++ and gcc is for c? I assume it is because this worked, I feel so stupid now lol, thanks for helping me for the second time 🤝


* - scam. - Aug 29, 2015

(Aug 29, 2015 10:55 PM)MishaTheHoovy Wrote:  Ah, so g++ is for c++ and gcc is for c? I assume it is because this worked, I feel so stupid now lol, thanks for helping me for the second time 🤝

No problem my man. I just like activity in this section.