[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Entry point i shared lib filer



Erwin S. Andreasen wrote:

Kasper Hauge <sslug@sslug> writes:

Hvordan gør man dette til Linux og gcc ??


void init() __attribute__((constructor));


void init() {
       printf("Hello world!\n");
}


Se mere i info gcc, led efter __attribute__. Det er dog gcc-specifikt.


I C++ kan du putte det i konstruktoren for en global variabel.


Nu har jeg prøvet alt !!! tror jeg. Jeg har fundet ud af at _init og _fini kun virker til C filer. I mit tilfælde er det C++, som skal være et shared lib. Når jeg prøver med __attribute__, som skulle være måden at gøre det på, virker det bare ikke.

Har du et eksemple der virker ??

Jeg har gjort sådan.

/* libtest.cpp */

#include <stdio.h>

void print_hello(void)
{
 printf("Hello Hauge\n");
}

void start () __attribute__ ((constructor));
void slut () __attribute__ ((destructor));


void start() { printf ("Start so\n\n"); }

void slut()
{
 printf ("Stop so\n\n");
}

coplilere sådan:
gcc -fPIC -O -c libtest.cpp

linker sådan:
gcc -shared -o libtest.so libtest.o


mit program som bruger dette shared lib ser sådan ud


/*test.cpp*/

#include "libtest.h"

int main (void)
{
 print_hello();
 return 0;
}

output er desværre kun

Hello Hauge

mvh
Kasper



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *