• [^] # Re: En vrac

    Posté par . En réponse au journal Pourquoi empaqueter KDE prend-il du temps ?. Évalué à 2. Dernière modification le 20 août 2014 à 12:48.

    As-tu essayé d'encapsuler les include avec extern "C"?

    fichier hello.c:

    #include <stdio.h>
    int hello( int i, float j){puts("hello ");return 0;}

    hello.h:

    #ifndef HELLO_H
    #define HELLO_H
    extern int hello( int i, float j);
    #endif

    fichier world.c:

    #include <stdio.h>
    int world( int i, float j){puts("world! ");return 0;}

    world.h:

    #ifndef WORLD_H
    #define WORLD_H
    extern int world( int i, float j);
    #endif

    main.cpp:

    extern "C"
    {
    #include "hello.h"
    #include "world.h"
    }
    int main()
    {
     int (* pFoo) (int, float);
     pFoo=hello;
     pFoo(1,0.2);
     pFoo=world;
     pFoo(1,0.2);
     return 0;
    }

    compilation et exécution:

    $ gcc hello.c -shared -fPIC -o libhello.so
    $ gcc world.c -shared -fPIC -o libworld.so
    $ clang++ -L/tmp/tmp -o test main.cpp -lhello -lworld
    $ LD_LIBRARY_PATH=./ ./test
    hello 
    world!

    La même technique résout-elle ton problème? (j'ai utilisé Clang++ et non G++ pour le C++ pour le fun, en théorie ça ne change rien, c'était histoire d'utiliser 2 compilo, mais bon ils sont compatibles donc... mais j'ai rien d'autre sous la main.)

    En tout cas, ce PoC marche, si ton cas ne marche pas, encore une fois, poste un extrait de code, qu'on puisse te répondre sans être dans le brouillard.