NiHoT
NiHoT

Reputation: 362

Building SQLite DLL with VS2015

I'm trying to build SQLite as a DLL from sources. In the the "How to" section of the website, they give a simple command line to build it :

cl sqlite3.c -link -dll -out:sqlite3.dll

When I try this command, I get the DLL but not the ".lib" file. With the DLL only I cannot use SQLite inside another dev project. Without the .lib file, there are some symbols missing.

Upvotes: 2

Views: 1053

Answers (2)

retif
retif

Reputation: 1652

For those trying to do this with CMake, and assuming that you are building from amalgamation sources, to produce the .lib file when building a shared variant on Windows you need to add a compile definition SQLITE_API=__declspec(dllexport), for example:

project("SQLite3"
    VERSION 3.39.1
    DESCRIPTION "Small, fast, self-contained, high-reliability, full-featured SQL database engine"
    LANGUAGES C
)

# ...

add_library(${PROJECT_NAME})

# ...

if(BUILD_SHARED_LIBS)
    if(WIN32)
        target_compile_definitions(${PROJECT_NAME}
           PRIVATE
               "SQLITE_API=__declspec(dllexport)"
        )
    else() # haven't tested that
        target_compile_definitions(${PROJECT_NAME}
           PRIVATE
               "SQLITE_API=__attribute__((visibility(\"default\")))"
        )
    endif()
endif()

# ...

Upvotes: 0

Grant Shannon
Grant Shannon

Reputation: 5075

here are some notes i made a while ago on creating a sqlite3.lib file using the contents of sqlitedll-X_X_X.zip (and some other files). This approach might differ from your intended approach - but it may get your project started - I hope it helps.

  1. create \tmp folder in your project directory
  2. find the following 3 files (on the web) and then copy them into the \tmp directory: lib.exe, link.exe, mspdb80.dll
  3. from the latest sqlitedll-X_X_X.zip file (i used: http://www.sqlite.org/sqlitedll-3_7_3.zip) copy sqlite3.def and sqlite3.dll to \tmp directory
  4. open command line (terminal) and navigate to \tmp directory
  5. create .LIB file by typing:

    LIB /DEF:sqlite3.def /MACHINE:X86

  6. copy the newly created sqlite3.lib file to your project directory

make sure that the following files are in the project directory:

also

  • add the sqlite3.h file to the project
  • make sure that the linker can see sqlite3.lib

Upvotes: 1

Related Questions