From 25ab3ce1c27373c799b28a578a44017ec08660ff Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Fri, 3 Feb 2023 18:27:21 +1100 Subject: [PATCH 01/10] Add dll export/import macros --- CMakeLists.txt | 5 +++++ include/SQLiteCpp/Backup.h | 3 ++- include/SQLiteCpp/Column.h | 15 ++++++++------- include/SQLiteCpp/Database.h | 23 ++++++++++++----------- include/SQLiteCpp/Exception.h | 3 ++- include/SQLiteCpp/SQLiteCpp.h | 3 +++ include/SQLiteCpp/SQLiteCppExport.h | 29 +++++++++++++++++++++++++++++ include/SQLiteCpp/Savepoint.h | 3 ++- include/SQLiteCpp/Statement.h | 3 ++- include/SQLiteCpp/Transaction.h | 3 ++- 10 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 include/SQLiteCpp/SQLiteCppExport.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5964791..16f7fc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,11 @@ endif () message(STATUS "Using c++ standard c++${CMAKE_CXX_STANDARD}") set(CMAKE_CXX_STANDARD_REQUIRED ON) +option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ON) +if(BUILD_SHARED_LIBS) +add_definitions(-DSQLITECPP_COMPILE_DLL -DSQLITECPP_EXPORT) +endif() + message (STATUS "CMake version: ${CMAKE_VERSION}") message (STATUS "Project version: ${PROJECT_VERSION}") diff --git a/include/SQLiteCpp/Backup.h b/include/SQLiteCpp/Backup.h index 578f21f..ecdd847 100644 --- a/include/SQLiteCpp/Backup.h +++ b/include/SQLiteCpp/Backup.h @@ -11,6 +11,7 @@ */ #pragma once +#include #include #include @@ -31,7 +32,7 @@ namespace SQLite * See also the a reference implementation of live backup taken from the official site: * https://www.sqlite.org/backup.html */ -class Backup +class DLL_API Backup { public: /** diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index 8fee096..21bd9d3 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -10,6 +10,7 @@ */ #pragma once +#include #include #include @@ -22,11 +23,11 @@ struct sqlite3_stmt; namespace SQLite { -extern const int INTEGER; ///< SQLITE_INTEGER -extern const int FLOAT; ///< SQLITE_FLOAT -extern const int TEXT; ///< SQLITE_TEXT -extern const int BLOB; ///< SQLITE_BLOB -extern const int Null; ///< SQLITE_NULL +DLL_API extern const int INTEGER; ///< SQLITE_INTEGER +DLL_API extern const int FLOAT; ///< SQLITE_FLOAT +DLL_API extern const int TEXT; ///< SQLITE_TEXT +DLL_API extern const int BLOB; ///< SQLITE_BLOB +DLL_API extern const int Null; ///< SQLITE_NULL /** * @brief Encapsulation of a Column in a row of the result pointed by the prepared Statement. @@ -44,7 +45,7 @@ extern const int Null; ///< SQLITE_NULL * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class Column +class DLL_API Column { public: /** @@ -241,7 +242,7 @@ private: * * @return Reference to the stream used */ -std::ostream& operator<<(std::ostream& aStream, const Column& aColumn); +DLL_API std::ostream& operator<<(std::ostream& aStream, const Column& aColumn); #if __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900) // c++14: Visual Studio 2015 diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index 3adde86..8408048 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -10,6 +10,7 @@ */ #pragma once +#include #include // c++17: MinGW GCC version > 8 @@ -84,26 +85,26 @@ namespace SQLite // Those public constants enable most usages of SQLiteCpp without including in the client application. /// The database is opened in read-only mode. If the database does not already exist, an error is returned. -extern const int OPEN_READONLY; // SQLITE_OPEN_READONLY +DLL_API extern const int OPEN_READONLY; // SQLITE_OPEN_READONLY /// The database is opened for reading and writing if possible, or reading only if the file is write protected /// by the operating system. In either case the database must already exist, otherwise an error is returned. -extern const int OPEN_READWRITE; // SQLITE_OPEN_READWRITE +DLL_API extern const int OPEN_READWRITE; // SQLITE_OPEN_READWRITE /// With OPEN_READWRITE: The database is opened for reading and writing, and is created if it does not already exist. -extern const int OPEN_CREATE; // SQLITE_OPEN_CREATE +DLL_API extern const int OPEN_CREATE; // SQLITE_OPEN_CREATE /// Enable URI filename interpretation, parsed according to RFC 3986 (ex. "file:data.db?mode=ro&cache=private") -extern const int OPEN_URI; // SQLITE_OPEN_URI +DLL_API extern const int OPEN_URI; // SQLITE_OPEN_URI /// Open in memory database -extern const int OPEN_MEMORY; // SQLITE_OPEN_MEMORY +DLL_API extern const int OPEN_MEMORY; // SQLITE_OPEN_MEMORY /// Open database in multi-thread threading mode -extern const int OPEN_NOMUTEX; // SQLITE_OPEN_NOMUTEX +DLL_API extern const int OPEN_NOMUTEX; // SQLITE_OPEN_NOMUTEX /// Open database with thread-safety in serialized threading mode -extern const int OPEN_FULLMUTEX; // SQLITE_OPEN_FULLMUTEX +DLL_API extern const int OPEN_FULLMUTEX; // SQLITE_OPEN_FULLMUTEX /// Open database with shared cache enabled -extern const int OPEN_SHAREDCACHE; // SQLITE_OPEN_SHAREDCACHE +DLL_API extern const int OPEN_SHAREDCACHE; // SQLITE_OPEN_SHAREDCACHE /// Open database with shared cache disabled -extern const int OPEN_PRIVATECACHE; // SQLITE_OPEN_PRIVATECACHE +DLL_API extern const int OPEN_PRIVATECACHE; // SQLITE_OPEN_PRIVATECACHE /// Database filename is not allowed to be a symbolic link (Note: only since SQlite 3.31.0 from 2020-01-22) -extern const int OPEN_NOFOLLOW; // SQLITE_OPEN_NOFOLLOW +DLL_API extern const int OPEN_NOFOLLOW; // SQLITE_OPEN_NOFOLLOW extern const int OK; ///< SQLITE_OK (used by check() bellow) @@ -160,7 +161,7 @@ struct Header { * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class Database +class DLL_API Database { friend class Statement; // Give Statement constructor access to the mSQLitePtr Connection Handle diff --git a/include/SQLiteCpp/Exception.h b/include/SQLiteCpp/Exception.h index eaf2542..e771dce 100644 --- a/include/SQLiteCpp/Exception.h +++ b/include/SQLiteCpp/Exception.h @@ -10,6 +10,7 @@ */ #pragma once +#include #include #include @@ -23,7 +24,7 @@ namespace SQLite /** * @brief Encapsulation of the error message from SQLite3, based on std::runtime_error. */ -class Exception : public std::runtime_error +class DLL_API Exception : public std::runtime_error { public: /** diff --git a/include/SQLiteCpp/SQLiteCpp.h b/include/SQLiteCpp/SQLiteCpp.h index c8d1801..e3b7448 100644 --- a/include/SQLiteCpp/SQLiteCpp.h +++ b/include/SQLiteCpp/SQLiteCpp.h @@ -18,6 +18,7 @@ // Include useful headers of SQLiteC++ +#include #include #include #include @@ -42,3 +43,5 @@ */ #define SQLITECPP_VERSION "3.02.01" // 3.2.1 #define SQLITECPP_VERSION_NUMBER 3002001 // 3.2.1 + + diff --git a/include/SQLiteCpp/SQLiteCppExport.h b/include/SQLiteCpp/SQLiteCppExport.h new file mode 100644 index 0000000..7242c9d --- /dev/null +++ b/include/SQLiteCpp/SQLiteCppExport.h @@ -0,0 +1,29 @@ +/** + * @file SQLiteCppExport.h + * @ingroup SQLiteCpp + * @brief File with macros needed in the generation of Windows DLLs + * + * + * Copyright (c) 2012-2022 Sebastien Rombauts (sebastien.rombauts@gmail.com) + * + * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt + * or copy at http://opensource.org/licenses/MIT) + */ + +#pragma once + +/* +* #define SQLITECPP_COMPILE_DLL to compile a DLL under Windows +* #define SQLITECPP_EXPORT to export symbols when creating the DLL, otherwise it defaults to importing symbols +*/ + +/* Windows DLL export/import */ +#if defined(WIN32) && defined(SQLITECPP_COMPILE_DLL) + #ifdef SQLITECPP_EXPORT + #define DLL_API __declspec(dllexport) + #pragma message("Exporting symbols") + #else + #define DLL_API __declspec(dllimport) + #pragma message("Importing symbols") + #endif +#endif diff --git a/include/SQLiteCpp/Savepoint.h b/include/SQLiteCpp/Savepoint.h index 0c0fba6..8a5d845 100644 --- a/include/SQLiteCpp/Savepoint.h +++ b/include/SQLiteCpp/Savepoint.h @@ -12,6 +12,7 @@ */ #pragma once +#include #include namespace SQLite @@ -53,7 +54,7 @@ class Database; * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class Savepoint +class DLL_API Savepoint { public: /** diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index e14fed0..dfdcd97 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -10,6 +10,7 @@ */ #pragma once +#include #include #include // SQLITECPP_PURE_FUNC @@ -49,7 +50,7 @@ extern const int OK; ///< SQLITE_OK * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class Statement +class DLL_API Statement { public: /** diff --git a/include/SQLiteCpp/Transaction.h b/include/SQLiteCpp/Transaction.h index af9de7e..77a3235 100644 --- a/include/SQLiteCpp/Transaction.h +++ b/include/SQLiteCpp/Transaction.h @@ -10,6 +10,7 @@ */ #pragma once +#include #include @@ -50,7 +51,7 @@ enum class TransactionBehavior { * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class Transaction +class DLL_API Transaction { public: /** From e3fc62dd35bdbe07baee9577b194d606b2ef741f Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Mon, 6 Feb 2023 13:19:57 +1100 Subject: [PATCH 02/10] More fixes, should be working now --- CMakeLists.txt | 9 +++++++-- include/SQLiteCpp/SQLiteCppExport.h | 6 ++++-- sqlite3/CMakeLists.txt | 12 ++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16f7fc4..0282847 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,9 +17,14 @@ endif () message(STATUS "Using c++ standard c++${CMAKE_CXX_STANDARD}") set(CMAKE_CXX_STANDARD_REQUIRED ON) -option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ON) if(BUILD_SHARED_LIBS) -add_definitions(-DSQLITECPP_COMPILE_DLL -DSQLITECPP_EXPORT) + if(WIN32) + message("defining SQLITECPP_COMPILE_DLL") + add_definitions("-DSQLITECPP_COMPILE_DLL") + if(SQLITECPP_DLL_EXPORT) + add_definitions("-DSQLITECPP_DLL_EXPORT") + endif() + endif() endif() message (STATUS "CMake version: ${CMAKE_VERSION}") diff --git a/include/SQLiteCpp/SQLiteCppExport.h b/include/SQLiteCpp/SQLiteCppExport.h index 7242c9d..63d1e0f 100644 --- a/include/SQLiteCpp/SQLiteCppExport.h +++ b/include/SQLiteCpp/SQLiteCppExport.h @@ -19,11 +19,13 @@ /* Windows DLL export/import */ #if defined(WIN32) && defined(SQLITECPP_COMPILE_DLL) - #ifdef SQLITECPP_EXPORT + #if defined(SQLITECPP_DLL_EXPORT) #define DLL_API __declspec(dllexport) #pragma message("Exporting symbols") #else #define DLL_API __declspec(dllimport) #pragma message("Importing symbols") - #endif + #endif +#else + #define DLL_API #endif diff --git a/sqlite3/CMakeLists.txt b/sqlite3/CMakeLists.txt index 0efc3ee..ef222e9 100644 --- a/sqlite3/CMakeLists.txt +++ b/sqlite3/CMakeLists.txt @@ -11,6 +11,18 @@ add_library(sqlite3 sqlite3.h ) +if(WIN32) + if(BUILD_SHARED_LIBS) + if(SQLITECPP_DLL_EXPORT) + message("Adding __declspec(dllexport)") + add_definitions("-DSQLITE_API=__declspec(dllexport)") + else() + message("Adding __declspec(dllimport)") + add_definitions("-DSQLITE_API=__declspec(dllimport)") + endif() + endif() +endif() + add_library(SQLite::SQLite3 ALIAS sqlite3) target_include_directories(sqlite3 From f2253419b295527a44761952af386db178909195 Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Mon, 6 Feb 2023 14:59:35 +1100 Subject: [PATCH 03/10] Incorrect include --- include/SQLiteCpp/SQLiteCpp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SQLiteCpp/SQLiteCpp.h b/include/SQLiteCpp/SQLiteCpp.h index e3b7448..94751b6 100644 --- a/include/SQLiteCpp/SQLiteCpp.h +++ b/include/SQLiteCpp/SQLiteCpp.h @@ -18,7 +18,7 @@ // Include useful headers of SQLiteC++ -#include +#include #include #include #include From 14cba69a33a9f4a16513cab8b1bfa3c29feeb2a0 Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Mon, 6 Feb 2023 19:43:35 +1100 Subject: [PATCH 04/10] Now working with example --- CMakeLists.txt | 23 +++++++++++++---------- include/SQLiteCpp/Database.h | 12 ++++++------ include/SQLiteCpp/SQLiteCppExport.h | 7 ++++++- include/SQLiteCpp/Statement.h | 2 +- sqlite3/CMakeLists.txt | 6 ------ src/Column.cpp | 10 +++++----- src/Database.cpp | 29 ++++++++++++++--------------- 7 files changed, 45 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0282847..3d94b4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,16 +17,6 @@ endif () message(STATUS "Using c++ standard c++${CMAKE_CXX_STANDARD}") set(CMAKE_CXX_STANDARD_REQUIRED ON) -if(BUILD_SHARED_LIBS) - if(WIN32) - message("defining SQLITECPP_COMPILE_DLL") - add_definitions("-DSQLITECPP_COMPILE_DLL") - if(SQLITECPP_DLL_EXPORT) - add_definitions("-DSQLITECPP_DLL_EXPORT") - endif() - endif() -endif() - message (STATUS "CMake version: ${CMAKE_VERSION}") message (STATUS "Project version: ${PROJECT_VERSION}") @@ -223,6 +213,13 @@ if (SQLITE_USE_LEGACY_STRUCT) target_compile_definitions(SQLiteCpp PUBLIC SQLITE_USE_LEGACY_STRUCT) endif (SQLITE_USE_LEGACY_STRUCT) +if(BUILD_SHARED_LIBS) + if(WIN32) + add_definitions("-DSQLITECPP_COMPILE_DLL") + target_compile_definitions(SQLiteCpp PRIVATE "SQLITECPP_DLL_EXPORT=1") + endif() +endif() + option(SQLITE_OMIT_LOAD_EXTENSION "Enable omit load extension" OFF) if (SQLITE_OMIT_LOAD_EXTENSION) # Enable the user definition of load_extension(). @@ -412,8 +409,14 @@ endif (SQLITECPP_RUN_DOXYGEN) option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF) if (SQLITECPP_BUILD_EXAMPLES) + # add the basic example executable add_executable(SQLiteCpp_example1 ${SQLITECPP_EXAMPLES}) + if(BUILD_SHARED_LIBS) + if(WIN32) + target_compile_definitions(SQLiteCpp_example1 PRIVATE "SQLITECPP_DLL_EXPORT=0") + endif() + endif() target_link_libraries(SQLiteCpp_example1 SQLiteCpp) if (MSYS OR MINGW) target_link_libraries(SQLiteCpp_example1 ssp) diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index 8408048..7d34988 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -107,15 +107,15 @@ DLL_API extern const int OPEN_PRIVATECACHE; // SQLITE_OPEN_PRIVATECACHE DLL_API extern const int OPEN_NOFOLLOW; // SQLITE_OPEN_NOFOLLOW -extern const int OK; ///< SQLITE_OK (used by check() bellow) +DLL_API extern const int OK; ///< SQLITE_OK (used by check() bellow) -extern const char* const VERSION; ///< SQLITE_VERSION string from the sqlite3.h used at compile time -extern const int VERSION_NUMBER; ///< SQLITE_VERSION_NUMBER from the sqlite3.h used at compile time +DLL_API extern const char* const VERSION; ///< SQLITE_VERSION string from the sqlite3.h used at compile time +DLL_API extern const int VERSION_NUMBER; ///< SQLITE_VERSION_NUMBER from the sqlite3.h used at compile time /// Return SQLite version string using runtime call to the compiled library -const char* getLibVersion() noexcept; +DLL_API const char* getLibVersion() noexcept; /// Return SQLite version number using runtime call to the compiled library -int getLibVersionNumber() noexcept; +DLL_API int getLibVersionNumber() noexcept; // Public structure for representing all fields contained within the SQLite header. // Official documentation for fields: https://www.sqlite.org/fileformat.html#the_database_header @@ -266,7 +266,7 @@ public: // Deleter functor to use with smart pointers to close the SQLite database connection in an RAII fashion. struct Deleter { - void operator()(sqlite3* apSQLite); + DLL_API void operator()(sqlite3* apSQLite); }; /** diff --git a/include/SQLiteCpp/SQLiteCppExport.h b/include/SQLiteCpp/SQLiteCppExport.h index 63d1e0f..c6322bb 100644 --- a/include/SQLiteCpp/SQLiteCppExport.h +++ b/include/SQLiteCpp/SQLiteCppExport.h @@ -19,7 +19,7 @@ /* Windows DLL export/import */ #if defined(WIN32) && defined(SQLITECPP_COMPILE_DLL) - #if defined(SQLITECPP_DLL_EXPORT) + #if SQLITECPP_DLL_EXPORT #define DLL_API __declspec(dllexport) #pragma message("Exporting symbols") #else @@ -29,3 +29,8 @@ #else #define DLL_API #endif + +#if defined(WIN32) && defined(SQLITECPP_COMPILE_DLL) + #pragma warning( disable : 4251 ) + #pragma warning( disable : 4275 ) +#endif diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index dfdcd97..bddc369 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -31,7 +31,7 @@ namespace SQLite class Database; class Column; -extern const int OK; ///< SQLITE_OK +DLL_API extern const int OK; ///< SQLITE_OK /** * @brief RAII encapsulation of a prepared SQLite Statement. diff --git a/sqlite3/CMakeLists.txt b/sqlite3/CMakeLists.txt index ef222e9..b3dc73a 100644 --- a/sqlite3/CMakeLists.txt +++ b/sqlite3/CMakeLists.txt @@ -13,13 +13,7 @@ add_library(sqlite3 if(WIN32) if(BUILD_SHARED_LIBS) - if(SQLITECPP_DLL_EXPORT) - message("Adding __declspec(dllexport)") add_definitions("-DSQLITE_API=__declspec(dllexport)") - else() - message("Adding __declspec(dllimport)") - add_definitions("-DSQLITE_API=__declspec(dllimport)") - endif() endif() endif() diff --git a/src/Column.cpp b/src/Column.cpp index 60b3c3b..ec7c64d 100644 --- a/src/Column.cpp +++ b/src/Column.cpp @@ -18,11 +18,11 @@ namespace SQLite { -const int INTEGER = SQLITE_INTEGER; -const int FLOAT = SQLITE_FLOAT; -const int TEXT = SQLITE_TEXT; -const int BLOB = SQLITE_BLOB; -const int Null = SQLITE_NULL; +DLL_API const int INTEGER = SQLITE_INTEGER; +DLL_API const int FLOAT = SQLITE_FLOAT; +DLL_API const int TEXT = SQLITE_TEXT; +DLL_API const int BLOB = SQLITE_BLOB; +DLL_API const int Null = SQLITE_NULL; // Encapsulation of a Column in a row of the result pointed by the prepared Statement. diff --git a/src/Database.cpp b/src/Database.cpp index c1403ae..a473dd9 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -23,29 +23,28 @@ #define SQLITE_DETERMINISTIC 0x800 #endif // SQLITE_DETERMINISTIC - namespace SQLite { -const int OK = SQLITE_OK; -const int OPEN_READONLY = SQLITE_OPEN_READONLY; -const int OPEN_READWRITE = SQLITE_OPEN_READWRITE; -const int OPEN_CREATE = SQLITE_OPEN_CREATE; -const int OPEN_URI = SQLITE_OPEN_URI; -const int OPEN_MEMORY = SQLITE_OPEN_MEMORY; -const int OPEN_NOMUTEX = SQLITE_OPEN_NOMUTEX; -const int OPEN_FULLMUTEX = SQLITE_OPEN_FULLMUTEX; -const int OPEN_SHAREDCACHE = SQLITE_OPEN_SHAREDCACHE; -const int OPEN_PRIVATECACHE = SQLITE_OPEN_PRIVATECACHE; +DLL_API const int OK = SQLITE_OK; +DLL_API const int OPEN_READONLY = SQLITE_OPEN_READONLY; +DLL_API const int OPEN_READWRITE = SQLITE_OPEN_READWRITE; +DLL_API const int OPEN_CREATE = SQLITE_OPEN_CREATE; +DLL_API const int OPEN_URI = SQLITE_OPEN_URI; +DLL_API const int OPEN_MEMORY = SQLITE_OPEN_MEMORY; +DLL_API const int OPEN_NOMUTEX = SQLITE_OPEN_NOMUTEX; +DLL_API const int OPEN_FULLMUTEX = SQLITE_OPEN_FULLMUTEX; +DLL_API const int OPEN_SHAREDCACHE = SQLITE_OPEN_SHAREDCACHE; +DLL_API const int OPEN_PRIVATECACHE = SQLITE_OPEN_PRIVATECACHE; // check if sqlite version is >= 3.31.0 and SQLITE_OPEN_NOFOLLOW is defined #if SQLITE_VERSION_NUMBER >= 3031000 && defined(SQLITE_OPEN_NOFOLLOW) -const int OPEN_NOFOLLOW = SQLITE_OPEN_NOFOLLOW; +DLL_API const int OPEN_NOFOLLOW = SQLITE_OPEN_NOFOLLOW; #else -const int OPEN_NOFOLLOW = 0; +DLL_API const int OPEN_NOFOLLOW = 0; #endif -const char* const VERSION = SQLITE_VERSION; -const int VERSION_NUMBER = SQLITE_VERSION_NUMBER; +DLL_API const char* const VERSION = SQLITE_VERSION; +DLL_API const int VERSION_NUMBER = SQLITE_VERSION_NUMBER; // Return SQLite version string using runtime call to the compiled library const char* getLibVersion() noexcept From 8f8eee616887fe27f84ee876a2982ef22e734d3c Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Tue, 7 Feb 2023 12:45:31 +1100 Subject: [PATCH 05/10] Simplify CMake for shared libs --- CMakeLists.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d94b4f..6d34baa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -216,7 +216,7 @@ endif (SQLITE_USE_LEGACY_STRUCT) if(BUILD_SHARED_LIBS) if(WIN32) add_definitions("-DSQLITECPP_COMPILE_DLL") - target_compile_definitions(SQLiteCpp PRIVATE "SQLITECPP_DLL_EXPORT=1") + target_compile_definitions(SQLiteCpp PRIVATE "SQLITECPP_DLL_EXPORT") endif() endif() @@ -412,11 +412,7 @@ if (SQLITECPP_BUILD_EXAMPLES) # add the basic example executable add_executable(SQLiteCpp_example1 ${SQLITECPP_EXAMPLES}) - if(BUILD_SHARED_LIBS) - if(WIN32) - target_compile_definitions(SQLiteCpp_example1 PRIVATE "SQLITECPP_DLL_EXPORT=0") - endif() - endif() + target_link_libraries(SQLiteCpp_example1 SQLiteCpp) if (MSYS OR MINGW) target_link_libraries(SQLiteCpp_example1 ssp) From 6110463dfea738899155349e66459862ce3b5ff1 Mon Sep 17 00:00:00 2001 From: Pierre Proske <117951793+pierre-aimi@users.noreply.github.com> Date: Mon, 13 Feb 2023 12:30:55 +1100 Subject: [PATCH 06/10] Update include/SQLiteCpp/SQLiteCppExport.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use _WIN32 instead of WIN32 Co-authored-by: Jonathan Guzmán --- include/SQLiteCpp/SQLiteCppExport.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SQLiteCpp/SQLiteCppExport.h b/include/SQLiteCpp/SQLiteCppExport.h index c6322bb..dea371a 100644 --- a/include/SQLiteCpp/SQLiteCppExport.h +++ b/include/SQLiteCpp/SQLiteCppExport.h @@ -18,7 +18,7 @@ */ /* Windows DLL export/import */ -#if defined(WIN32) && defined(SQLITECPP_COMPILE_DLL) +#if defined(_WIN32) && defined(SQLITECPP_COMPILE_DLL) #if SQLITECPP_DLL_EXPORT #define DLL_API __declspec(dllexport) #pragma message("Exporting symbols") From 1eca00cb01e0403f59df4cb426ec89161b146368 Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Tue, 14 Feb 2023 10:34:48 +1100 Subject: [PATCH 07/10] Fixed meson build thanks to @ninjaoflight --- meson.build | 63 +++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/meson.build b/meson.build index e270d56..c8c52d3 100644 --- a/meson.build +++ b/meson.build @@ -65,6 +65,8 @@ sqlitecpp_deps = [ ] ## used to override the default sqlitecpp options like cpp standard sqlitecpp_opts = [] +## used to set required macros when using sqlitecpp +sqlitecpp_dep_args = [] ## tests @@ -97,11 +99,6 @@ if host_machine.system() == 'windows' sqlitecpp_opts += [ 'cpp_std=c++14', ] - # check that we are not trying to build as dynamic library - if get_option('default_library') != 'shared' - message('warning: SQLiteCpp does not support shared library on Windows, the library will be built as static') - endif - endif # Options relative to SQLite and SQLiteC++ functions @@ -199,33 +196,36 @@ if get_option('b_coverage') ] endif -## Workarround for windows: if building on windows we will build the library as static -if host_machine.system() == 'windows' - libsqlitecpp = static_library( - 'sqlitecpp', - sqlitecpp_srcs, - include_directories: sqlitecpp_incl, - cpp_args: sqlitecpp_args, - dependencies: sqlitecpp_deps, - # override the default options - override_options: sqlitecpp_opts,) -else - libsqlitecpp = library( - 'sqlitecpp', - sqlitecpp_srcs, - include_directories: sqlitecpp_incl, - cpp_args: sqlitecpp_args, - dependencies: sqlitecpp_deps, - # override the default options - override_options: sqlitecpp_opts, - install: true, - # API version for SQLiteCpp shared library. - version: '0',) +sqlitecpp_static_args = sqlitecpp_args +sqlitecpp_static_dep_args = sqlitecpp_dep_args +# if windows and shared library +if host_machine.system() == 'windows' and get_option('default_library') == 'shared' + # compile with SQLITECPP_COMPILE_DLL and SQLITECPP_DLL_EXPORT=1 + sqlitecpp_args += [ + '-DSQLITECPP_COMPILE_DLL', + '-DSQLITECPP_DLL_EXPORT', + ] + sqlitecpp_dep_args += [ + # we just need to define SQLITECPP_COMPILE_DLL + '-DSQLITECPP_COMPILE_DLL', + ] endif +libsqlitecpp = library( + 'sqlitecpp', + sqlitecpp_srcs, + include_directories: sqlitecpp_incl, + cpp_args: sqlitecpp_args, + dependencies: sqlitecpp_deps, + # override the default options + override_options: sqlitecpp_opts, + install: true, + # API version for SQLiteCpp shared library. + version: '0',) + if get_option('SQLITECPP_BUILD_TESTS') # for the unit tests we need to link against a static version of SQLiteCpp - if host_machine.system() == 'windows' or get_option('default_library') == 'static' + if get_option('default_library') == 'static' # we do not need to recomplile the library libsqlitecpp_static = libsqlitecpp else @@ -233,7 +233,7 @@ if get_option('SQLITECPP_BUILD_TESTS') 'sqlitecpp_static', sqlitecpp_srcs, include_directories: sqlitecpp_incl, - cpp_args: sqlitecpp_args, + cpp_args: sqlitecpp_static_args, dependencies: sqlitecpp_deps, # override the default options override_options: sqlitecpp_opts,) @@ -247,13 +247,14 @@ install_subdir( sqlitecpp_dep = declare_dependency( include_directories: sqlitecpp_incl, link_with: libsqlitecpp, + compile_args: sqlitecpp_dep_args, ) if get_option('SQLITECPP_BUILD_TESTS') ## make the dependency static so the unit tests can link against it - ## (mainly for windows as the symbols are not exported by default) sqlitecpp_static_dep = declare_dependency( include_directories: sqlitecpp_incl, link_with: libsqlitecpp_static, + compile_args: sqlitecpp_static_dep_args, ) endif @@ -264,7 +265,7 @@ if get_option('SQLITECPP_BUILD_TESTS') fallback: ['gtest', 'gtest_main_dep']) sqlitecpp_test_dependencies = [ gtest_dep, - sqlitecpp_static_dep, + sqlitecpp_dep, sqlite3_dep, ] From 060d5323c38f04fb5a798af87c80d5aedad64369 Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Tue, 14 Feb 2023 11:31:54 +1100 Subject: [PATCH 08/10] =?UTF-8?q?Rename=20DLL=5FAPI=20to=20=C2=96SQLITECPP?= =?UTF-8?q?=5FAPI,=20and=20add=20=C2=96visibility=20attribute=20for=20gcc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/SQLiteCpp/Backup.h | 2 +- include/SQLiteCpp/Column.h | 14 ++++++------ include/SQLiteCpp/Database.h | 34 ++++++++++++++--------------- include/SQLiteCpp/Exception.h | 2 +- include/SQLiteCpp/SQLiteCppExport.h | 10 ++++++--- include/SQLiteCpp/Savepoint.h | 2 +- include/SQLiteCpp/Statement.h | 4 ++-- include/SQLiteCpp/Transaction.h | 2 +- src/Column.cpp | 10 ++++----- src/Database.cpp | 28 ++++++++++++------------ 10 files changed, 56 insertions(+), 52 deletions(-) diff --git a/include/SQLiteCpp/Backup.h b/include/SQLiteCpp/Backup.h index ecdd847..8a5d966 100644 --- a/include/SQLiteCpp/Backup.h +++ b/include/SQLiteCpp/Backup.h @@ -32,7 +32,7 @@ namespace SQLite * See also the a reference implementation of live backup taken from the official site: * https://www.sqlite.org/backup.html */ -class DLL_API Backup +class SQLITECPP_API Backup { public: /** diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index 21bd9d3..fbe2c1a 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -23,11 +23,11 @@ struct sqlite3_stmt; namespace SQLite { -DLL_API extern const int INTEGER; ///< SQLITE_INTEGER -DLL_API extern const int FLOAT; ///< SQLITE_FLOAT -DLL_API extern const int TEXT; ///< SQLITE_TEXT -DLL_API extern const int BLOB; ///< SQLITE_BLOB -DLL_API extern const int Null; ///< SQLITE_NULL +SQLITECPP_API extern const int INTEGER; ///< SQLITE_INTEGER +SQLITECPP_API extern const int FLOAT; ///< SQLITE_FLOAT +SQLITECPP_API extern const int TEXT; ///< SQLITE_TEXT +SQLITECPP_API extern const int BLOB; ///< SQLITE_BLOB +SQLITECPP_API extern const int Null; ///< SQLITE_NULL /** * @brief Encapsulation of a Column in a row of the result pointed by the prepared Statement. @@ -45,7 +45,7 @@ DLL_API extern const int Null; ///< SQLITE_NULL * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class DLL_API Column +class SQLITECPP_API Column { public: /** @@ -242,7 +242,7 @@ private: * * @return Reference to the stream used */ -DLL_API std::ostream& operator<<(std::ostream& aStream, const Column& aColumn); +SQLITECPP_API std::ostream& operator<<(std::ostream& aStream, const Column& aColumn); #if __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900) // c++14: Visual Studio 2015 diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index 7d34988..d0de0b4 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -85,37 +85,37 @@ namespace SQLite // Those public constants enable most usages of SQLiteCpp without including in the client application. /// The database is opened in read-only mode. If the database does not already exist, an error is returned. -DLL_API extern const int OPEN_READONLY; // SQLITE_OPEN_READONLY +SQLITECPP_API extern const int OPEN_READONLY; // SQLITE_OPEN_READONLY /// The database is opened for reading and writing if possible, or reading only if the file is write protected /// by the operating system. In either case the database must already exist, otherwise an error is returned. -DLL_API extern const int OPEN_READWRITE; // SQLITE_OPEN_READWRITE +SQLITECPP_API extern const int OPEN_READWRITE; // SQLITE_OPEN_READWRITE /// With OPEN_READWRITE: The database is opened for reading and writing, and is created if it does not already exist. -DLL_API extern const int OPEN_CREATE; // SQLITE_OPEN_CREATE +SQLITECPP_API extern const int OPEN_CREATE; // SQLITE_OPEN_CREATE /// Enable URI filename interpretation, parsed according to RFC 3986 (ex. "file:data.db?mode=ro&cache=private") -DLL_API extern const int OPEN_URI; // SQLITE_OPEN_URI +SQLITECPP_API extern const int OPEN_URI; // SQLITE_OPEN_URI /// Open in memory database -DLL_API extern const int OPEN_MEMORY; // SQLITE_OPEN_MEMORY +SQLITECPP_API extern const int OPEN_MEMORY; // SQLITE_OPEN_MEMORY /// Open database in multi-thread threading mode -DLL_API extern const int OPEN_NOMUTEX; // SQLITE_OPEN_NOMUTEX +SQLITECPP_API extern const int OPEN_NOMUTEX; // SQLITE_OPEN_NOMUTEX /// Open database with thread-safety in serialized threading mode -DLL_API extern const int OPEN_FULLMUTEX; // SQLITE_OPEN_FULLMUTEX +SQLITECPP_API extern const int OPEN_FULLMUTEX; // SQLITE_OPEN_FULLMUTEX /// Open database with shared cache enabled -DLL_API extern const int OPEN_SHAREDCACHE; // SQLITE_OPEN_SHAREDCACHE +SQLITECPP_API extern const int OPEN_SHAREDCACHE; // SQLITE_OPEN_SHAREDCACHE /// Open database with shared cache disabled -DLL_API extern const int OPEN_PRIVATECACHE; // SQLITE_OPEN_PRIVATECACHE +SQLITECPP_API extern const int OPEN_PRIVATECACHE; // SQLITE_OPEN_PRIVATECACHE /// Database filename is not allowed to be a symbolic link (Note: only since SQlite 3.31.0 from 2020-01-22) -DLL_API extern const int OPEN_NOFOLLOW; // SQLITE_OPEN_NOFOLLOW +SQLITECPP_API extern const int OPEN_NOFOLLOW; // SQLITE_OPEN_NOFOLLOW -DLL_API extern const int OK; ///< SQLITE_OK (used by check() bellow) +SQLITECPP_API extern const int OK; ///< SQLITE_OK (used by check() bellow) -DLL_API extern const char* const VERSION; ///< SQLITE_VERSION string from the sqlite3.h used at compile time -DLL_API extern const int VERSION_NUMBER; ///< SQLITE_VERSION_NUMBER from the sqlite3.h used at compile time +SQLITECPP_API extern const char* const VERSION; ///< SQLITE_VERSION string from the sqlite3.h used at compile time +SQLITECPP_API extern const int VERSION_NUMBER; ///< SQLITE_VERSION_NUMBER from the sqlite3.h used at compile time /// Return SQLite version string using runtime call to the compiled library -DLL_API const char* getLibVersion() noexcept; +SQLITECPP_API const char* getLibVersion() noexcept; /// Return SQLite version number using runtime call to the compiled library -DLL_API int getLibVersionNumber() noexcept; +SQLITECPP_API int getLibVersionNumber() noexcept; // Public structure for representing all fields contained within the SQLite header. // Official documentation for fields: https://www.sqlite.org/fileformat.html#the_database_header @@ -161,7 +161,7 @@ struct Header { * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class DLL_API Database +class SQLITECPP_API Database { friend class Statement; // Give Statement constructor access to the mSQLitePtr Connection Handle @@ -266,7 +266,7 @@ public: // Deleter functor to use with smart pointers to close the SQLite database connection in an RAII fashion. struct Deleter { - DLL_API void operator()(sqlite3* apSQLite); + SQLITECPP_API void operator()(sqlite3* apSQLite); }; /** diff --git a/include/SQLiteCpp/Exception.h b/include/SQLiteCpp/Exception.h index e771dce..cb7c665 100644 --- a/include/SQLiteCpp/Exception.h +++ b/include/SQLiteCpp/Exception.h @@ -24,7 +24,7 @@ namespace SQLite /** * @brief Encapsulation of the error message from SQLite3, based on std::runtime_error. */ -class DLL_API Exception : public std::runtime_error +class SQLITECPP_API Exception : public std::runtime_error { public: /** diff --git a/include/SQLiteCpp/SQLiteCppExport.h b/include/SQLiteCpp/SQLiteCppExport.h index dea371a..8f76f0f 100644 --- a/include/SQLiteCpp/SQLiteCppExport.h +++ b/include/SQLiteCpp/SQLiteCppExport.h @@ -20,14 +20,18 @@ /* Windows DLL export/import */ #if defined(_WIN32) && defined(SQLITECPP_COMPILE_DLL) #if SQLITECPP_DLL_EXPORT - #define DLL_API __declspec(dllexport) + #define SQLITECPP_API __declspec(dllexport) #pragma message("Exporting symbols") #else - #define DLL_API __declspec(dllimport) + #define SQLITECPP_API __declspec(dllimport) #pragma message("Importing symbols") #endif #else - #define DLL_API + #if __GNUC__ >= 4 + #define SQLITECPP_API __attribute__ ((visibility ("default"))) + #else + #define SQLITECPP_API + #endif #endif #if defined(WIN32) && defined(SQLITECPP_COMPILE_DLL) diff --git a/include/SQLiteCpp/Savepoint.h b/include/SQLiteCpp/Savepoint.h index 8a5d845..febe046 100644 --- a/include/SQLiteCpp/Savepoint.h +++ b/include/SQLiteCpp/Savepoint.h @@ -54,7 +54,7 @@ class Database; * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class DLL_API Savepoint +class SQLITECPP_API Savepoint { public: /** diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index bddc369..f33e18a 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -31,7 +31,7 @@ namespace SQLite class Database; class Column; -DLL_API extern const int OK; ///< SQLITE_OK +SQLITECPP_API extern const int OK; ///< SQLITE_OK /** * @brief RAII encapsulation of a prepared SQLite Statement. @@ -50,7 +50,7 @@ DLL_API extern const int OK; ///< SQLITE_OK * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class DLL_API Statement +class SQLITECPP_API Statement { public: /** diff --git a/include/SQLiteCpp/Transaction.h b/include/SQLiteCpp/Transaction.h index 77a3235..5cc4171 100644 --- a/include/SQLiteCpp/Transaction.h +++ b/include/SQLiteCpp/Transaction.h @@ -51,7 +51,7 @@ enum class TransactionBehavior { * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class DLL_API Transaction +class SQLITECPP_API Transaction { public: /** diff --git a/src/Column.cpp b/src/Column.cpp index ec7c64d..74b288d 100644 --- a/src/Column.cpp +++ b/src/Column.cpp @@ -18,11 +18,11 @@ namespace SQLite { -DLL_API const int INTEGER = SQLITE_INTEGER; -DLL_API const int FLOAT = SQLITE_FLOAT; -DLL_API const int TEXT = SQLITE_TEXT; -DLL_API const int BLOB = SQLITE_BLOB; -DLL_API const int Null = SQLITE_NULL; +SQLITECPP_API const int INTEGER = SQLITE_INTEGER; +SQLITECPP_API const int FLOAT = SQLITE_FLOAT; +SQLITECPP_API const int TEXT = SQLITE_TEXT; +SQLITECPP_API const int BLOB = SQLITE_BLOB; +SQLITECPP_API const int Null = SQLITE_NULL; // Encapsulation of a Column in a row of the result pointed by the prepared Statement. diff --git a/src/Database.cpp b/src/Database.cpp index a473dd9..c982dd5 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -26,25 +26,25 @@ namespace SQLite { -DLL_API const int OK = SQLITE_OK; -DLL_API const int OPEN_READONLY = SQLITE_OPEN_READONLY; -DLL_API const int OPEN_READWRITE = SQLITE_OPEN_READWRITE; -DLL_API const int OPEN_CREATE = SQLITE_OPEN_CREATE; -DLL_API const int OPEN_URI = SQLITE_OPEN_URI; -DLL_API const int OPEN_MEMORY = SQLITE_OPEN_MEMORY; -DLL_API const int OPEN_NOMUTEX = SQLITE_OPEN_NOMUTEX; -DLL_API const int OPEN_FULLMUTEX = SQLITE_OPEN_FULLMUTEX; -DLL_API const int OPEN_SHAREDCACHE = SQLITE_OPEN_SHAREDCACHE; -DLL_API const int OPEN_PRIVATECACHE = SQLITE_OPEN_PRIVATECACHE; +SQLITECPP_API const int OK = SQLITE_OK; +SQLITECPP_API const int OPEN_READONLY = SQLITE_OPEN_READONLY; +SQLITECPP_API const int OPEN_READWRITE = SQLITE_OPEN_READWRITE; +SQLITECPP_API const int OPEN_CREATE = SQLITE_OPEN_CREATE; +SQLITECPP_API const int OPEN_URI = SQLITE_OPEN_URI; +SQLITECPP_API const int OPEN_MEMORY = SQLITE_OPEN_MEMORY; +SQLITECPP_API const int OPEN_NOMUTEX = SQLITE_OPEN_NOMUTEX; +SQLITECPP_API const int OPEN_FULLMUTEX = SQLITE_OPEN_FULLMUTEX; +SQLITECPP_API const int OPEN_SHAREDCACHE = SQLITE_OPEN_SHAREDCACHE; +SQLITECPP_API const int OPEN_PRIVATECACHE = SQLITE_OPEN_PRIVATECACHE; // check if sqlite version is >= 3.31.0 and SQLITE_OPEN_NOFOLLOW is defined #if SQLITE_VERSION_NUMBER >= 3031000 && defined(SQLITE_OPEN_NOFOLLOW) -DLL_API const int OPEN_NOFOLLOW = SQLITE_OPEN_NOFOLLOW; +SQLITECPP_API const int OPEN_NOFOLLOW = SQLITE_OPEN_NOFOLLOW; #else -DLL_API const int OPEN_NOFOLLOW = 0; +SQLITECPP_API const int OPEN_NOFOLLOW = 0; #endif -DLL_API const char* const VERSION = SQLITE_VERSION; -DLL_API const int VERSION_NUMBER = SQLITE_VERSION_NUMBER; +SQLITECPP_API const char* const VERSION = SQLITE_VERSION; +SQLITECPP_API const int VERSION_NUMBER = SQLITE_VERSION_NUMBER; // Return SQLite version string using runtime call to the compiled library const char* getLibVersion() noexcept From 2f0079081172faf9d2eacfcc54e3610f4c7e0802 Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Tue, 14 Feb 2023 11:31:54 +1100 Subject: [PATCH 09/10] Rename DLL_API to SQLITECPP_API, and add visibility attribute for gcc --- include/SQLiteCpp/Backup.h | 2 +- include/SQLiteCpp/Column.h | 14 ++++++------ include/SQLiteCpp/Database.h | 34 ++++++++++++++--------------- include/SQLiteCpp/Exception.h | 2 +- include/SQLiteCpp/SQLiteCppExport.h | 10 ++++++--- include/SQLiteCpp/Savepoint.h | 2 +- include/SQLiteCpp/Statement.h | 4 ++-- include/SQLiteCpp/Transaction.h | 2 +- src/Column.cpp | 10 ++++----- src/Database.cpp | 28 ++++++++++++------------ 10 files changed, 56 insertions(+), 52 deletions(-) diff --git a/include/SQLiteCpp/Backup.h b/include/SQLiteCpp/Backup.h index ecdd847..8a5d966 100644 --- a/include/SQLiteCpp/Backup.h +++ b/include/SQLiteCpp/Backup.h @@ -32,7 +32,7 @@ namespace SQLite * See also the a reference implementation of live backup taken from the official site: * https://www.sqlite.org/backup.html */ -class DLL_API Backup +class SQLITECPP_API Backup { public: /** diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index 21bd9d3..fbe2c1a 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -23,11 +23,11 @@ struct sqlite3_stmt; namespace SQLite { -DLL_API extern const int INTEGER; ///< SQLITE_INTEGER -DLL_API extern const int FLOAT; ///< SQLITE_FLOAT -DLL_API extern const int TEXT; ///< SQLITE_TEXT -DLL_API extern const int BLOB; ///< SQLITE_BLOB -DLL_API extern const int Null; ///< SQLITE_NULL +SQLITECPP_API extern const int INTEGER; ///< SQLITE_INTEGER +SQLITECPP_API extern const int FLOAT; ///< SQLITE_FLOAT +SQLITECPP_API extern const int TEXT; ///< SQLITE_TEXT +SQLITECPP_API extern const int BLOB; ///< SQLITE_BLOB +SQLITECPP_API extern const int Null; ///< SQLITE_NULL /** * @brief Encapsulation of a Column in a row of the result pointed by the prepared Statement. @@ -45,7 +45,7 @@ DLL_API extern const int Null; ///< SQLITE_NULL * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class DLL_API Column +class SQLITECPP_API Column { public: /** @@ -242,7 +242,7 @@ private: * * @return Reference to the stream used */ -DLL_API std::ostream& operator<<(std::ostream& aStream, const Column& aColumn); +SQLITECPP_API std::ostream& operator<<(std::ostream& aStream, const Column& aColumn); #if __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900) // c++14: Visual Studio 2015 diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index 7d34988..d0de0b4 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -85,37 +85,37 @@ namespace SQLite // Those public constants enable most usages of SQLiteCpp without including in the client application. /// The database is opened in read-only mode. If the database does not already exist, an error is returned. -DLL_API extern const int OPEN_READONLY; // SQLITE_OPEN_READONLY +SQLITECPP_API extern const int OPEN_READONLY; // SQLITE_OPEN_READONLY /// The database is opened for reading and writing if possible, or reading only if the file is write protected /// by the operating system. In either case the database must already exist, otherwise an error is returned. -DLL_API extern const int OPEN_READWRITE; // SQLITE_OPEN_READWRITE +SQLITECPP_API extern const int OPEN_READWRITE; // SQLITE_OPEN_READWRITE /// With OPEN_READWRITE: The database is opened for reading and writing, and is created if it does not already exist. -DLL_API extern const int OPEN_CREATE; // SQLITE_OPEN_CREATE +SQLITECPP_API extern const int OPEN_CREATE; // SQLITE_OPEN_CREATE /// Enable URI filename interpretation, parsed according to RFC 3986 (ex. "file:data.db?mode=ro&cache=private") -DLL_API extern const int OPEN_URI; // SQLITE_OPEN_URI +SQLITECPP_API extern const int OPEN_URI; // SQLITE_OPEN_URI /// Open in memory database -DLL_API extern const int OPEN_MEMORY; // SQLITE_OPEN_MEMORY +SQLITECPP_API extern const int OPEN_MEMORY; // SQLITE_OPEN_MEMORY /// Open database in multi-thread threading mode -DLL_API extern const int OPEN_NOMUTEX; // SQLITE_OPEN_NOMUTEX +SQLITECPP_API extern const int OPEN_NOMUTEX; // SQLITE_OPEN_NOMUTEX /// Open database with thread-safety in serialized threading mode -DLL_API extern const int OPEN_FULLMUTEX; // SQLITE_OPEN_FULLMUTEX +SQLITECPP_API extern const int OPEN_FULLMUTEX; // SQLITE_OPEN_FULLMUTEX /// Open database with shared cache enabled -DLL_API extern const int OPEN_SHAREDCACHE; // SQLITE_OPEN_SHAREDCACHE +SQLITECPP_API extern const int OPEN_SHAREDCACHE; // SQLITE_OPEN_SHAREDCACHE /// Open database with shared cache disabled -DLL_API extern const int OPEN_PRIVATECACHE; // SQLITE_OPEN_PRIVATECACHE +SQLITECPP_API extern const int OPEN_PRIVATECACHE; // SQLITE_OPEN_PRIVATECACHE /// Database filename is not allowed to be a symbolic link (Note: only since SQlite 3.31.0 from 2020-01-22) -DLL_API extern const int OPEN_NOFOLLOW; // SQLITE_OPEN_NOFOLLOW +SQLITECPP_API extern const int OPEN_NOFOLLOW; // SQLITE_OPEN_NOFOLLOW -DLL_API extern const int OK; ///< SQLITE_OK (used by check() bellow) +SQLITECPP_API extern const int OK; ///< SQLITE_OK (used by check() bellow) -DLL_API extern const char* const VERSION; ///< SQLITE_VERSION string from the sqlite3.h used at compile time -DLL_API extern const int VERSION_NUMBER; ///< SQLITE_VERSION_NUMBER from the sqlite3.h used at compile time +SQLITECPP_API extern const char* const VERSION; ///< SQLITE_VERSION string from the sqlite3.h used at compile time +SQLITECPP_API extern const int VERSION_NUMBER; ///< SQLITE_VERSION_NUMBER from the sqlite3.h used at compile time /// Return SQLite version string using runtime call to the compiled library -DLL_API const char* getLibVersion() noexcept; +SQLITECPP_API const char* getLibVersion() noexcept; /// Return SQLite version number using runtime call to the compiled library -DLL_API int getLibVersionNumber() noexcept; +SQLITECPP_API int getLibVersionNumber() noexcept; // Public structure for representing all fields contained within the SQLite header. // Official documentation for fields: https://www.sqlite.org/fileformat.html#the_database_header @@ -161,7 +161,7 @@ struct Header { * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class DLL_API Database +class SQLITECPP_API Database { friend class Statement; // Give Statement constructor access to the mSQLitePtr Connection Handle @@ -266,7 +266,7 @@ public: // Deleter functor to use with smart pointers to close the SQLite database connection in an RAII fashion. struct Deleter { - DLL_API void operator()(sqlite3* apSQLite); + SQLITECPP_API void operator()(sqlite3* apSQLite); }; /** diff --git a/include/SQLiteCpp/Exception.h b/include/SQLiteCpp/Exception.h index e771dce..cb7c665 100644 --- a/include/SQLiteCpp/Exception.h +++ b/include/SQLiteCpp/Exception.h @@ -24,7 +24,7 @@ namespace SQLite /** * @brief Encapsulation of the error message from SQLite3, based on std::runtime_error. */ -class DLL_API Exception : public std::runtime_error +class SQLITECPP_API Exception : public std::runtime_error { public: /** diff --git a/include/SQLiteCpp/SQLiteCppExport.h b/include/SQLiteCpp/SQLiteCppExport.h index dea371a..8f76f0f 100644 --- a/include/SQLiteCpp/SQLiteCppExport.h +++ b/include/SQLiteCpp/SQLiteCppExport.h @@ -20,14 +20,18 @@ /* Windows DLL export/import */ #if defined(_WIN32) && defined(SQLITECPP_COMPILE_DLL) #if SQLITECPP_DLL_EXPORT - #define DLL_API __declspec(dllexport) + #define SQLITECPP_API __declspec(dllexport) #pragma message("Exporting symbols") #else - #define DLL_API __declspec(dllimport) + #define SQLITECPP_API __declspec(dllimport) #pragma message("Importing symbols") #endif #else - #define DLL_API + #if __GNUC__ >= 4 + #define SQLITECPP_API __attribute__ ((visibility ("default"))) + #else + #define SQLITECPP_API + #endif #endif #if defined(WIN32) && defined(SQLITECPP_COMPILE_DLL) diff --git a/include/SQLiteCpp/Savepoint.h b/include/SQLiteCpp/Savepoint.h index 8a5d845..febe046 100644 --- a/include/SQLiteCpp/Savepoint.h +++ b/include/SQLiteCpp/Savepoint.h @@ -54,7 +54,7 @@ class Database; * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class DLL_API Savepoint +class SQLITECPP_API Savepoint { public: /** diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index bddc369..f33e18a 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -31,7 +31,7 @@ namespace SQLite class Database; class Column; -DLL_API extern const int OK; ///< SQLITE_OK +SQLITECPP_API extern const int OK; ///< SQLITE_OK /** * @brief RAII encapsulation of a prepared SQLite Statement. @@ -50,7 +50,7 @@ DLL_API extern const int OK; ///< SQLITE_OK * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class DLL_API Statement +class SQLITECPP_API Statement { public: /** diff --git a/include/SQLiteCpp/Transaction.h b/include/SQLiteCpp/Transaction.h index 77a3235..5cc4171 100644 --- a/include/SQLiteCpp/Transaction.h +++ b/include/SQLiteCpp/Transaction.h @@ -51,7 +51,7 @@ enum class TransactionBehavior { * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class DLL_API Transaction +class SQLITECPP_API Transaction { public: /** diff --git a/src/Column.cpp b/src/Column.cpp index ec7c64d..74b288d 100644 --- a/src/Column.cpp +++ b/src/Column.cpp @@ -18,11 +18,11 @@ namespace SQLite { -DLL_API const int INTEGER = SQLITE_INTEGER; -DLL_API const int FLOAT = SQLITE_FLOAT; -DLL_API const int TEXT = SQLITE_TEXT; -DLL_API const int BLOB = SQLITE_BLOB; -DLL_API const int Null = SQLITE_NULL; +SQLITECPP_API const int INTEGER = SQLITE_INTEGER; +SQLITECPP_API const int FLOAT = SQLITE_FLOAT; +SQLITECPP_API const int TEXT = SQLITE_TEXT; +SQLITECPP_API const int BLOB = SQLITE_BLOB; +SQLITECPP_API const int Null = SQLITE_NULL; // Encapsulation of a Column in a row of the result pointed by the prepared Statement. diff --git a/src/Database.cpp b/src/Database.cpp index a473dd9..c982dd5 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -26,25 +26,25 @@ namespace SQLite { -DLL_API const int OK = SQLITE_OK; -DLL_API const int OPEN_READONLY = SQLITE_OPEN_READONLY; -DLL_API const int OPEN_READWRITE = SQLITE_OPEN_READWRITE; -DLL_API const int OPEN_CREATE = SQLITE_OPEN_CREATE; -DLL_API const int OPEN_URI = SQLITE_OPEN_URI; -DLL_API const int OPEN_MEMORY = SQLITE_OPEN_MEMORY; -DLL_API const int OPEN_NOMUTEX = SQLITE_OPEN_NOMUTEX; -DLL_API const int OPEN_FULLMUTEX = SQLITE_OPEN_FULLMUTEX; -DLL_API const int OPEN_SHAREDCACHE = SQLITE_OPEN_SHAREDCACHE; -DLL_API const int OPEN_PRIVATECACHE = SQLITE_OPEN_PRIVATECACHE; +SQLITECPP_API const int OK = SQLITE_OK; +SQLITECPP_API const int OPEN_READONLY = SQLITE_OPEN_READONLY; +SQLITECPP_API const int OPEN_READWRITE = SQLITE_OPEN_READWRITE; +SQLITECPP_API const int OPEN_CREATE = SQLITE_OPEN_CREATE; +SQLITECPP_API const int OPEN_URI = SQLITE_OPEN_URI; +SQLITECPP_API const int OPEN_MEMORY = SQLITE_OPEN_MEMORY; +SQLITECPP_API const int OPEN_NOMUTEX = SQLITE_OPEN_NOMUTEX; +SQLITECPP_API const int OPEN_FULLMUTEX = SQLITE_OPEN_FULLMUTEX; +SQLITECPP_API const int OPEN_SHAREDCACHE = SQLITE_OPEN_SHAREDCACHE; +SQLITECPP_API const int OPEN_PRIVATECACHE = SQLITE_OPEN_PRIVATECACHE; // check if sqlite version is >= 3.31.0 and SQLITE_OPEN_NOFOLLOW is defined #if SQLITE_VERSION_NUMBER >= 3031000 && defined(SQLITE_OPEN_NOFOLLOW) -DLL_API const int OPEN_NOFOLLOW = SQLITE_OPEN_NOFOLLOW; +SQLITECPP_API const int OPEN_NOFOLLOW = SQLITE_OPEN_NOFOLLOW; #else -DLL_API const int OPEN_NOFOLLOW = 0; +SQLITECPP_API const int OPEN_NOFOLLOW = 0; #endif -DLL_API const char* const VERSION = SQLITE_VERSION; -DLL_API const int VERSION_NUMBER = SQLITE_VERSION_NUMBER; +SQLITECPP_API const char* const VERSION = SQLITE_VERSION; +SQLITECPP_API const int VERSION_NUMBER = SQLITE_VERSION_NUMBER; // Return SQLite version string using runtime call to the compiled library const char* getLibVersion() noexcept From 82afee652ba0419ecca4311c7be8c4107d0fd4e3 Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Tue, 7 Mar 2023 17:03:32 +1100 Subject: [PATCH 10/10] Fix Mingw build and suppress attribute warnings --- include/SQLiteCpp/SQLiteCppExport.h | 2 +- meson.build | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/SQLiteCpp/SQLiteCppExport.h b/include/SQLiteCpp/SQLiteCppExport.h index 8f76f0f..8629306 100644 --- a/include/SQLiteCpp/SQLiteCppExport.h +++ b/include/SQLiteCpp/SQLiteCppExport.h @@ -18,7 +18,7 @@ */ /* Windows DLL export/import */ -#if defined(_WIN32) && defined(SQLITECPP_COMPILE_DLL) +#if defined(_WIN32)&& !defined(__GNUC__) && defined(SQLITECPP_COMPILE_DLL) #if SQLITECPP_DLL_EXPORT #define SQLITECPP_API __declspec(dllexport) #pragma message("Exporting symbols") diff --git a/meson.build b/meson.build index 4439612..10240e4 100644 --- a/meson.build +++ b/meson.build @@ -57,6 +57,7 @@ sqlitecpp_args = cxx.get_supported_arguments( '-Wswitch-enum', '-Wshadow', '-Wno-long-long', + '-Wno-attributes', ) sqlitecpp_link = [] sqlitecpp_deps = [