Nitish Upreti
Nitish Upreti

Reputation: 6550

Do I need to wrap SQlite calls with extern "C" in my C++ application?

DO I need to wrap SQLite(http://www.sqlite.org/) library calls in my C++ application as :

extern "C" {    

    //Wrapping SQLite C header
    #include "sqlite3.h" 

    // Some example function definitions
    int sqlite3_open(const char *filename,sqlite3 **ppDb);
    void sqlite3_free(void*);
    int sqlite3_close(sqlite3*);
}

Or can I access the library directly (as most examples show in the website)? Would also love to know the reason behind the right answer.

Upvotes: 0

Views: 292

Answers (1)

user149341
user149341

Reputation:

sqlite3.h already includes an extern "C" wrapper. From the source:

/*
** Make sure we can call this stuff from C++.
*/
#ifdef __cplusplus
extern "C" {
#endif

…

#ifdef __cplusplus
}  /* end of the 'extern "C"' block */
#endif

As such, you don't need to wrap it yourself.

Upvotes: 2

Related Questions