Skip to content

Commit

Permalink
feat: add __declspec(dllexport) to class
Browse files Browse the repository at this point in the history
fix build dynamic library issue on Windows
  • Loading branch information
xiaoyifang committed Apr 17, 2023
1 parent 5798d02 commit 9775e58
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 35 deletions.
2 changes: 1 addition & 1 deletion include/zim/archive.h
Expand Up @@ -53,7 +53,7 @@ namespace zim
*
* All methods of archive may throw an `ZimFileFormatError` if the file is invalid.
*/
class Archive
class LIBZIM_API Archive
{
public:
template<EntryOrder order> class EntryRange;
Expand Down
2 changes: 1 addition & 1 deletion include/zim/blob.h
Expand Up @@ -35,7 +35,7 @@ namespace zim
*
* All `Blob`'s methods are threadsafe.
*/
class Blob
class LIBZIM_API Blob
{
public: // types
using DataPtr = std::shared_ptr<const char>;
Expand Down
2 changes: 1 addition & 1 deletion include/zim/entry.h
Expand Up @@ -36,7 +36,7 @@ namespace zim
*
* All `Entry`'s methods are threadsafe.
*/
class Entry
class LIBZIM_API Entry
{
public:
explicit Entry(std::shared_ptr<FileImpl> file_, entry_index_type idx_);
Expand Down
18 changes: 10 additions & 8 deletions include/zim/error.h
Expand Up @@ -20,29 +20,31 @@
#ifndef ZIM_ERROR_H
#define ZIM_ERROR_H

#include "export_api.h"

#include <stdexcept>
#include <sstream>
#include <typeinfo>

namespace zim
{
class ZimFileFormatError : public std::runtime_error
class LIBZIM_API ZimFileFormatError : public std::runtime_error
{
public:
explicit ZimFileFormatError(const std::string& msg)
: std::runtime_error(msg)
{ }
};

class InvalidType: public std::logic_error
class LIBZIM_API InvalidType: public std::logic_error
{
public:
explicit InvalidType(const std::string& msg)
: std::logic_error(msg)
{}
};

class EntryNotFound : public std::runtime_error
class LIBZIM_API EntryNotFound : public std::runtime_error
{
public:
explicit EntryNotFound(const std::string& msg)
Expand All @@ -54,7 +56,7 @@ namespace zim
*
* Most exceptions actually thrown are inheriting this exception.
*/
class CreatorError : public std::runtime_error
class LIBZIM_API CreatorError : public std::runtime_error
{
public:
explicit CreatorError(const std::string& message)
Expand All @@ -63,7 +65,7 @@ namespace zim
};

/* Exception thrown when a entry cannot be added to the Creator.*/
class InvalidEntry : public CreatorError
class LIBZIM_API InvalidEntry : public CreatorError
{
public:
explicit InvalidEntry(const std::string& message)
Expand All @@ -81,7 +83,7 @@ namespace zim
* If a incoherence has been detected in those implementations a
* `IncoherentImplementationError` will be thrown.
*/
class IncoherentImplementationError : public CreatorError
class LIBZIM_API IncoherentImplementationError : public CreatorError
{
public:
explicit IncoherentImplementationError(const std::string& message)
Expand Down Expand Up @@ -113,7 +115,7 @@ namespace zim
* }
* ```
*/
class AsyncError : public CreatorError
class LIBZIM_API AsyncError : public CreatorError
{
public:
explicit AsyncError(const std::exception_ptr exception)
Expand Down Expand Up @@ -149,7 +151,7 @@ namespace zim
* If the creator is in error state (mostly because a AsyncError has already
* being thrown), any call to any method on it will thrown a `CreatorStateError`.
*/
class CreatorStateError : public CreatorError
class LIBZIM_API CreatorStateError : public CreatorError
{
public:
explicit CreatorStateError()
Expand Down
10 changes: 10 additions & 0 deletions include/zim/export_api.h
@@ -0,0 +1,10 @@
#ifndef ZIM_EXPORT_API_H
#define ZIM_EXPORT_API_H

#if (defined _WIN32 || defined __CYGWIN__) && defined ENABLE_EXPORT_DLL
#define LIBZIM_API __declspec(dllexport)
#else
#define LIBZIM_API
#endif

#endif
2 changes: 1 addition & 1 deletion include/zim/item.h
Expand Up @@ -35,7 +35,7 @@ namespace zim
*
* All `Item`'s methods are threadsafe.
*/
class Item
class LIBZIM_API Item
{
public: // types
typedef std::pair<std::string, offset_type> DirectAccessInfo;
Expand Down
8 changes: 4 additions & 4 deletions include/zim/search.h
Expand Up @@ -53,7 +53,7 @@ class SearchResultSet;
* However, Searcher (and subsequent classes) do not maintain a global/share state.
* You can create several Searchers and use them in different threads.
*/
class Searcher
class LIBZIM_API Searcher
{
public:
/** Searcher constructor.
Expand Down Expand Up @@ -115,7 +115,7 @@ class Searcher
* It describe what have to be searched and how.
* A Query is "database" independent.
*/
class Query
class LIBZIM_API Query
{
public:
/** Query constructor.
Expand Down Expand Up @@ -156,7 +156,7 @@ class Query
* This is somehow the reunification of a `Searcher` (what to search on)
* and a `Query` (what to search for).
*/
class Search
class LIBZIM_API Search
{
public:
Search(Search&& s);
Expand Down Expand Up @@ -195,7 +195,7 @@ class Search
*
* It mainly allows to get a iterator.
*/
class SearchResultSet
class LIBZIM_API SearchResultSet
{
public:
typedef SearchIterator iterator;
Expand Down
2 changes: 1 addition & 1 deletion include/zim/search_iterator.h
Expand Up @@ -32,7 +32,7 @@ namespace zim
{
class SearchResultSet;

class SearchIterator : public std::iterator<std::bidirectional_iterator_tag, Entry>
class LIBZIM_API SearchIterator : public std::iterator<std::bidirectional_iterator_tag, Entry>
{
friend class zim::SearchResultSet;
public:
Expand Down
6 changes: 3 additions & 3 deletions include/zim/suggestion.h
Expand Up @@ -52,7 +52,7 @@ class SuggestionDataBase;
* However, SuggestionSearcher (and subsequent classes) do not maintain a global/
* share state You can create several Searchers and use them in different threads.
*/
class SuggestionSearcher
class LIBZIM_API SuggestionSearcher
{
public:
/** SuggestionSearcher constructor.
Expand Down Expand Up @@ -95,7 +95,7 @@ class SuggestionSearcher
/**
* A SuggestionSearch represent a particular suggestion search, based on a `SuggestionSearcher`.
*/
class SuggestionSearch
class LIBZIM_API SuggestionSearch
{
public:
SuggestionSearch(SuggestionSearch&& s);
Expand Down Expand Up @@ -147,7 +147,7 @@ class SuggestionSearch
*
* It mainly allows to get a iterator either based on an MSetIterator or a RangeIterator.
*/
class SuggestionResultSet
class LIBZIM_API SuggestionResultSet
{
public:
typedef SuggestionIterator iterator;
Expand Down
4 changes: 2 additions & 2 deletions include/zim/suggestion_iterator.h
Expand Up @@ -31,7 +31,7 @@ class SuggestionResultSet;
class SuggestionItem;
class SearchIterator;

class SuggestionIterator : public std::iterator<std::bidirectional_iterator_tag, SuggestionItem>
class LIBZIM_API SuggestionIterator : public std::iterator<std::bidirectional_iterator_tag, SuggestionItem>
{
typedef Archive::iterator<EntryOrder::titleOrder> RangeIterator;
friend class SuggestionResultSet;
Expand Down Expand Up @@ -81,7 +81,7 @@ class SuggestionIterator : public std::iterator<std::bidirectional_iterator_tag,
#endif // LIBZIM_WITH_XAPIAN
};

class SuggestionItem
class LIBZIM_API SuggestionItem
{
public: // methods
SuggestionItem(std::string title, std::string path, std::string snippet = "")
Expand Down
4 changes: 2 additions & 2 deletions include/zim/tools.h
Expand Up @@ -21,7 +21,7 @@
#define ZIM_TOOLS_H

#include <zim/zim_config.h>

#include "export_api.h"

namespace zim {
#if defined(LIBZIM_WITH_XAPIAN)
Expand All @@ -32,7 +32,7 @@ namespace zim {
* in the library. So android application needs to set
* the data directory where ICU can find its data.
*/
void setICUDataDirectory(const std::string& path);
LIBZIM_API void setICUDataDirectory(const std::string& path);

#endif
}
Expand Down
2 changes: 1 addition & 1 deletion include/zim/uuid.h
Expand Up @@ -26,7 +26,7 @@
#include <algorithm>
#include <cstring>
#include <string>

#include "export_api.h"
namespace zim
{
struct Uuid
Expand Down
8 changes: 4 additions & 4 deletions include/zim/writer/contentProvider.h
Expand Up @@ -42,7 +42,7 @@ namespace zim
* `ContentProvider` is an abstract class in charge of providing the content to
* add in the archive to the creator.
*/
class ContentProvider {
class LIBZIM_API ContentProvider {
public:
virtual ~ContentProvider() = default;
/**
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace zim
/**
* StringProvider provide the content stored in a string.
*/
class StringProvider : public ContentProvider {
class LIBZIM_API StringProvider : public ContentProvider {
public:
/**
* Create a provider using a string as content.
Expand All @@ -107,7 +107,7 @@ namespace zim
* It is mostly the same thing that `StringProvider` but use a shared_ptr
* to avoid copy.
*/
class SharedStringProvider : public ContentProvider {
class LIBZIM_API SharedStringProvider : public ContentProvider {
public:
/**
* Create a provider using a string as content.
Expand All @@ -130,7 +130,7 @@ namespace zim
/**
* FileProvider provide the content stored in file.
*/
class FileProvider : public ContentProvider {
class LIBZIM_API FileProvider : public ContentProvider {
public:
/**
* Create a provider using file as content.
Expand Down
2 changes: 1 addition & 1 deletion include/zim/writer/creator.h
Expand Up @@ -61,7 +61,7 @@ namespace zim
* - Any other exception thrown for unknown reason.
* By default, creator status is not changed by thrown exception and creation should stop.
*/
class Creator
class LIBZIM_API Creator
{
public:
/**
Expand Down
10 changes: 5 additions & 5 deletions include/zim/writer/item.h
Expand Up @@ -47,7 +47,7 @@ namespace zim
* (But default `Item::getIndexData` returns a default implementation
* for IndexData which works for html content.)
*/
class IndexData {
class LIBZIM_API IndexData {
public:
using GeoPosition = std::tuple<bool, double, double>;
virtual ~IndexData() = default;
Expand Down Expand Up @@ -124,7 +124,7 @@ namespace zim
* libzim provides `BasicItem`, `StringItem` and `FileItem`
* to simplify (or avoid) this reimplementation.
*/
class Item
class LIBZIM_API Item
{
public:
/**
Expand Down Expand Up @@ -230,7 +230,7 @@ namespace zim
* `BasicItem` provides a basic implementation for everything about an `Item`
* but the actual content of the item.
*/
class BasicItem : public Item
class LIBZIM_API BasicItem : public Item
{
public:
/**
Expand Down Expand Up @@ -262,7 +262,7 @@ namespace zim
/**
* A `StringItem` is a full implemented item where the content is stored in a string.
*/
class StringItem : public BasicItem, public std::enable_shared_from_this<StringItem>
class LIBZIM_API StringItem : public BasicItem, public std::enable_shared_from_this<StringItem>
{
public:
/**
Expand Down Expand Up @@ -296,7 +296,7 @@ namespace zim
/**
* A `FileItem` is a full implemented item where the content is file.
*/
class FileItem : public BasicItem
class LIBZIM_API FileItem : public BasicItem
{
public:
/**
Expand Down
1 change: 1 addition & 0 deletions include/zim/zim.h
Expand Up @@ -33,6 +33,7 @@
#define DEPRECATED
#endif

#include "export_api.h"

#include <zim/zim_config.h>

Expand Down
2 changes: 2 additions & 0 deletions meson.build
Expand Up @@ -37,6 +37,8 @@ static_linkage = static_linkage or get_option('default_library')=='static'
lzma_dep = dependency('liblzma', static:static_linkage)
if static_linkage
add_project_arguments('-DLZMA_API_STATIC', language: 'cpp')
else
private_conf.set('ENABLE_EXPORT_DLL', true)
endif

zstd_dep = dependency('libzstd', static:static_linkage)
Expand Down

0 comments on commit 9775e58

Please sign in to comment.