Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export symbols #1108

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions websocketpp/common/symbol_export.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef WEBSOCKETPP_COMMON_SYMBOL_EXPORT_HPP
#define WEBSOCKETPP_COMMON_SYMBOL_EXPORT_HPP

/**
* Defines `_WEBSOCKETPP_SYMBOL_EXPORT`, used to export certain symbols, such
* as exception types and `lib::error_category` singletons, that do not work
* correctly across shared library boundaries otherwise.
*/

#if !defined(_WEBSOCKETPP_SYMBOL_EXPORT) && !defined(_WEBSOCKETPP_NO_SYMBOL_EXPORT)
// `_WEBSOCKETPP_SYMBOL_EXPORT` can be predefined, or an empty definition
// can be forced by defining `_WEBSOCKETPP_NO_SYMBOL_EXPORT`.

#if defined(_WEBSOCKETPP_BOOST_SYMBOL_EXPORT)
// Just use `BOOST_SYMBOL_EXPORT` from Boost.Config .

#include <boost/config.hpp>
#define _WEBSOCKETPP_SYMBOL_EXPORT BOOST_SYMBOL_EXPORT

// The following is fairly portable, but there are some environments in
// which it might not work. If so, predefining `_WEBSOCKETPP_SYMBOL_EXPORT`
// or opting out entirely with `_WEBSOCKETPP_NO_SYMBOL_EXPORT` are viable
// alternatives.
#elif defined(__GNUC__) || defined(__clang__)
#if defined(_WIN32) || defined(__CYGWIN__)
#define _WEBSOCKETPP_SYMBOL_EXPORT __attribute__((dllexport))
#else
#define _WEBSOCKETPP_SYMBOL_EXPORT __attribute__((visibility("default")))
#endif
#elif defined(_WIN32)
#define _WEBSOCKETPP_SYMBOL_EXPORT __declspec(dllexport)
#endif
#endif

#ifndef _WEBSOCKETPP_SYMBOL_EXPORT
#define _WEBSOCKETPP_SYMBOL_EXPORT
#endif

#endif
5 changes: 3 additions & 2 deletions websocketpp/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <utility>

#include <websocketpp/common/cpp11.hpp>
#include <websocketpp/common/symbol_export.hpp>
#include <websocketpp/common/system_error.hpp>

namespace websocketpp {
Expand Down Expand Up @@ -232,7 +233,7 @@ class category : public lib::error_category {
}
};

inline const lib::error_category& get_category() {
inline _WEBSOCKETPP_SYMBOL_EXPORT const lib::error_category& get_category() {
static category instance;
return instance;
}
Expand All @@ -253,7 +254,7 @@ _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_

namespace websocketpp {

class exception : public std::exception {
class _WEBSOCKETPP_SYMBOL_EXPORT exception : public std::exception {
public:
exception(std::string const & msg, lib::error_code ec = make_error_code(error::general))
: m_msg(msg.empty() ? ec.message() : msg), m_code(ec)
Expand Down
3 changes: 2 additions & 1 deletion websocketpp/extensions/extension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define WEBSOCKETPP_EXTENSION_HPP

#include <websocketpp/common/cpp11.hpp>
#include <websocketpp/common/symbol_export.hpp>
#include <websocketpp/common/system_error.hpp>

#include <string>
Expand Down Expand Up @@ -78,7 +79,7 @@ class category : public lib::error_category {
}
};

inline lib::error_category const & get_category() {
inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() {
static category instance;
return instance;
}
Expand Down
3 changes: 2 additions & 1 deletion websocketpp/extensions/permessage_deflate/enabled.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <websocketpp/common/memory.hpp>
#include <websocketpp/common/platforms.hpp>
#include <websocketpp/common/stdint.hpp>
#include <websocketpp/common/symbol_export.hpp>
#include <websocketpp/common/system_error.hpp>
#include <websocketpp/error.hpp>

Expand Down Expand Up @@ -149,7 +150,7 @@ class category : public lib::error_category {
};

/// Get a reference to a static copy of the permessage-deflate error category
inline lib::error_category const & get_category() {
inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() {
static category instance;
return instance;
}
Expand Down
5 changes: 3 additions & 2 deletions websocketpp/http/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <vector>
#include <utility>

#include <websocketpp/common/symbol_export.hpp>
#include <websocketpp/common/system_error.hpp>

namespace websocketpp {
Expand Down Expand Up @@ -297,7 +298,7 @@ inline std::string get_string(value code) {
* HTTP error message, and a body to return with the HTTP
* error response.
*/
class exception : public std::exception {
class _WEBSOCKETPP_SYMBOL_EXPORT exception : public std::exception {
public:
exception(const std::string& log_msg,
status_code::value error_code,
Expand Down Expand Up @@ -435,7 +436,7 @@ class category : public lib::error_category {
};

/// Get a reference to a static copy of the asio transport error category
inline lib::error_category const & get_category() {
inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() {
static category instance;
return instance;
}
Expand Down
3 changes: 2 additions & 1 deletion websocketpp/transport/asio/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <websocketpp/common/asio.hpp>
#include <websocketpp/common/cpp11.hpp>
#include <websocketpp/common/functional.hpp>
#include <websocketpp/common/symbol_export.hpp>
#include <websocketpp/common/system_error.hpp>
#include <websocketpp/common/type_traits.hpp>

Expand Down Expand Up @@ -208,7 +209,7 @@ class category : public lib::error_category {
};

/// Get a reference to a static copy of the asio transport error category
inline lib::error_category const & get_category() {
inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() {
static category instance;
return instance;
}
Expand Down
3 changes: 2 additions & 1 deletion websocketpp/transport/base/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <websocketpp/common/cpp11.hpp>
#include <websocketpp/common/connection_hdl.hpp>
#include <websocketpp/common/functional.hpp>
#include <websocketpp/common/symbol_export.hpp>
#include <websocketpp/common/system_error.hpp>

#include <string>
Expand Down Expand Up @@ -216,7 +217,7 @@ class category : public lib::error_category {
}
};

inline lib::error_category const & get_category() {
inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() {
static category instance;
return instance;
}
Expand Down
3 changes: 2 additions & 1 deletion websocketpp/transport/debug/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <websocketpp/common/system_error.hpp>
#include <websocketpp/common/cpp11.hpp>
#include <websocketpp/common/symbol_export.hpp>

#include <string>

Expand Down Expand Up @@ -80,7 +81,7 @@ class category : public lib::error_category {
};

/// Get a reference to a static copy of the debug transport error category
inline lib::error_category const & get_category() {
inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() {
static category instance;
return instance;
}
Expand Down
3 changes: 2 additions & 1 deletion websocketpp/transport/iostream/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <websocketpp/common/cpp11.hpp>
#include <websocketpp/common/functional.hpp>
#include <websocketpp/common/connection_hdl.hpp>
#include <websocketpp/common/symbol_export.hpp>

#include <websocketpp/transport/base/connection.hpp>

Expand Down Expand Up @@ -109,7 +110,7 @@ class category : public lib::error_category {
};

/// Get a reference to a static copy of the iostream transport error category
inline lib::error_category const & get_category() {
inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() {
static category instance;
return instance;
}
Expand Down
3 changes: 2 additions & 1 deletion websocketpp/transport/stub/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define WEBSOCKETPP_TRANSPORT_STUB_BASE_HPP

#include <websocketpp/common/system_error.hpp>
#include <websocketpp/common/symbol_export.hpp>
#include <websocketpp/common/cpp11.hpp>

#include <string>
Expand Down Expand Up @@ -71,7 +72,7 @@ class category : public lib::error_category {
};

/// Get a reference to a static copy of the stub transport error category
inline lib::error_category const & get_category() {
inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() {
static category instance;
return instance;
}
Expand Down