Issues compiling in Linux

Sep 1, 2010 at 1:43am
So my code worked perfectly in Visual Studios but now that I'm testing in Linux I'm getting all types of errors.

This is a preview of my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <ostream>
#include <math.h>
using namespace std;



int main ()

{

..................
	return 0;
	system("pause");


I get the following message when I try to compile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
dlugo_lab01_v03.cpp:(.text+0x15): undefined reference to `std::cout'
dlugo_lab01_v03.cpp:(.text+0x1a): undefined reference to `std::basic_ostream<cha
r, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basi
c_ostream<char, std::char_traits<char> >&, char const*)'                       
dlugo_lab01_v03.cpp:(.text+0x26): undefined reference to `std::cin'
dlugo_lab01_v03.cpp:(.text+0x2b): undefined reference to `std::basic_istream<cha
r, std::char_traits<char> >::operator>>(long&)'                                
dlugo_lab01_v03.cpp:(.text+0x35): undefined reference to `std::cout'
dlugo_lab01_v03.cpp:(.text+0x3a): undefined reference to `std::basic_ostream<cha
r, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basi
c_ostream<char, std::char_traits<char> >&, char const*)'                       
dlugo_lab01_v03.cpp:(.text+0x46): undefined reference to `std::cin'
dlugo_lab01_v03.cpp:(.text+0x4b): undefined reference to `std::basic_istream<cha
r, std::char_traits<char> >::operator>>(long&)'                                
dlugo_lab01_v03.cpp:(.text+0x6f): undefined 


Why is this happening all of a sudden when it works fine in Visual Studios?

EDIT:

Also I forgot to mention that if I leave the system("pause") in it returns:

1
2
3
dlugo_lab01_v03.cpp: In function ‘int main()’:
dlugo_lab01_v03.cpp:51: error: ‘system’ was not declared in this scope
[dlugo@1005-11 Desktop]$


But if I take it out I get all of that craziness.
Last edited on Sep 1, 2010 at 1:47am
Sep 1, 2010 at 1:51am
Are you compiling with "gcc" or with "g++"?
Sep 1, 2010 at 1:59am
gcc. My instructor is telling that I need to be able to compile my code in any compiler. I'm even including the following:
1
2
3
4
5
6
7
8
#include <iostream>

#include <ostream>

#include <math.h>
#include <stdlib.h>

using namespace std;
Last edited on Sep 1, 2010 at 2:02am
Sep 1, 2010 at 2:28am
Use g++ rather than gcc.
Sep 1, 2010 at 2:30am
Also this...
1
2
3
4
5
6
7
8
#include <iostream>

#include <ostream>

#include <math.h>
#include <stdlib.h>

using namespace std;

...should be...
1
2
3
4
5
6
7
8
#include <iostream>

#include <ostream>

#include <cmath> // use this for C++
#include <cstdlib> // use this for C++

using namespace std;
Sep 1, 2010 at 3:47am
Yeah but would that cause all that ruckus?
Sep 1, 2010 at 4:17am
Yeah but would that cause all that ruckus?

Usually any misspelling in that regards would probably mess it all up.
Sep 1, 2010 at 4:35am
Your errors are cause by using gcc instead of g++.
Sep 1, 2010 at 4:49pm
Galik wrote:
Your errors are cause by using gcc instead of g++.

Yep, g++ links with the C++ Standard Library (std::cout, etc.) by default.
Sep 1, 2010 at 8:24pm
Yes, this is exactly the problem. I tried to compile using g++ and came up with no errors. Thanks yall.
Topic archived. No new replies allowed.