Understanding of the LGPL protocol

Source: Internet
Author: User
Tags wrappers

loaden:http://bbs.csdn.net/topics/330104257

http://devbean.blog.51cto.com/448512/313477

have been studying Qt recently. Qt has two licenses: LGPL and commercial agreements. The two protocols in the current QT version of the code is exactly the same (the latent meaning is that the earlier version of QT, the commercial version of QT usually contains some open source version of the library, such as qtsingleapplication this library). So now for ordinary developers and some commercial companies, using the LGPL version of Qt can save a lot of overhead. The biggest difference between the two versions is that the former is free and the latter is charged. Since the code is consistent, the cost will be to buy Qt after-sales service and training and other related services.

Now we're going to take a look at the copyright issue. LGPL is an open source protocol, so some people worry about whether LGPL can be used to develop closed-source programs that can be sold for money. Although some companies in the country do not attach great importance to this aspect of the problem, but if you violate the agreement, one day by someone else sent a letter of the lawyer, really is to cry no tears Oh. So, let's start by looking at this protocol, LGPL can be used to develop closed-source programs.

The following is my search for N multiple sites summed up, because the beans are not lawyers, so the LGPL agreement basically do not understand. How to understand this agreement, still want to be able to have professionals to speak out. Here is a way to do it! Although not very certain, but the understanding here is basically sorta.

As for what is the LGPL protocol, there is no more talk here, and our concern is if you use the LGPL protocol to develop a business program. Note that the closed-source program mentioned here means that the source code is not open in some form, that is, the user (including other developers) cannot obtain the source code of the program. First of all, the LGPL agreement is a business-friendly agreement. The implication here is that you can use the LGPL protocol to develop a business process, and of course it can be a non-commercial closed source program. However, it has some limitations. That's the point we're going to talk about.

Now that we have identified them, then we go directly to the topic: Using the LGPL protocol to develop the closed source program, if you use dynamic link form, then you can publish your application in any form, commercial, non-commercial, open source, non-open source, with you.

If for some reason you have to statically link a library that is published based on the LGPL protocol (we simply referred to as the LGPL library), then you are obligated to do the following:

1. You must indicate in your document that the LGPL library is used in your program and that the library is published based on LGPL;
2. You must include a copy of the LGPL agreement in your application release, usually the text file;
3. You must open all code that uses the LGPL library code, such as some wrappers. However, other code that uses these wrappers does not need to be open;
4. You must include the destination file for the remainder of your application (usually what we say. O, etc.), or other equivalent files. The source code is not required.

Isn't it hard to understand? Let's talk about it in detail.

The first one is easy to understand, and the second one is easy to understand, and you can find the contents of the LGPL protocol here, copy it and publish it with your program. The third one is not so well understood. To put it simply, the LGPL protocol requires that if your class uses the code of the LGPL library, you must open it up to this class. For example, if your program app.exe each source file with the code for the LGPL library, all your source code is open source. To avoid this, we usually write a wrapper that encapsulates the code of the LGPL library so that it only needs to open the wrapper's code, while the other code that uses the wrapper does not need to be open. Fourth is a supplement to the third article: those that use the wrapper do not need open source, but you have to open the intermediate files you compiled, Windows is those. o files.

You're wondering why the LGPL agreement is to be stipulated? LGPL's work is to ensure that the user has the ability to modify the way you use the LGPL library functions (those wrappers are the way you use the LGPL library, those that are open source), recompile the code, and then reconnect the program (the target files that are needed for the connection are also included. This is the fourth rule) and a new executable procedure can be obtained.

Well, if you don't understand how to use it, let's look at an example.

Suppose we use a library called Lib, which is published based on the LGPL protocol. If you use Lib.dll to do dynamic links (under Windows), OK, everything OK. Whatever your program, you can do what you do.

We mainly look at how you need to organize your code if you want to use static links. If you have a main.cpp (we assume that all Lib library functions are prefixed with the lib_):

1.//Main.cpp
2. int main () {
3. Lib_init ();
4. lib_do_something ();
5. Lib_done ();
6. Lib_close ();
7.
8. return 0;
9.}

Now that you've finished the main.cpp, you have to open it up! Because it uses the code of the LGPL library. This is stipulated in the third article above. I don't want to open it up, what do I do? Okay, we're building a new file. Lib_wrapper.cpp:

1. void My_lib_init ()
2. {
3. Lib_init ();
4.}
5.
6. void My_lib_do_something ()
7. {
8. lib_do_something ();
9.}
10.
One. void My_lib_done ()
12. {
Lib_done ();
14.}
15.
. void My_lib_close ()
17. {
Lib_close ();
19.}

In Main.cpp, we make the appropriate changes:

1. int main () {
2. My_lib_init ();
3. my_lib_do_something ();
4. My_lib_done ();
5. My_lib_close ();
6.
7. return 0;
8.}

Now, Main.cpp is no longer a direct use of the LGPL library code, so it does not need open source, and our wrapper lib_wrapper.cpp must be open source.

Well, compile our program and you will get MAIN.O (under Windows) this target file.

In the final program release, you need to include the file:

1. A document stating that: This program uses LIB library, which is published based on the LGPL protocol;
2. LGPL.txt;
3. Lib_wrapper.cpp
4. MAIN.O

In this way, users can change the way you use the LGPL library by modifying the contents of the Lib_wrapper.cpp, for example:

1. void My_lib_done ()
2. {
3. Lib_done ();
4. Lib_close ();
5.}
6.
7. void My_lib_close ()
8. {
9.//Lib_close ();
10.}

Then compile this lib_wrapper.cpp and eventually relink. A new executable program was born!

Well, that's what you need to follow to develop a closed source program using the LGPL library. Or suggest that you abide by the agreement and respect the work of the author of the results Oh ~

The attachment is a text file of the LGPL protocol.

Understanding of the LGPL protocol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.