This is the mail archive of the
mailing list for the binutils project.
Re: Linking error
On Fri, Jun 15, 2012 at 12:39 PM, Rohit Arul Raj <email@example.com> wrote:
> On Fri, Jun 15, 2012 at 12:31 PM, naga raj <firstname.lastname@example.org> wrote:
>> Thanks Ian for the reply.
>> On Thu, Jun 14, 2012 at 10:23 PM, Ian Lance Taylor <email@example.com> wrote:
>>> naga raj <firstname.lastname@example.org> 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
>>>> ../../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'
>>>> 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'
>>>> 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
>>>> 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
> The linking order is from left to right.
> Try this ordering: -Wl,--start-group,-lgcc,-llocal,-lc,-lstdc++,--end-group
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
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: