New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
callback from C to CAML #4847
Comments
Comment author: daweil NB : I put the issue in the wrong category, it is not a feature request but a blocking issue for migrating our software from 3.10 to 3.11 |
Comment author: @alainfrisch You'd better use flexlink to produce the main program. You also need to link Here is a working Makefile: include $(shell ocamlc -where)/Makefile.config byte: opt: |
Comment author: daweil Thanks for your fast answer. Now I want to do the next step that is required for our software : callback from C to CAML but but the CAML in a DLL. So I added the following target in the makefile you suggest : It fails with the following message : What's wrong ? The symbols "_caml_startup _fib _format_result" appears to be exporteed when I use the -show_exports option of flexlink |
Comment author: @alainfrisch The symbols are exported in the sense of flexdll. Since the DLL will be loaded in the main program directly (not with flexdll), through its import library, you need real DLL exports. You can achieve that by passing /def:XXX flags to the linker, or with a .def file, or by adding declspec(dllexport) directives to modwrap.c. For the .def file solution, you can create a file modwrap.def with those lines: EXPORTS And then the Makefile rule would be: bytedll: Note that I use here the new feature of OCaml that allows you to get a DLL directly (-output-obj X.dll). |
Comment author: daweil Thanks for your answer. I'm making progress. I'm able to make a dll containing caml code compiled in byte & native mode and link a main file to the .lib file exporting the symbols I want. Note that I put the wrapper outside the dll, it corresponds to the use case I have. Now, I would like to understand the other method which use flexdll to dynamically load my dll. I manage to compile but execution fails : ./mainflex.exe Can you explain what happen? |
Comment author: @alainfrisch Flexlink can really produce two very different kinds of DLLs:
The "-output-obj X.dll" feature of OCaml produces a regular DLL. If you want to produce a flexlink DLL, you need to produce the .obj yourself and use flexlink explictly. Also, since mainflex.c does not refer to OCaml headers, it seems better to call the C compiler directly. Here is a working Makefile, for both bytecode and native: byteflexdll: optflexdll: |
Comment author: daweil Thanks. All these examples works fine. I think you can close the issue. Will this makefile be include in the official caml documentation? |
Comment author: daweil It doesn't work on Windows 64bits. I found 2 issues.
|
Comment author: @alainfrisch I won't be able to look at (1) in the next two weeks. For (2), it is indeed the case that flexlink does not support COFF debugging information and there is little chance that it will be implemented (by myself). |
Comment author: daweil All these issues are only on 64 machines. For 2), the problem may be that I don't use the same version of compiler, so I should try again to recompile flexlink myself (I tried a few weeks ago but failed) |
Comment author: @xavierleroy I looked into (1) and I think I've diagnosed and fixed the problem. Still needs to be tested under Win64. Fix will go in 3.11.2. |
Original bug ID: 4847
Reporter: daweil
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2011-05-29T10:20:12Z)
Resolution: fixed
Priority: normal
Severity: major
Platform: Windows MSVC
OS: Windows XP
OS Version: Servica Pack3
Version: 3.11.1
Fixed in version: 3.11.2+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: daweil
Bug description
small example given in ocaml documentation at §18.8 works on ocaml3.10 and not on ocaml3.11.
What .obj or .lib is missing?
Could the Windows version of the example be described in the official Ocaml documentation?
PS : I use Microsoft Visual 2005
Steps to reproduce
unzip the attached file. type "make debug" or "make opt", observe the following message:
ocamlc -custom -output-obj -o modcaml.obj mod.ml
modcaml.c
ocamlc -c modwrap.c
modwrap.c
ocamlc -c main.c
main.c
cp C:/ProgramFiles/ocaml3.11.0/lib/libcamlrun.lib mod.lib
lib.exe mod.lib modcaml.obj modwrap.obj /out:modwrap.lib #E:/users/dwl/dev/R209/AUTdwlINFR209/AUTLciKernel/caml_src/flexdll-bin-0.19/*.obj
Microsoft (R) Library Manager Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.
link.exe modwrap.lib main.obj /out:main.exe
Microsoft (R) Incremental Linker Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.
modwrap.lib(win32.obj) : error LNK2019: unresolved external symbol _flexdll_dump_exports referenced in function _caml_dlopen
modwrap.lib(win32.obj) : error LNK2019: unresolved external symbol _flexdll_dlopen referenced in function _caml_dlopen
modwrap.lib(win32.obj) : error LNK2019: unresolved external symbol _flexdll_dlclose referenced in function _caml_dlclose
modwrap.lib(win32.obj) : error LNK2019: unresolved external symbol _flexdll_dlsym referenced in function _caml_dlsym
modwrap.lib(win32.obj) : error LNK2019: unresolved external symbol _flexdll_dlerror referenced in function _caml_dlerror
modwrap.lib(debugger.obj) : error LNK2019: unresolved external symbol _connect@12 referenced in function _open_connection
modwrap.lib(debugger.obj) : error LNK2019: unresolved external symbol _socket@12 referenced in function _open_connection
modwrap.lib(debugger.obj) : error LNK2019: unresolved external symbol _setsockopt@20 referenced in function _open_connection
modwrap.lib(debugger.obj) : error LNK2019: unresolved external symbol _getsockopt@20 referenced in function _open_connection
modwrap.lib(debugger.obj) : error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _winsock_startup
modwrap.lib(debugger.obj) : error LNK2019: unresolved external symbol _WSACleanup@0 referenced in function _winsock_cleanup
modwrap.lib(debugger.obj) : error LNK2019: unresolved external symbol _htons@4 referenced in function _caml_debugger_init
modwrap.lib(debugger.obj) : error LNK2019: unresolved external symbol _gethostbyname@4 referenced in function _caml_debugger_init
modwrap.lib(debugger.obj) : error LNK2019: unresolved external symbol _inet_addr@4 referenced in function _caml_debugger_init
main.exe : fatal error LNK1120: 14 unresolved externals
File attachments
The text was updated successfully, but these errors were encountered: