Création bibliothèque sous Linux
Bonsoir,
Je n'arrive pas à créer et utiliser une bibliothèque sous Linux. Voici mon code :
test.c :
Code:
1 2 3 4 5 6 7 8
|
#include "my_lib/testlib.h"
int main(void)
{
affichage("Hello World");
return 0;
} |
mylib/testlib.h :
Code:
1 2 3 4 5 6
|
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
extern int affichage(const char *message); |
mylib/testlic.c :
Code:
1 2 3 4 5 6 7 8
|
#include "stdio.h"
int affichage(const char *message)
{
int result=puts("Hello World\n");
return result;
} |
Je compile la bibliothèque comme ceci :
Code:
1 2 3 4
|
cd mylib
gcc -c -fPIC testlib.c
gcc -shared -Wl,-soname,mylib.so.1 testlib.o -o mylib.so.1 |
et pour le fichier test :
Code:
1 2
|
gcc -c test.c -l<chemin de ma bibliothèque> -o test |
La biliothèque semble ok (si j'utiloise objdump, je vois bien ma fonction affichage)
Par contre le fichier test compilé est un fichier ELF (file test retourne binen un format ELF), mais il est invalide.
ldd test me répond "n'est pas un executable dynamique".
Merci pour votre aide.