caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] linking problem with camlidl on windows
@ 2003-07-18  6:43 matthieu.dubuget
  2003-07-18 13:16 ` Xavier Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: matthieu.dubuget @ 2003-07-18  6:43 UTC (permalink / raw)
  To: caml-list

Hello!

I posted a question some days ago, but it was not very precise.

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 ****

Here are the steps (*files are the 4 hand-written files):

                           
*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

Matthieu Dubuget


********** L'ADSL A 20 EUR/MOIS**********
Tiscali propose l'ADSL le moins cher du marché : 20 EUR/mois et le modem ADSL offert ! 
Pour profiter de cette offre exceptionnelle, cliquez ici : http://register.tiscali.fr/adsl/
Offre soumise à conditions.


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] linking problem with camlidl on windows
  2003-07-18  6:43 [Caml-list] linking problem with camlidl on windows matthieu.dubuget
@ 2003-07-18 13:16 ` Xavier Leroy
  0 siblings, 0 replies; 3+ messages in thread
From: Xavier Leroy @ 2003-07-18 13:16 UTC (permalink / raw)
  To: matthieu.dubuget; +Cc: caml-list

> I posted a question some days ago, but it was not very precise.
> 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.
> [...]
> 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?

You can go one step further this way:

link /dll /out:somme_stubs.dll /def:somme_stubs.def \
   somme_stubs.obj somme.lib \
   /libpath:"c:/ocaml/lib" libcamlidl.lib ocamlrun.lib ole32.lib

somme_stubs.obj references symbols from libcamlidl.lib, 
and libcamlidl.lib references symbols from the OCaml runtime system,
hence the need to link the import library for the latter, ocamlrun.lib.

However, you run into the problem with Windows DLLs that I described
in my message of yesterday:

libcamlidl.lib(idlalloc.obj) : error LNK2001: unresolved external 
symbol _local_roots

That is, libcamlidl.lib was compiled for static linking with the OCaml
runtime system, not for dynamic linking.  Import libraries bridge the
differences between static and dynamic linking in the case of
references to functions, but not in the case of references to global
variables such as "local_roots".

So, basically, you can't do what you want to do with the current
version of CamlIDL.  The CamlIDL library would need to be compiled as
a DLL itself for this to work.

> I did the same thing on linux and it worked fine.

Welcome to the wonderful world of Windows DLL :-)

- Xavier Leroy

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] linking problem with camlidl on windows
@ 2003-07-21  8:41 matthieu.dubuget
  0 siblings, 0 replies; 3+ messages in thread
From: matthieu.dubuget @ 2003-07-21  8:41 UTC (permalink / raw)
  To: caml-list

Thanks a lot for your explanation Xavier.

The DLL problem can be avoided to solve my problem by using
static linking. But I followed the other discussion (about
ocamlmklib on windows) with great interest. I think you took
this discussion off caml-list: I suggest that when it is
finished you post a digest if something interesting comes out.

Salutations

Matthieu Dubuget

********** L'ADSL A 20 EUR/MOIS**********
Tiscali propose l'ADSL le moins cher du marché : 20 EUR/mois et le modem ADSL offert ! 
Pour profiter de cette offre exceptionnelle, cliquez ici : http://register.tiscali.fr/adsl/
Offre soumise à conditions.


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-07-21  8:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-18  6:43 [Caml-list] linking problem with camlidl on windows matthieu.dubuget
2003-07-18 13:16 ` Xavier Leroy
2003-07-21  8:41 matthieu.dubuget

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).