-2

I have a decent understanding of C#. I've been asked to make a SDK along with our program so that a customer can make his own UI using our functions. In C#, I did this by adding a DLL. I had to use a database file (.db) to hold commands, and it went successfully. Now I've been asked to do the same in C++. I'm very new to C++. But here's what I read from MSDN and did:

  1. I created a library project.
  2. Added database as a resource file, sqlite3 header file and library file(I got from giving lib command on command prompt).
  3. Created a header file with functions and wrote in a .cpp file with all function definitions.
  4. Built it and got the library file from lib command.

So far, so good. Now when I try to use this library file and header, I'm getting the following errors during build time.

error C2059: syntax error : '<'
error C2018: unknown character '0x7'
error C2018: unknown character '0x60'
error C2018: unknown character '0x7'
error C2018: unknown character '0x2'
error C2018: unknown character '0x1e'
error C2018: unknown character '0x18'

I struggled with this for sometime when I remembered that these errors were the same I got a few days ago. I actually asked the question in SE and got the answer (Error while including database file in C++ project).

So I inferred that the compiler is trying to read the database file saved in the library file and hence I got these errors.

Now I have three questions:

  1. Am I right? Is the compiler trying to read the .db file stored in .lib file?
  2. If so, can anyone please give any suggestions
  3. Also, if you think I'm wrong, I would appreciate any other explanations.

I'm using Visual Express C++ 2010. I used command prompt that comes with Visual Studio to create .lib file. My reference for creating .lib file was https://msdn.microsoft.com/en-us/library/ms235627.aspx#BKMK_CreateAppToRefTheLib.

Community
  • 1
  • 1

1 Answers1

1

A database file cannot be stored in a static library file to be deployed. Because the compiler ALWAYS reads through the contents of the library. It shows that its reading this when you are building the program.

So what to do if you have to issue a database with your SDK? I have two solutions:

  1. Add database file with your .lib file and .h file and just flat out give a glossary of commands with the SDK. (I however do not advise this)
  2. Change the extension of database file and write methods in .lib file calling database using sqlite3 functions. Give the user a glossary of functions that you wrote with function names masked so that they dont know its a database file in play. The database file need not have .db extension for sqlite to recognize it. Just give sqlite_open and include database name as database.bhjbkhj (where bhjbkhj is a random extension you wrote). Sqlite is very good in this regard at recognising databases.

So there you go. Problem cannot be solved. But two alternatives.

Chris Baker
  • 49,926
  • 12
  • 96
  • 115