alanxz / SimpleAmqpClient

Simple C++ Interface to rabbitmq-c
MIT License
397 stars 213 forks source link

Linking error for Windows DLL for static class variables in Channel.hpp #312

Open CayOest opened 1 year ago

CayOest commented 1 year ago

Hi, when linking against the dynamic Windows DLL of SimpleAmqpClient, the following error occurs:

error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const AmqpClient::Channel::EXCHANGE_TYPE_DIRECT" (?EXCHANGE_TYPE_DIRECT@Channel@AmqpClient@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B)
3>C:\dev\cpp\x64\Debug\example-service.exe : fatal error LNK1120: 1 unresolved externals

This happens because the static variable EXCHANGE_TYPE_DIRECT is not exported.

See https://stackoverflow.com/questions/2479784/exporting-static-data-in-a-dll .

Hence, there should be some some getters/setters to set the three static variables in class Channel: static const std::string EXCHANGE_TYPE_DIRECT; ///< "direct" string constant static const std::string EXCHANGE_TYPE_FANOUT; ///< "fanout" string constant static const std::string EXCHANGE_TYPE_TOPIC; ///< "topic" string constant

Or some other solution.

CayOest commented 1 year ago

Since it seems to be used in Channel::DeclareExchange only, the simplest solution would be to directly set the default argument of the function as void DeclareExchange( const std::string &exchange_name, const std::string &exchange_type = "direct", bool passive = false, bool durable = false, bool auto_delete = false);