Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

Browse thread
Use a DLL from ocaml: linking problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Matthieu Dubuget <matthieu.dubuget@m...>
Subject: Use a DLL from ocaml: linking problem
Hello!

I am trying to use one DLL from Ocaml with camlidl.

Since I can't have this work on windows (no problem under linux) because 
of linking problems, I reproduced it there.


There are 4 files :
somme.c, somme.def, somme.idl, somme_stubs.def

**** somme.c ****
#include "somme.h"

char * toto[3] = { "un", "deux", "trois" };

handle get(int indice){
return toto[indice];
}

char * string_of_handle(handle h){
return (char *) h;
}
**** somme.c ****
**** somme.def *****
EXPORTS
get
string_of_handle
**** somme.def *****

Here is the somme.idl file :

**** somme.idl ****
typedef [abstract] char * handle;

handle get([in] int indice);

[string] char * string_of_handle([in] handle h);
**** somme.idl ****
**** somme_stubs.def ****
EXPORTS
camlidl_somme_get
camlidl_somme_string_of_handle
**** somme_stubs.def ****

*somme.def|-3->somme.dll|-5->somme_stubs.dll
*somme.c|-2-> somme.obj| |
*somme.idl-1->|somme.h |
|somme_stubs.c-4-> somme_stubs.obj |
| *somme_stubs.def |
|somme.ml
|somme.mli

1/ ocamlidl -header somme.idl
2/ cl /c somme.c
3/ link /dll /out:somme.dll /def:somme.def somme.obj
4/ ocamlc -c somme_stubs.c

5/ Here is the step I cannot pass, because there are always unresolved 
external symbols. I cannot guess which library I should link? Is it 
possible that I made something wrong when installing camlidl?

FIRST TRY:
link /dll /out:somme_stubs.dll /def:somme_stubs.def somme_stubs.obj 
somme.lib
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Creating library somme_stubs.lib and object somme_stubs.exp
somme_stubs.obj : error LNK2001: unresolved external symbol _alloc
somme_stubs.obj : error LNK2001: unresolved external symbol _camlidl_free
somme_stubs.obj : error LNK2001: unresolved external symbol _copy_string
somme_stubs.dll : fatal error LNK1120: 3 unresolved externals

SECOND TRY (worse):
link /dll /out:somme_stubs.dll /def:somme_stubs.def somme_stubs.obj 
somme.lib /libpath:"c:/ocaml/lib" libcamlidl.lib
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Creating library somme_stubs.lib and object somme_stubs.exp
somme_stubs.obj : error LNK2001: unresolved external symbol _alloc
somme_stubs.obj : error LNK2001: unresolved external symbol _copy_string
libcamlidl.lib(idlalloc.obj) : error LNK2001: unresolved external symbol 
_invalid_argument
libcamlidl.lib(idlalloc.obj) : error LNK2001: unresolved external symbol 
_alloc_small
libcamlidl.lib(idlalloc.obj) : error LNK2001: unresolved external symbol 
_local_roots
libcamlidl.lib(idlalloc.obj) : error LNK2001: unresolved external symbol 
_stat_alloc
libcamlidl.lib(idlalloc.obj) : error LNK2001: unresolved external symbol 
_raise_out_of_memory
libcamlidl.lib(idlalloc.obj) : error LNK2001: unresolved external symbol 
__imp__CoTaskMemAlloc@4
libcamlidl.lib(idlalloc.obj) : error LNK2001: unresolved external symbol 
__imp__CoTaskMemFree@4
libcamlidl.lib(idlalloc.obj) : error LNK2001: unresolved external symbol 
_stat_free
libcamlidl.lib(idlalloc.obj) : error LNK2001: unresolved external symbol 
_string_length
somme_stubs.dll : fatal error LNK1120: 11 unresolved externals
NMAKE : fatal error U1077: 'link' : return code '0x460'
Stop.

COMMENTS:
I did the same thing on linux and it worked fine.
I did it with a simpler idl file on windows (without abstract type 
definition) and it worked too.

Where am I wrong ?

Thanks in advance