问题描述:

What are the general differences between compiling a program as a static library

vs. including the source code into the program?

i.e. A program with functions that is compiled as a static library (.lib) and linked into the program vs A program with functions that is included as a source file in the main program.

Static libraries more suitable for release when releasing closed source programs?

Faster compilation? etc..

网友答案:

I'd advocate inclusion of source code because:

  1. Static library is more architecture depending than source code. You will need to compile it again and again.
  2. Optionally, source code allows more optimization than linking with a pre-compiled library.
  3. When examining the program it is always better to have possibility to see the source code than just a prototype.
网友答案:

As an already compiled executable file, basically there is no difference between them. I think the point is your purpose of software engineering.

If you are a component developer, static link libraries can keep your valuable source code secret. If you are making source code as business, it is probably very important.

Meanwhile, if you want people use your source code on any platform, you may want to release your modules as source code, as open source developers are doing.

网友答案:

The compilation would be faster when using a library, as you won't need to compile its code, but only to link it. But the most important gain turns around software architecture : making a library will offer you a way to write code that will be easier to reuse in future application. From Wikipedia :

The value of a library is the reuse of the behavior. When a program invokes a library, it gains the behavior implemented inside that library without having to implement that behavior itself. Libraries encourage the sharing of code in a modular fashion, and ease the distribution of the code.

网友答案:

Its generally a good idea to isolate piece of your software and convert it to a .lib or .dll file(or which ever suits your OS and your Executable Formats){No Repetition}.

Also, including the source code directly into your source file, makes the application bulky and, updating only small portion of code would require a rebuild of your executable and if you want your users to download and use the app, your users will not be happy with downloading the whole application file again.

Thirdly, as user3647458 said, if you are making money selling component code, then .lib file is what you would like to give your libraries off as(possibly for free).

相关阅读:
Top