English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Shared libraries with ocamlopt callable from C (without main())?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-01-11 (16:28)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: [Caml-list] Shared libraries with ocamlopt callable from C (without main())?
> =====  $ cat ./main.c =====
>     #include <stdio.h>
>     #include "libadd5wrapper.h"
>     int main (int argc,char **argv){
>        printf("Gimme - %d \n", add5wrapper());

Should be add5wrapper(argv) -- as gcc's warnings told you.

>        return 0;
> }
> Now I try to BUILD the whole thing:
> [...]
> Number 4 is where it breaks. I get a ton of errors and this is where
> it ends for me. Because # 4 is also the point where I definitely have
> no idea what I'm doing.

Two things:

- You're not linking in add5-prog.o as far as I can see

- In static mode, the Unix linker is very picky about the relative
  order of -lxxx arguments on the command-line.  For more information,
  see the Info pages for GNU ld.  You probably don't need -static anyway.

The following works:

ocamlopt -output-obj add5.ml -o add5-prog.o
gcc -I`ocamlc -where` -c add5wrapperlib.c
gcc -c main.c
gcc -o mainprog.opt main.o add5wrapperlib.o add5-prog.o \
       -L`ocamlc -where` -lasmrun -ldl -lm

Add "-static" to the last line if you know you really need it.

Hope this puts you back on tracks.

- Xavier Leroy