Windows static extension

Issue #13 resolved
petko created an issue

It is possible to configure CMake to generate static SQLite extension under Windows? I only see a hardcoded add_definitions(-DNU_DYNAMIC_EXTENSION) call in CMakeLists.txt for the extension.

Comments (12)

  1. Aleksey Tulinov repo owner

    There is no static SQLite extension target in CMake currently, but it should be possible to just compile nusqlite3.c as any other C-source file, link with it (and nunicode) and then call nunicode_sqlite3_static_init() somewhere in code.

  2. Aleksey Tulinov repo owner

    Check out sqlite3/samples/autoextension.c/sqlite3/samples/CMakeLists.txt for example.

  3. petko reporter

    Thanks, that will be probably what I will do. I was just curious if there is something possible currently. I am planning using your extension inside a library, which includes SQLite and other code, so that everything is in a single DLL.

  4. Aleksey Tulinov repo owner

    The reason why there is no static target is because such static library would contain a single object file (nusqlite3.c.o). So there is not a lot of value, in my opinion, to build such target, nusqlite3.c can be just added to a project and compiled along other files. But it's not hard to add this, for example:

    sqlite3/CMakeLists.txt

    include_directories(${CMAKE_SOURCE_DIR} ${SQLITE3_INCLUDE_DIR} ".")
    
    if(NU_BUILD_SAMPLES)
            add_subdirectory(samples)
    endif(NU_BUILD_SAMPLES)
    
    link_libraries(nu)
    add_library(nusqlite3-static STATIC nusqlite3.c)
    add_library(nusqlite3 SHARED nusqlite3.c)
    set_target_properties(nusqlite3 PROPERTIES COMPILE_DEFINITIONS NU_DYNAMIC_EXTENSION=1)
    

    sqlite3/samples/CMakeLists.txt

    link_libraries(nu sqlite3)
    add_executable(../autoextension autoextension.c)
    target_link_libraries(../autoextension nusqlite3-static)
    add_executable(../loadextension loadextension.c)
    

    And this produces libnusqlite3-static.a which is essentially nusqlite3.c.o ar'ed.

    Please let me know if there is any inconvenience with or without static SQLite3 extension, i'll keep this issue open for a while anyway.

  5. Aleksey Tulinov repo owner

    By the way, while checking autoextension, i've found that it segfaults on SQLite 3.23.0. I've updated extension for newer SQLite in 67e9dc4 (no other changes). If you want to try it, when you will probably need updated nusqlite3.c, it's on master: https://bitbucket.org/alekseyt/nunicode/src/master/sqlite3/nusqlite3.c, git pull will update it too if you have it cloned. It's going to be included into next release (this summer, around Unicode 11 release).

  6. petko reporter

    If I try to build the static nusqlite3, I get the following error in VC 2017: Error C2375 'sqlite3_nunicode_init': redefinition; different linkage nusqlite3-static ...\sqlite3\nusqlite3.c 496

  7. Aleksey Tulinov repo owner

    Sadly i don't have MSVC, so i can't check if it compiles or not with that compiler. You could try 66dfe6e, hopefully fixed.

  8. petko reporter

    Excellent! Everything seems to work OK now. Thank you very much!

    Could you please add the changes to the sqlite3/CMakeLists.txt above in the future commits?

  9. Aleksey Tulinov repo owner

    Glad to hear it works. I'll review all the changes later and add static target for SQLite extension if i won't come up with anything against it. I'll update this issue.

  10. Log in to comment