This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Linking error


On Fri, Jun 15, 2012 at 12:39 PM, Rohit Arul Raj <rohitarulraj@gmail.com> wrote:
> On Fri, Jun 15, 2012 at 12:31 PM, naga raj <gnuuser.raj@gmail.com> wrote:
>> Thanks Ian for the reply.
>>
>> On Thu, Jun 14, 2012 at 10:23 PM, Ian Lance Taylor <iant@google.com> wrote:
>>> naga raj <gnuuser.raj@gmail.com> writes:
>>>
>>>> ? ? I am using arm compiler to run a simple c++ program
>>>>
>>>> ?#include <iostream>
>>>> ?#include <cstdlib>
>>>> ?using namespace std;
>>>>
>>>> ?int main(int argc, char* argv[])
>>>> ?{
>>>> ? ? ? ? ? ? ? ? cout <<"hi" <<endl;
>>>> ? ? ? ? ? ? ? ? return 0;
>>>> ? }
>>>>
>>>> ? It was compiled sucessfully but in linking it is throwing following errors
>>>>
>>>> ? arm-eabi-g++ -Wl,-T -Wl,../src/lscript.ld
>>>> -L../../empty_cpp_bsp_0/lib -o"empty_cpp_0.elf" ?./src/main.o
>>>> -Wl,--start-group,-llocal,-lgcc,-lc,-lstdc++,--end-group
>>>>
>>>> ../../empty_cpp_bsp_0/lib/liblocal.a(close.o): In function `close':
>>>> /proj/empty_cpp_bsp_0//libsrc/src/close.c:50: multiple definition of `close'
>>>> /bin/../lib/gcc/arm-eabi/4.6.1/../../../../arm-eabi/lib/libc.a(lib_a-sysclose.o):sysclose.c:(.text+0x0):
>>>> first defined here
>>>>
>>>> ../../empty_cpp_bsp_0/lib/liblocal.a(fstat.o): In function `fstat':
>>>> /proj/arm/empty_cpp_bsp_0/libsrc/src/fstat.c:51: multiple definition of `fstat'
>>>> /bin/../lib/gcc/arm-eabi/4.6.1/../../../../arm-eabi/lib/libc.a(lib_a-sysfstat.o):sysfstat.c:(.text+0x0):
>>>> first defined here
>>>> collect2: ld returned 1 exit status
>>>> make: *** [empty_cpp_0.elf] Error 1
>>>>
>>>> My requirement is to pick close() & fstat() functions from
>>>> /proj/empty_cpp_bsp_0/lib/liblocal.a not from
>>>> /bin/../lib/gcc/arm-eabi/4.6.1/../../../../arm-eabi/lib/libc.a
>>>>
>>>> I have included my local library with -L../../empty_cpp_bsp_0/lib..
>>>>
>>>> Can anyone please help me in fixing this compilation issue..
>>>
>>>
>>> This is really a library issue, and you didn't say anything about the
>>> libraries you are using.
>>
>> ? It is for a embedded target so we have developed our own libraries.
>> In our library close is just a dummy function it does nothing..
>>
>>> You can try using the option -Wl,foo.map and then looking in the foo.map
>>> file to see why the different objects are being included. ?That may
>>> suggest how to fix your libraries.
>>
>> ?From map file I found that close() function is called from libc of
>> toolchain and not from my local library. I dont know why it is still
>> refering close in local library.
>>
>> ?> Ian
>>
>> Thanks,
>> Nagaraju
>
> The linking order is from left to right.
> Try this ordering: -Wl,--start-group,-lgcc,-llocal,-lc,-lstdc++,--end-group
>
> -Rohit

Sorry, i didn't see your 'multiple definition' error. I assumed that
you wanted to pick your function definition from liblocal.a and not
from libc.a, so suggested re-ordering of libraries.

1. Check if the syscall library present in 'libc.a' is taken from
single object file. e.g. 'libsyscall.o' which contains definition of
all syscall objects (close.o, fstat.o, open.o etc..). This is because
even though the GNU linker will bring in only the objects it needs
from each library, it will bring in each object entirety. So if you
are using libc.a to link for other system calls (like open.o) which is
bundled with 'libsyscall.o', then the definition of close and fstat
will also get included as they are part of single object file
(libsyscall.o).

2. Alternatively, as your 'libc.a' is built with syscall support, you
can delete all the default syscall definitions provided by 'libc.a'
and build your own syscall library.
The list of syscall definitions to be provided for a bareboard system
is provided here:
http://sourceware.org/newlib/libc.html#Syscalls

Regards,
Rohit


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]