Re: help with old source code from book

Discussion in 'C Programming' started by Mug, Aug 1, 2009.

  1. Mug

    Mug Guest

    On Aug 1, 12:56 am, superpollo <> wrote:
    > Richard Heathfield wrote:
    > > superpollo said:

    >
    > > <snip>

    >
    > >>and if i delete the offending #include <alloc.h> from the two files,
    > >>i get:

    >
    > >>$ gcc LIST2_1.C iplib.c
    > >>LIST2_1.C: In function `int main(int, char**)':
    > >>LIST2_1.C:53: warning: converting to `int' from `double'

    >
    > > Should be easy enough to determine whether or not that conversion is
    > > appropriate.

    >
    > >>LIST2_1.C:71: error: `free' undeclared (first use this function)

    >
    > > Well, that's easily fixed. Just add the appropriate header. For
    > > free(), that's <stdlib.h>

    >
    > i added the #include <stdlib.h> to LIST2_1.C, and:
    >
    > $ gcc LIST2_1.C iplib.c
    > LIST2_1.C: In function `int main(int, char**)':
    > LIST2_1.C:54: warning: converting to `int' from `double'
    > /tmp/ccIpyCSo.o(.text+0x5f): In function `main':
    > : warning: the `gets' function is dangerous and should not be used.
    > /tmp/ccIpyCSo.o(.text+0xae): In function `main':
    > : undefined reference to `read_pnm(char*, int*, int*, int*)'
    > /tmp/ccIpyCSo.o(.text+0x21c): In function `main':
    > : undefined reference to `write_pnm(unsigned char*, char*, int, int, int)'
    > /tmp/ccIpyCSo.o(.eh_frame+0x11): undefined reference to
    > `__gxx_personality_v0'
    > collect2: ld returned 1 exit status
    > $


    i have the same result,yet those functions are declared in iplib.c
     
    Mug, Aug 1, 2009
    #1
    1. Advertising

  2. Mug

    Mug Guest

    On Aug 1, 1:29 am, Beej Jorgensen <> wrote:
    > Mug  <> wrote:
    > >i have the same result,yet those functions are declared in iplib.c

    >
    > Funky.  I'd help out, but it compiles for me. :-/  With the
    > alloc.h/stdlib.h fixes:
    >
    > $ gcc -Wall list2_1.c iplib.c
    > iplib.c: In function 'getnum':
    > iplib.c:156: warning: suggest explicit braces to avoid ambiguous 'else'
    > /tmp/ccQIltLY.o: In function `main':
    > list2_1.c:(.text+0x7e): warning: the `gets' function is dangerous and
    > should not be used.
    >

    i got the same result,after changing LIST2_1.C to LIST2_1.c
    strange

    > $ gcc --version
    > gcc (GCC) 4.3.3
    >
    > Compiles in C99 mode, too.
    >
    > Maybe try:
    >
    > gcc -c LIST2_1.C
    > gcc -c iplib.c
    > gcc LIST2_1.o iplib.o
    >
    > not that it should make any difference.
    >
    > -Beej
     
    Mug, Aug 1, 2009
    #2
    1. Advertising

  3. Mug <> wrote:
    >i have the same result,yet those functions are declared in iplib.c


    Funky. I'd help out, but it compiles for me. :-/ With the
    alloc.h/stdlib.h fixes:

    $ gcc -Wall list2_1.c iplib.c
    iplib.c: In function 'getnum':
    iplib.c:156: warning: suggest explicit braces to avoid ambiguous 'else'
    /tmp/ccQIltLY.o: In function `main':
    list2_1.c:(.text+0x7e): warning: the `gets' function is dangerous and
    should not be used.

    $ gcc --version
    gcc (GCC) 4.3.3

    Compiles in C99 mode, too.

    Maybe try:

    gcc -c LIST2_1.C
    gcc -c iplib.c
    gcc LIST2_1.o iplib.o

    not that it should make any difference.

    -Beej
     
    Beej Jorgensen, Aug 1, 2009
    #3
  4. Gordon Burditt <> wrote:
    >*DECLARE* them all you want; but when you go to link the program
    >these functions have to be *DEFINED* somewhere.


    Terminology confusion on the part of the parent--the functions really
    are defined right there in iplib.c. I linked to them without a problem.

    -Beej
     
    Beej Jorgensen, Aug 1, 2009
    #4
  5. Mug <> wrote:
    >i got the same result,after changing LIST2_1.C to LIST2_1.c
    >strange


    Oh, blast from the past! Wasn't .C the old extension for C++ files?
    Maybe a name mangling issue, and probably explains the gxx_personality
    linker error.

    -Beej
     
    Beej Jorgensen, Aug 1, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Hill
    Replies:
    3
    Views:
    411
    Jim Hill
    Feb 12, 2007
  2. *Prot3anThr3ad*

    old repository for old C++ source code

    *Prot3anThr3ad*, Sep 29, 2006, in forum: C++
    Replies:
    6
    Views:
    390
    *Prot3anThr3ad*
    Oct 2, 2006
  3. John Henry
    Replies:
    24
    Views:
    1,027
    alex23
    May 30, 2008
  4. Mug
    Replies:
    2
    Views:
    365
    Nobody
    Aug 1, 2009
  5. Phil Carmody

    Re: [LONG] help with old source code from book

    Phil Carmody, Aug 3, 2009, in forum: C Programming
    Replies:
    2
    Views:
    348
    Phil Carmody
    Aug 3, 2009
Loading...

Share This Page