Should I link sqlite3 as simple object code or static library in a C ++ application?

I am creating a C ++ application that uses sqlite3 as an embedded database. The source for sqlite3 is distributed as a combined source file sqlite3.c

and two header files.

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

I've already decided not to reference the sqlite3 code as a dynamic library.

+2


source to share


3 answers


It really doesn't matter much.
Assuming you have some kind of makefile, sqlite.c will only be created once if you don't change anything, and the linker will merge the object file in much the same way as in a static library.



+3


source


The static library will compile into your program. The code link is directly compiled into your program. So it looks like it's actually the same :) It might be easier to manage the project if you linked it as a static library, since you will have fewer source files. On the other hand, if you need to make quick changes to the original library files, this does not require restoring the static library. Ultimately it depends on you.



+2


source


Here's how you can include sqlite3 in your library without including any symbols in your library:

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

      

Then you are guaranteed not to conflict with other sqlite implementations that users of your library may reference.

0


source







All Articles