Linking error in calling sbrk() function

  • Follow


Hi folks,

I had tried the sample c program for memory allocation in linux
platform (Red Hat 4.1.2-44) using g++ compiler version 4.1.2.
In that the following piece of code is throwing an linking error:
Code :
    intptr_t ab;
                 cp = sbrk (ab);
In my C program, I have included the header file called <unistd.h>
While compiling i tried all the following options:
===============================
g++ -g -o memoryallocation.o  -Wall     memoryallocation.cpp  -L/usr/
lib -lc

g++ -g -o memoryallocation.o  -Wall  -L/usr/lib -lc
memoryallocation.cpp

g++ -g -o memoryallocation.o  -Wall  memoryallocation.cpp

But the following Linking Error is not resolved.

/tmp/ccuZtrlB.o: In function `moreMemory':
/root/vinoth/memoryallocation.cpp:121: undefined reference to `sbrk
(int)'



Would you plz throw some light on this problem.


Regards
valagesan

-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply valagesan 9/25/2009 10:38:54 PM

valagesan wrote:

> I had tried the sample c program for memory allocation in linux

Firstly, this is a C++ newsgroup - you should really be asking C
questions in comp.lang.c or comp.lang.c.moderated.

> platform (Red Hat 4.1.2-44) using g++ compiler version 4.1.2.
> In that the following piece of code is throwing an linking error:
> Code :
>     intptr_t ab;
>                  cp = sbrk (ab);
> In my C program, I have included the header file called <unistd.h>
> While compiling i tried all the following options:
> ===============================
> g++ -g -o memoryallocation.o  -Wall     memoryallocation.cpp  -L/usr/
> lib -lc
> 
> g++ -g -o memoryallocation.o  -Wall  -L/usr/lib -lc
> memoryallocation.cpp
> 
> g++ -g -o memoryallocation.o  -Wall  memoryallocation.cpp

I don't know if it is an oversight, but you are compiling without the
the -c flag. This means that you will produce an executable called
memoryallocation.o, which is certainly not what you want and may explain
your problems. Your code compiles and links correctly for me with g++
4.1.0 on Fedora.

Neil Butterworth


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply Neil 9/26/2009 11:56:40 AM


1 Replies
526 Views

(page loaded in 0.08 seconds)

Similiar Articles:













7/21/2012 2:04:12 AM


Reply: