0

I am currently working on a Raspberry Pi project that uses the OpenCV library, among others. The OpenCV library is quite large, and the build process for it is decently extensive. I found a script which downloads and installs the latest version of OpenCV, and following some suggestions from this question, I was able to build the library, and begin using the functions within OpenCV.

Considering the actual build process for OpenCV took considerably longer than building our project would, is it acceptable to just build the library once, as opposed to building the library each time we build our project?

While I realize this is probably personal preference, I am wondering how others handle situations similar to this.

Community
  • 1
  • 1
Aidan H.
  • 75
  • 6
  • 1
    if you dont change anything of that library it is completely valid to build it only once and don't include the library sources in your project at all (you normally dont do that even if you change library code, they should be kept separately). Just include the heades and link the binaries!! – Micka Jan 26 '15 at 15:52
  • 1
    I'm not sure I understand your question. Libraries are supposed to be built just once, that's why you use them as libraries.. – Svalorzen Jan 26 '15 at 15:52
  • @Svalorzen Right, but our build script for our project does not have any make calls or anything for the OpenCV library, so I guess it is just assuming the library is built and ready to go when it tries to link it. – Aidan H. Jan 26 '15 at 15:56
  • The sole purpose of libraries is just that: avoid building it every time you do a project build. If you use OpenCV for example, it's probably paramount to make sure you don't get any bleeding edge changes to the lib during the development cycle of your own product. Without any knowledge of your project's details, the right way to deal with that is likely to check out OpenCV from the project's repository once, keep it stable during your development cycle (even if there is a newer version available), release your revision and start again with an updated library version for your new version. – mfro Jan 26 '15 at 16:08
  • @AidanH. So add a sanity check to the build script? It does not need to build the whole OpenCV, but verifying that the files needed to build are there is a check that makes sense for a build tool. – Svalorzen Jan 26 '15 at 16:08
  • @mfro That makes perfect sense. I will look into pulling down OpenCV from their repo as opposed to running a script to install it. Thanks for the suggestions! – Aidan H. Jan 26 '15 at 16:44
  • @Svalorzen Currently we are just using make files to build the project. Shouldn't be terribly hard to put in a check to see if the OpenCV directory exists or maybe even specific header files. Thanks for the help! – Aidan H. Jan 26 '15 at 16:46

2 Answers2

3

As you probably already know, code that does not change does not need to be recompiled. This is true for executables and libraries alike.

A library is supposed to provide you addictional functionality in a neat, pre-packaged form. The difference between additional code you add to your project and a library is that the code included in a library is supposed to be in a stable state, so that once built the user will be able to use its features without any maintenance hassle; the APIs will be available and they will always work. You will be able to discard any implementation files, and just work with the header files - which provide you with the API within your code - and the library files, which contain the compiled implementation.

You are pretty much pre-compiling part of your program; a part that will also be able to be used in other projects, again without recompiling.

Note that C++ itself is an example of this: an implementation of the C++ standard library (for example libc++) is already included with your compiler, so that you are able to use the standard C++ headers without the need to recompile C++ whole every time you try a "Hello World!" program.

You can even extract libraries out of parts of your project that you feel are already completed and stable: this can allow you to reduce the time required to compile your project even though it becomes bigger. These reasons are part of why modularity is so strongly encouraged when programming.

TL; DR: Recompiling a library only once is not only acceptable, is most probably what you want to do.

Svalorzen
  • 5,353
  • 3
  • 30
  • 54
-2

It is normal to compile once and then only link the library. For that reason the compilers can detect whether there are changes in source files.

i486
  • 6,491
  • 4
  • 24
  • 41
  • 1
    which compilers do you mean can detect source changes?? they cannot! build tools (like make) can! – Géza Török Jan 26 '15 at 16:06
  • OK, this is function of IDE. But for example, Borland C++ IDE has integrated compiler. – i486 Jan 26 '15 at 19:19
  • Still, the compiler doesn't do so, even if it's integrated. Build management is always fairly isolated from compiling. – Géza Török Jan 27 '15 at 10:37
  • OK, it is not important which part exactly detects the changes. The result is - Compilation after change, not always. – i486 Jan 27 '15 at 10:46