SQLite function calls all have invalid arguments

791 views Asked by At

I'm trying to add the SQLite Amalgamation to my project. According to their page, I "Just copy the amalgamation into your source directory and compile it along with the other C code files in your project." I've also copied in sqlite3.h so I have access to the API.

However, any function call to the API, for instance:

sqlite3 *db;
int rc;

rc = sqlite3_open("test.db", &db);

results in the following error:

Invalid arguments '
Candidates are:
int sqlite3_open(const char *, * *) '

DataSettings.cpp
/FCS/src
line 24
Semantic Error

What am I doing wrong here? What have I neglected to set up?

1

There are 1 answers

0
John Bollinger On BEST ANSWER

The problem has the hallmarks of a name-mangling mismatch. Because C++ allows functions to be overloaded based on their argument types, C++ compilers must "mangle" function names they emit into object code to encode the argument types. C compilers do not do this, and do not expect it to be done to them. Specifying to a C++ compiler that a function has "C" linkage disables name mangling AND overloading of that function name; this is what extern "C" does.

Although C is similar in many ways to a subset of C++, the two are distinct languages. It is best to compile C code with a C compiler. One of your alternatives, therefore, is to build the C source of the sqlite amalgamation separately from your C++ code, into a library for instance, and link that with your C++ object files to produce the final executable.