Tumba
Tumba

Reputation: 73

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

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.

Upvotes: 3

Views: 2988

Answers (3)

Erik Aronesty
Erik Aronesty

Reputation: 12887

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.

Upvotes: 1

ttvd
ttvd

Reputation: 1675

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.

Upvotes: 2

Martin Beckett
Martin Beckett

Reputation: 96109

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.

Upvotes: 4

Related Questions