bombela / backward-cpp

A beautiful stack trace pretty printer for C++
MIT License
3.68k stars 467 forks source link

Meson WrapDB + issues on windows #274

Open tmayoff opened 1 year ago

tmayoff commented 1 year ago

I wanted to add this repo to mesonbuild dependency manager, I got the port working all fine except the windows build. Unfortunately I've not really ever dealt with windows development so not sure if this is something fixable from here, here's the PR to the wrap

https://github.com/mesonbuild/wrapdb/pull/692

UnixY2K commented 1 year ago

on some forks of projects what I did was to add a macro on a exportAPI.hpp file like this

#pragma once
// Utility header for SQLiteCpp
// it allows exporting/importing c++ code to an dynamic library

#if defined(SQLiteCppLIBRARY_EXPORT)
    #define SQLiteCppAPI EXPORT
#else
    #define SQLiteCppAPI IMPORT
#endif

#if defined(_MSC_VER)
    //  Microsoft 
    #define EXPORT __declspec(dllexport)
    #define IMPORT __declspec(dllimport)
#elif defined(__GNUC__)
    //  GCC
    #define EXPORT __attribute__((visibility("default")))
    #define IMPORT
#else
    //  do nothing
    #define EXPORT
    #define IMPORT
    #pragma warning Unknown dynamic link import/export semantics.
#endif

keep in mind that this may require some modifications as it was used for other project

then on the header files add that macro on the class, method, variable, etc. that you may want to export as in windows the visibility is hidden by default.

ex:

namespace SQLite
{

// Those public constants enable most usages of SQLiteCpp without including <sqlite3.h> in the client application.

/// The database is opened in read-only mode. If the database does not already exist, an error is returned.
SQLiteCppAPI 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.
SQLiteCppAPI extern const int OPEN_READWRITE;    // SQLITE_OPEN_READWRITE
// ...
class SQLiteCppAPI Backup{
// rest of the code

under the cpp you would need to do the following:

#define SQLiteCppLIBRARY_EXPORT
#include <SQLiteCpp/private/exportAPI.h>
// other includes along with the headers that define the symbols if required

namespace SQLite
{

SQLiteCppAPI const int INTEGER   = SQLITE_INTEGER;
SQLiteCppAPI const int FLOAT     = SQLITE_FLOAT;
SQLiteCppAPI const int TEXT      = SQLITE_TEXT;
SQLiteCppAPI const int BLOB      = SQLITE_BLOB;
SQLiteCppAPI const int Null      = SQLITE_NULL;
// rest of the code

I had an old fork of SQLiteCpp with those modifications in case you want to check them