I'm writing a library which is a template-rich C++ library. All templated functions and classes are defined inside headers. It also has some non-templated functions, which are implemented inside headers and included in the program when a special macro is defined. I also want to offer a dynamic library (and possibly a static library too) with all non-templated functions and classes (included in the library source files from headers with the help of the preprocessor). I want to license it under GNU LGPLv3, but I'm not sure is that right.

As far as I know, LGPL is OK for header-only libraries. But what about dynamic and static linking?


Note that this answer is wrong, as pointed out by amon in the comments. It is mostly correct for LGPL2, but LGPL3 added a special header exemption in section 3 that allows redistribution of an application at any terms even if there are header files with significant logic in them.

I need to rewrite or delete the remaining answer. The rewritten answer will ask the question: "You don't get the freedom for the end users tor swap out your library, so why use LGPLv3 at all?" instead of "Do you want the consumer of library to require publishing their source code that interfaces with the library?".

You, the library author, can publish your library under any valid license, and as far as we know, the LPGL 3 is considered a valid license. The question you need to focus on is not "is the LGPL OK to use for <library of type x>", but instead "does the LGPL have the intended effect on <library of type x>".

The key point of the LGPL is (in my opinion), that the users of your library can use the library in non-(L)GPL products, so your library can get used in more places. At the same time, the LGPL ensures that the users of the product where your library is incorporated still have the the same freedom for working on the code of your library and using a modified version of your library as if this third-party product were GPL licensed. This means that authors of 3rd party products needs to make sure that users of these product can incorporate a modified version of the library. With C++ header-only libraries, the only way to switch out your library with a modified version of your library is recompiling the 3rd party application. In consequence, you force 3rd party authors to publish their source code if they want to legally use your library. You do not force 3rd party authors to publish their source code under an open source license, though.

So, the question you need to really think about is: Do you intend the effect that users of your library need to publish their source code, at least of the source files that interact with your library?

  • 1
    Header files have special status under section 3 of the LGPL v3. Their use will not force downstream users of the library to permit changes to the LGPL-covered parts, and will not force them to make their source available. For a header-only library, LGPLv3 is very similar to MIT.
    – amon
    Jan 13 '21 at 23:04
  • 1
    @amon Thanks for the comment. This shows my answer is wrong - I am going to correct it the next days. Jan 14 '21 at 7:02

You can definitely use LGPL 3 for both static and dynamic linking.

The way a program is "linked" to your library doesn't change the conceptual relationship between them - another author's application uses your library to perform some functionality. They are allowed to redistribute your library in order to perform this functionality but must state so, must note your copyright and must make the source available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.