You are not logged in.

#1 2005-09-13 00:30:36

yak8998
Member
Registered: 2004-03-01
Posts: 143

gcc hassling me (c++)

#include <iostream>

using namespace std;

int main() {

int d = -1;
int n;
int q;
int r;


cout << "Enter the numerator (top number)";
cin >> n;

while (d == 0 || d == -1) {
        if (d == 0) {
                cout << "You can't divide by 0";
        }
        cout << "nEnter the denominator (bottom number)";
        cin >> d;
        cout << "n";
}

q = n / d;
r = n % d;
cout << "nThe quotient with remainder is " << q << " R" << r;

q = 1.0 * n / d;
cout << "nThe quotient is " << q;



return 0;
}
project2_1.cpp: In function `int main()':
project2_1.cpp:31: warning: converting to `int' from `double'
/tmp/ccBBSb6P.o(.text+0xd): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
/tmp/ccBBSb6P.o(.text+0x60): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccBBSb6P.o(.text+0x9f): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccBBSb6P.o(.text+0xce): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccBBSb6P.o(.text+0x12e): In function `main':
: undefined reference to `std::cout'
/tmp/ccBBSb6P.o(.text+0x133): In function `main':
: 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/ccBBSb6P.o(.text+0x141): In function `main':
: undefined reference to `std::cin'
/tmp/ccBBSb6P.o(.text+0x146): In function `main':
: undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
/tmp/ccBBSb6P.o(.text+0x169): In function `main':
: undefined reference to `std::cout'
/tmp/ccBBSb6P.o(.text+0x16e): In function `main':
: 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/ccBBSb6P.o(.text+0x17d): In function `main':
: undefined reference to `std::cout'
/tmp/ccBBSb6P.o(.text+0x182): In function `main':
: 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/ccBBSb6P.o(.text+0x190): In function `main':
: undefined reference to `std::cin'
/tmp/ccBBSb6P.o(.text+0x195): In function `main':
: undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
/tmp/ccBBSb6P.o(.text+0x1a4): In function `main':
: undefined reference to `std::cout'
/tmp/ccBBSb6P.o(.text+0x1a9): In function `main':
: 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/ccBBSb6P.o(.text+0x1e8): In function `main':
: undefined reference to `std::cout'
/tmp/ccBBSb6P.o(.text+0x1ed): In function `main':
: 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/ccBBSb6P.o(.text+0x1fe): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
/tmp/ccBBSb6P.o(.text+0x20e): In function `main':
: 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/ccBBSb6P.o(.text+0x21f): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
/tmp/ccBBSb6P.o(.text+0x24e): In function `main':
: undefined reference to `std::cout'
/tmp/ccBBSb6P.o(.text+0x253): In function `main':
: 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/ccBBSb6P.o(.text+0x264): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
/tmp/ccBBSb6P.o(.text+0x28d): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init()'
/tmp/ccBBSb6P.o(.text+0x2be): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccBBSb6P.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

I have no idea whats going on. Haven't had a chance to play with any other compilers yet, dunno if its my computer, probably my code. I miss java  :oops:
thanks


"Ignorance is bliss, for stupid people."
"open-source is [...] programming Darwinism."
Vaughan-Nichols

Offline

#2 2005-09-13 00:32:49

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: gcc hassling me (c++)

try g++

Offline

#3 2005-09-13 00:48:01

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: gcc hassling me (c++)

sorry I should have been more clear...
g++ will compile c++ files while gcc is C.
when you do g++ nameoffile.cpp it spits out an a.out executable. If you want to change that you can do

g++ -o nameofoutputfile nameoffile.cpp

and the executable will be nameofoutputfile.

Offline

#4 2005-09-13 01:40:20

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: gcc hassling me (c++)

or you can just type make and it will use the correct gnu compiler for you

Offline

#5 2005-09-13 01:45:02

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: gcc hassling me (c++)

Euphoric Nightmare wrote:

or you can just type make and it will use the correct gnu compiler for you

Doesn't that require writing a makefile??

Offline

#6 2005-09-13 02:25:57

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: gcc hassling me (c++)

Another problem with your code is that you declare q as an integer:

int q;

but you give it a double value:

q = 1.0 * n / d;

Offline

#7 2005-09-13 03:12:16

yak8998
Member
Registered: 2004-03-01
Posts: 143

Re: gcc hassling me (c++)

Snowman wrote:

Another problem with your code is that you declare q as an integer:

int q;

but you give it a double value:

q = 1.0 * n / d;

ah crap, thats why it wasnt working. stupid me...

thanks for the help everyone, works now


"Ignorance is bliss, for stupid people."
"open-source is [...] programming Darwinism."
Vaughan-Nichols

Offline

#8 2005-09-13 11:27:53

awalk
Member
From: Perth, Western Australia
Registered: 2005-02-14
Posts: 40

Re: gcc hassling me (c++)

Dusty: Yes, it requires a Makefile.

Offline

#9 2005-09-13 14:04:01

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: gcc hassling me (c++)

Actually no, its not needed. you can just type make project2_1

I just tested it on a random c file:

[sgillespie@SG-Arch01 cApps]$ make strTest
cc     strTest.c   -o strTest

Offline

#10 2005-09-13 14:09:38

awalk
Member
From: Perth, Western Australia
Registered: 2005-02-14
Posts: 40

Re: gcc hassling me (c++)

Well I'll be. I stand corrected smile

Offline

#11 2005-09-13 14:23:55

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Offline

#12 2005-09-13 16:02:37

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: gcc hassling me (c++)

Who says you don't learn something new everyday?

I stole that idea from phrakture who responded with this a long time ago on a similar question.

Offline

#13 2005-09-13 16:04:20

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: gcc hassling me (c++)

Euphoric Nightmare wrote:

Who says you don't learn something new everyday?

I stole that idea from phrakture who responded with this a long time ago on a similar question.

I remember that too but I could never get it to work....didn't realize you had to leave off the extension.

Offline

#14 2005-09-13 21:47:10

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: gcc hassling me (c++)

Yep, I figured that out earlier today.

It says that nothing can be done or something.

Offline

#15 2005-09-14 05:02:19

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: gcc hassling me (c++)

Penguin wrote:
Euphoric Nightmare wrote:

Who says you don't learn something new everyday?

I stole that idea from phrakture who responded with this a long time ago on a similar question.

I remember that too but I could never get it to work....didn't realize you had to leave off the extension.

Yeah, it's cool... but be careful with it... you almost always want to compile with -Wall, but "make myprog" won't do that.... unless you do "make CFLAGS=-Wall myprog"

Offline

Board footer

Powered by FluxBB