GPL or LGPL for OCaml libraries?

Someone recently wrote me to know why I did put my ocaml-ssl library under GPL instead of LGPL. Since it's not the first time I'm asked this question, I decided to copy my answer here.

> Hello,
>
> your openssl-library is under GPL.
> Well, did you decide this, even though you know
> that libraries are often put under LGPL?
>
> What reasons did you have for putting the library under GPL, not LGPL?
> Did you think about LGPL?
> Why not using it?

Choosing between GPL and LGPL is a bit tough choice especially for OCaml projects.

In both cases what you basically say is that users can modify your library as long as the modified library stays under the same licence (well a LGPL library could also be made GPL) and therefore you ensure that your code will stay open source. The main difference between the two is that GPL is much more contaminating and therefore is a stronger advocate for open source.

If I make a program using a GPL library then my program must be under a licence which is compatible with GPL (e.g. GPL, LGPL, BSD or public domain), therefore open source. Moreover, the resulting program as a whole will be under GPL: this means if I put the code of my program under a BSD, the program as a whole will still be under GPL because I use a GPL library, however if someone takes only a file or a piece of code that I wrote for the program he'll be able to use it under the terms of the BSD. GPL contaminates the whole program but not the individual files.

The "problem" with GPL would be that it cannot be used in programs whose licence is not compatible with GPL, in proprietary programs in particular. This is ok if you're a strong advocate of open source. However the OCaml community is still very small and it needs to have many available libraries for all kind of applications (including commercial ones) if we want to see someday OCaml as a widely used programming language. Just think of all the libraries avalaible for C or perl for example.

This is why the LGPL has been made for. If your library is under LGPL, what is approximatively says is that your library is under the GPL terms excepting that it can be used in programs whose licence is not GPL-compatible. This means that a proprietary program can use your library but the source code of your library or any modification which has been done to your library must be released to the public (under the terms of the LGPL) if the program is distributed; but the source code of the program itself does not have to be made public.

Open source is interesting because users can make improvements to your library. This caracteristic would not be so true if an LGPL library was statically linked with a proprietary program for example, because you could not improve the library and benefit from those improvements in the proprietary program. That's why the LGPL also requires (clause 6.c) that any program using your library must provide some way for the users to use a modified version of the library whithin the program. Usually, this is done by using dynamically linked libraries: the code of the library is found at runtime and can be therefore changed (for ELF libraries you just have to replace the .so by a new, binary-compatible, .so).

The problem with OCaml is that it does not support dynamic linking very well which makes a LGPL almost the same as a GPL for a library (if you don't provide a mean to change a LGPLed library used by a program you must give the source code of the program or a way to relink the program)... The solution chosen by INRIA for the standard library of OCaml is to make a special exception to the LGPL which allows users to statically link libraries:

As a special exception to the GNU Library General Public License, you may link, statically or dynamically, a "work that uses the Library" with a publicly distributed version of the Library to produce an executable file containing portions of the Library, and distribute that executable file under terms of your choice, without any of the additional requirements listed in clause 6 of the GNU Library General Public License. By "a publicly distributed version of the Library", we mean either the unmodified Library as distributed by INRIA, or a modified version of the Library that is distributed under the conditions defined in clause 3 of the GNU Library General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU Library General Public License.

This solves the problem in a certain way but allows people to use your library without giving the opportunity to change the version used by the program and use a modified version of the library. I don't like this so much since having the right to modify a library is not very interesting if you can't have those modifications in programs that use the library. And since a LGPL without this exception is almost like a GPL, I chose GPL for ocaml-ssl to make things clear. My choice is not irrevocable though...