0

I have seen many questions on Stack Overflow like "how to include curlpp etc in Visual Studio?"

If we have the code of these libraries available online, why do people explicitly use .lib files to include to their projects when they can add the code directly to their project?

And I'm trying to achieve the above said thing for curlpp but I'm not successful, getting so many linker errors. Can someone suggest how to integrate the open source code directly which I wanted to do this even if this approach has drawbacks? Can you direct me to some blog post or steps to achieve this? And what are the drawbacks of this approach?

Edit: Compiling may not be a valid reason if I'm not dealing with large amount of code. And from users' point of view you still you have to distribute the binaries used by the project. Except the compilation factor and suppose the code is open source and there are no licensing issues, what can be the other drawbacks?

My main question is to know how to integrate such third party code directly.

Thanks for all drawbacks but I'm trying to experiment so can you guide me how to do this?

Biffen
  • 6,249
  • 6
  • 28
  • 36
Bad Sector
  • 37
  • 5
  • 1
    Because you don't have to recompile everything if you just use the library. You only have to link with it. Of course you may still need to recompile your code if the library and/or headers have changed. – Robinson Aug 17 '15 at 10:19
  • Not all libraries have such a trivial build system that you can easily integrate its source code directly into your own project. And some have a license that wouldn't allow it in some cases. – nos Aug 17 '15 at 10:20
  • 1
    as @Robinson said, recompilation takes time, and when your project grows, if you compile every single piece, it might take month/years/potato – Zaiborg Aug 17 '15 at 10:21

2 Answers2

0

For a lot of reasons. From the developer side:

  • you don't want to compile a lot of stuff if you have it already compiled by someone else
  • you don't want to download sources and compile them over and over again every time they get updated by the third party developer
  • you don't want your binaries to be larger than what they need
  • GPL linking exception and other possible licensing issues

From users side:

  • you don't want the same library to be hardcoded into several different program binaries (this would be a disk and memory waste)
Paolo M
  • 12,403
  • 6
  • 52
  • 73
  • yeah I don`t think libraries are compiled against all possible configurations and If you have to give it to the use you have to distribute with the dependency binaries as well. – Bad Sector Aug 17 '15 at 10:24
  • @BadSector You are forced to distribute libraries along with your binaries only on some systems. For example, if your system supports a package manager, you can just specify a dependency. Furthermore, if a library binary is not available for your target platform, a better approach would be to compile it separately from your project and then link to it. – Paolo M Aug 17 '15 at 10:28
  • I`m dealing with visual studio, so for visual studio nugget is the only feasible package manager and also it provides lib files compiled with /MD if I want /MT I have to create .lib file on my own. – Bad Sector Aug 17 '15 at 10:30
0

Libraries also help in: i. Componentization ii. Decoupling API's with implementations.

You also want to think of the cost of managing a monolith code. If you were to include the source code of libraries into the project, the well defined API boundaries will begin to fade over period of time.

Abhinav
  • 11
  • 3