_init , _fini and the qnx make tree

Hi,

I want to use “_init” and “_fini” entries in a shared library.
Using QNX’s make tree I get following error:

ntcan.o: In function _init': ntcan.o(.text+0x0): multiple definition of _init’
/x86/lib/crti.o(.init+0x0): first defined here
ntcan.o: In function _fini': ntcan.o(.text+0x28): multiple definition of _fini’
/x86/lib/crti.o(.fini+0x0): first defined here
cc: /usr/bin/ntox86-ld error 1



If I link the library with “ld” (qnx make-tree uses qcc), it workes for
x86.

If I try “ntoppc-ld” for the ppc version of the library, I get following
error:

ntoppc-ld: warning: powerpc:common architecture of input file ntcan.o' is incompatible with i386 output ntcan.o: In function _init’:
ntcan.o(.text+0x14): relocation truncated to fit: R_386_PC8
GLOBAL_OFFSET_TABLE
ntoppc-ld: final link failed: Bad value


Any suggestions?

You could try

#include <stdio.h>

void my_init(void) attribute((constructor));
void my_fini(void) attribute((destructor));

void my_init(void)
{
printf(“init!\n”);
}
void my_fini(void)
{
printf(“fini!\n”);
}

int main(void)
{
printf(“main!\n”);
return 0;
}

Michael Tasche <michael.tasche@esd-electronics.com> wrote:

Hi,

I want to use “_init” and “_fini” entries in a shared library.
Using QNX’s make tree I get following error:

ntcan.o: In function _init': ntcan.o(.text+0x0): multiple definition of _init’
/x86/lib/crti.o(.init+0x0): first defined here
ntcan.o: In function _fini': ntcan.o(.text+0x28): multiple definition of _fini’
/x86/lib/crti.o(.fini+0x0): first defined here
cc: /usr/bin/ntox86-ld error 1



If I link the library with “ld” (qnx make-tree uses qcc), it workes for
x86.

If I try “ntoppc-ld” for the ppc version of the library, I get following
error:

ntoppc-ld: warning: powerpc:common architecture of input file ntcan.o' is incompatible with i386 output ntcan.o: In function _init’:
ntcan.o(.text+0x14): relocation truncated to fit: R_386_PC8
GLOBAL_OFFSET_TABLE
ntoppc-ld: final link failed: Bad value



Any suggestions?


cburgess@qnx.com

Hi Colin,

it works.

Thank you very much
Michael


On 19 Sep 2003 16:03:59 GMT, Colin Burgess <cburgess@qnx.com> wrote:

You could try

#include <stdio.h

void my_init(void) attribute((constructor));
void my_fini(void) attribute((destructor));

void my_init(void)
{
printf(“init!\n”);
}
void my_fini(void)
{
printf(“fini!\n”);
}

int main(void)
{
printf(“main!\n”);
return 0;
}

Michael Tasche <> michael.tasche@esd-electronics.com> > wrote:
Hi,

I want to use “_init” and “_fini” entries in a shared library.
Using QNX’s make tree I get following error:

ntcan.o: In function _init': ntcan.o(.text+0x0): multiple definition of _init’
/x86/lib/crti.o(.init+0x0): first defined here
ntcan.o: In function _fini': ntcan.o(.text+0x28): multiple definition of _fini’
/x86/lib/crti.o(.fini+0x0): first defined here
cc: /usr/bin/ntox86-ld error 1



If I link the library with “ld” (qnx make-tree uses qcc), it workes for
x86.

If I try “ntoppc-ld” for the ppc version of the library, I get following
error:

ntoppc-ld: warning: powerpc:common architecture of input file ntcan.o' is incompatible with i386 output ntcan.o: In function _init’:
ntcan.o(.text+0x14): relocation truncated to fit: R_386_PC8
GLOBAL_OFFSET_TABLE
ntoppc-ld: final link failed: Bad value


Any suggestions?

Note that this doesn’t seem to work with C++ - in that case you could
use a static object to do the constructor/destructor thing.

Michael Tasche <michael.tasche@esd-electronics.com> wrote:

Hi Colin,

it works.

Thank you very much
Michael



On 19 Sep 2003 16:03:59 GMT, Colin Burgess <> cburgess@qnx.com> > wrote:

You could try

#include <stdio.h

void my_init(void) attribute((constructor));
void my_fini(void) attribute((destructor));

void my_init(void)
{
printf(“init!\n”);
}
void my_fini(void)
{
printf(“fini!\n”);
}

int main(void)
{
printf(“main!\n”);
return 0;
}

Michael Tasche <> michael.tasche@esd-electronics.com> > wrote:
Hi,

I want to use “_init” and “_fini” entries in a shared library.
Using QNX’s make tree I get following error:

ntcan.o: In function _init': ntcan.o(.text+0x0): multiple definition of _init’
/x86/lib/crti.o(.init+0x0): first defined here
ntcan.o: In function _fini': ntcan.o(.text+0x28): multiple definition of _fini’
/x86/lib/crti.o(.fini+0x0): first defined here
cc: /usr/bin/ntox86-ld error 1



If I link the library with “ld” (qnx make-tree uses qcc), it workes for
x86.

If I try “ntoppc-ld” for the ppc version of the library, I get following
error:

ntoppc-ld: warning: powerpc:common architecture of input file ntcan.o' is incompatible with i386 output ntcan.o: In function _init’:
ntcan.o(.text+0x14): relocation truncated to fit: R_386_PC8
GLOBAL_OFFSET_TABLE
ntoppc-ld: final link failed: Bad value


Any suggestions?
\


cburgess@qnx.com