Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

[Mint] Help with compiling C++

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
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.
(Aug 29, 2015 10:50 PM)scam. 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 🤝
(Aug 29, 2015 10:55 PM)Paul Wilson 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.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by Zero_LuffyNov 19, 2014 10:30 PM 2 128 Nov 19, 2014 10:30 PM
Last Post: NeverHere
by mindswordAug 2, 2014 11:55 PM 8 100 Aug 2, 2014 11:55 PM
Last Post: mindsword
by kitkin15Jul 1, 2010 06:46 PM 8 76 Jul 1, 2010 06:46 PM
Last Post: kitkin15