ocaml / flexdll

a dlopen-like API for Windows
Other
97 stars 30 forks source link

Get rid of flexdll #55

Closed skaller closed 4 years ago

skaller commented 6 years ago

It says in the notes that on Windows DLLs can't refer to symbols in the executable or previously loaded DLLs. The latter claim is not quite correct, it should say implicitly.

This is not actually a problem, it is correct behaviour and should NOT be fixed. Instead ocaml should be fixed. The issue is due to the historical development of Unix. Modern Unix linkers allow the archaic incorrect behaviour for compatibility but are moving away from it. OSX has moved well away and Linux is catching up with Windows too.

The correct way to link is to explicitly refer to a library. As mentioned, on Windows you have to link against a library to refer to its symbols because Windows actually uses a linker which has NO SUPPORT AT ALL for dynamic linkage. Windows always used a linker which could only do static linkage, so special import libraries are built which you link against instead. Calls to the symbols in the library trigger run time dynamic loading of a DLL and binding of the symbol at that time.

Linux and OSX also provide visibility control now and two level linkage, something that should have been enforced a long time ago. Unfortunately C and more recently C++ have impeded correcting the age old design fault. Still, it works right on OSX.

The question is: how can we build Ocaml correctly so we don't need flexdll? Currently I get the tiresome error "** Cannot resolve symbols for C:\ocaml\lib\libasmrun.lib(win32.obj): flexdll_wdlopen". I did have it working for Ocaml 4.02 but this is an upgrade someone built for Ocaml 4.06. "ocaml" works fine, the problem is only for ocamlopt.

dra27 commented 6 years ago

You appear to have a libasmrun.lib compiled against flexdll 0.36 or 0.37 but which you're then using on a system which has an older flexdll? We finally fixed the support on Windows for Unicode in 4.06.0 and it required a new symbol to be added to flexdll. Sorry about that.

More detail on your setup, and less detail of your wishes might help!

skaller commented 6 years ago

i wish i knew, i didn't build it. Its here:

https://github.com/felix-lang/win64ocaml

dra27 commented 6 years ago

Whoever committed it needed to clean the tree first - you've got manually installed flexdll 0.34 from your 2015 version left in bin (and presumably ocamlbuild from 4.02.3, etc) which will override the lib/flexdll objects from what, at least from the commit, looks like an msvc64 bootstrapped build.

skaller commented 6 years ago

so delete the flexdll stuff in bin?

skaller commented 6 years ago

Yep, that fixed it! Thanks! I'd still like to get rid of flexdll.

dra27 commented 4 years ago

It is possible to compile OCaml on Cygwin without FlexDLL (which disables all shared library support) and it is at present not possible to do that for the native Windows ports, which might be nice, if somewhat academic.

It's up to you if you want to transfer the issue to OCaml's issue tracker, but the issue here can be closed - FlexDLL isn't going anywhere while OCaml needs it (clearly).

I have found in previous discussions with other OCaml core devs that it's easy to have a rose-tinted view of what Windows OCaml was like pre-3.11 (i.e. when FlexDLL causes pain now, it turns out our memories have blocked out all the previous pain we used to suffer):

So I would humbly suggest that an issue on ocaml/ocaml may begin with "I would like to eliminate FlexDLL" but also needs to include at least a detailed description, if not also prototype implementation, which cleanly addresses those three points...

skaller commented 4 years ago

Ubuntu runs under Windows now, there is no reason to use Cygwin.

You may be right this is an issue for Ocaml list. There's no reason Ocaml can't generate code for Windows that allows loading C libraries at load time. The Windows linker ONLY supports static linkage. If you want to load a library dynamically you have to link to the .LIB file corresponding to the .DLL. So if you can do static linkage against C libraries you can do dynamic linkage because its the same. The only difference is exporting symbols from the C library is required to generate the *.LIB file.

dra27 commented 4 years ago

Great - then please feel free to close your issue and use Ubuntu! 🙂

skaller commented 4 years ago

I think you misunderstand. Ubuntu replaces Cygwin. Why use a Linux emulation when you can use actual Linux? [Actually it's not, but its miles closer than Cygwin]

It doesn't replace Windows. The issue for me isn't me building code for Windows. The issue is my client Windows programmers using my system with MSVC++, and my system happens to include a compiler that generates C++ for MSVC++ .. and the compiler is (unfortunately) written in Ocaml. The build and operation are 100% native Windows.

skaller commented 4 years ago

BTW: I do appreciate the pain that went into making flexdll. But really, being able to operate on Windows should have been the responsibility of the Ocaml developers. After all one of the original MAJOR features of Ocaml was that almost all the functions worked the same in Windows as Unix. It was actually easier than writing "portable" code in C or C++ to use Ocaml.

The problem I have is that my clients can't just install Ocaml. They have to install FlexDLL as well. And get them to work together. It's enough of an obstacle that most people give up. It's bad enough the main package manager doesn't work on Windows. I personally use a Mac for development, but my application is supposed to run on Linux and Windows (and iPhone) as well. And the compiler is a single statically linked executable that does not use ANY C libraries.

skaller commented 4 years ago

Sorry, it does do I/O so it uses Unix. It used to use BigNum but that got discarded breaking one of the third party packages I used. Then the immutable string fiasco broke another. Anyhow I will close the issue, you're right it's not your problem. Thanks for FlexDLL.

skaller commented 4 years ago

Sorry, it does do I/O so it uses Unix. It used to use BigNum but that got discarded breaking one of the third party packages I used. Then the immutable string fiasco broke another. Anyhow I will close the issue, you're right it's not your problem. Thanks for FlexDLL.