Multiple definition of '__assert'

Till Straumann strauman at slac.stanford.edu
Mon Sep 12 18:32:07 UTC 2005


Camilo Alejandro Arboleda wrote:

> Looking at BSP sources, there is only one call to assert (in ne2000 
> driver), I'm going to try your recomendation and tell you the results.
>
> I don't know the linker internals, so there is a question that rise: 
> Why does it works when I put console.c in my project?

It depends on the order in which things are linked. If console.o has 
already been added to the link
when the linker looks for __assert it already has it and won't look for 
it in libc.

However, if the libc version gets linked first and 'console.o' is linked 
afterwards (note: in order to
satisfy another symbol, not __assert) the linker also finds __assert in 
'console.o' and then
does the sanity check (size comparison) which subsequently fails...

HTH
Till

>
>
>
> Till Straumann escribió:
>
>> Camilo Alejandro Arboleda wrote:
>>
>>> Hello,
>>>
>>> I worte to the list because of this problem, but there is no answer 
>>> (yet).
>>>
>>> I'm using rtems 4.6.2, with gcc 3.2.3 and newlib 1.1.13. When I try 
>>> to compile even a simple application agaist pc486 BSP I get an error 
>>> message telling there is a previous definition of __assert.  My 
>>> work-around was to copy console.c to my project directory, and 
>>> compiling it as part of my project.
>>>
>>> Has anybody the same problem? 
>>
>>
>>
>>
>> Yes. This is a bug. You should file a PR (after double-checking that 
>> no one
>> exists already). The PCx86 BSP provides its own version of __assert 
>> although
>> another implementation already comes with libc. The BSP's version 
>> (among other
>> things) uses 'printk' instead of 'printf' so that assert can be used 
>> from ISR context.
>>
>> My suggested fix would be eliminating the BSP-specific implementation 
>> from
>> console.c and removing 'assert' statements from interrupt handlers 
>> (pcx86 BSP).
>>
>>
>> HTH
>> -- Till
>>
>>> Any ideas or a cleaner work-around?
>>>
>>> The test program is
>>>
>>> | /* confdefs.h.  */
>>> |
>>> | #define PACKAGE_NAME ""
>>> | #define PACKAGE_TARNAME ""
>>> | #define PACKAGE_VERSION ""
>>> | #define PACKAGE_STRING ""
>>> | #define PACKAGE_BUGREPORT ""
>>> | /* end confdefs.h.  */
>>> |
>>> | int
>>> | main ()
>>> | {
>>> |
>>> |   ;
>>> |   return 0;
>>> | }
>>>
>>>
>>> and the error is:
>>>
>>>
>>> /usr/rtems-4.6/i386-rtems/pc486/lib/librtemsbsp.a(console.o): In
>>> function `__assert':
>>> /cygdrive/c/rtems/build-rtems/i386-rtems-4.6.2/i386-rtems/c/pc486/lib/libbsp/i386/pc386/console/../../../../../../../../../../rtems-4.6.2/c/src/lib/libbsp/i386/pc386/console/console.c:151: 
>>>
>>> multiple definition of `__assert'
>>> /cygdrive/c/cygwin/usr/rtems/i386-rtems/bin/../lib/gcc-lib/i386-rtems/3.2.3/../../../../i386-rtems/lib/libc.a(assert.o):/cygdrive/c/rtems/build-utils/gcc_3.2.3-i386/i386-rtems/newlib/libc/stdlib/../../../../../../source/gcc-3.2.3/newlib/libc/stdlib/assert.c:56: 
>>>
>>> first defined here
>>> /cygdrive/c/cygwin/usr/rtems/i386-rtems/bin/../lib/gcc-lib/i386-rtems/3.2.3/../../../../i386-rtems/bin/ld: 
>>>
>>> Warning: size of symbol `__assert' changed from 41 to 133 in
>>> /usr/rtems-4.6/i386-rtems/pc486/lib/librtemsbsp.a(console.o)
>>>
>>
>>




More information about the users mailing list