Question

I am building an application in C++ which uses sqlite3 as an embedded database. The source for sqlite3 is distributed as an amalgamated source code file sqlite3.c and two header files.

What are the relative advantages or disadvantages of linking the sqlite3 code directly into my program binary versus compiling sqlite3 as a static library and linking it in that way?

I have already decided against linking to the sqlite3 code as a dynamic library.

Was it helpful?

Solution

It really doesn't make much difference.
Assuming you have some sort of makefile environment the sqlite.c will only be built once if you don't change anything and the linker will combine the object file in almost the same way as plugging in a static library.

OTHER TIPS

Static library gets compiled into your program. Linking code directly gets compiled into your program. So it seems it's actually the same thing :) It might be easier to manage the project if you link it as static library since you'll have fewer source files. On the other hand if you need to make quick modifications to the library source files, it won't require rebuilding the static library. Ultimately it's up to you.

Here's a way of including sqlite3 in your library, without including any of the symbols in your library:

#define SQLITE_API static
#include <sqlite.h>
#include <sqlite.c>

Then you're guaranteed not to conflict with other implementations of sqlite that users of your library might link with.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top