am试图从git编译开源dll,出现以下错误:
错误(活动)无法定义dllimport实体cppkafka
错误'cppkafka :: Queue :: DEFAULT_TIMEOUT':不允许定义dllimport静态数据成员
错误C2491'cppkafka :: KafkaHandleBase :: DEFAULT_TIMEOUT':不允许定义dllimport静态数据成员
错误C2491'cppkafka :: BackoffPerformer :: DEFAULT_INITIAL_BACKOFF':dllimport静态数据成员的定义不允许
错误C2491'cppkafka :: BackoffPerformer :: DEFAULT_BACKOFF_STEP':DLLimport静态数据成员的定义不允许
错误C2491'cppkafka :: BackoffPerformer :: DEFAULT_MAXIMUM_BACKOFF':不允许定义dllimport静态数据成员
错误C2491'cppkafka :: BackoffPerformer :: DEFAULT_MAXIMUM_RETRIES':不允许定义dllimport静态数据成员
这些类是:
这是头文件:
//#ifdef BUILDING_MYDLL
//#define CPPKAFKA_API __declspec(dllexport)
//#else
//#define CPPKAFKA_API __declspec(dllimport)
//#endif
#ifndef CPPKAFKA_BACKOFF_PERFORMER_H
#define CPPKAFKA_BACKOFF_PERFORMER_H
#include <chrono>
#include <functional>
#include <thread>
#include "consumer.h"
namespace cppkafka {
/**
*
*/
class CPPKAFKA_API BackoffPerformer {
public:
using TimeUnit = std::chrono::milliseconds;
static const TimeUnit DEFAULT_INITIAL_BACKOFF;
static const TimeUnit DEFAULT_BACKOFF_STEP;
static const TimeUnit DEFAULT_MAXIMUM_BACKOFF;
static const size_t DEFAULT_MAXIMUM_RETRIES;
/**
* The backoff policy to use
*/
enum class BackoffPolicy {
LINEAR,
EXPONENTIAL
};
/**
* Constructs an instance of backoff performer
*
* By default, the linear backoff policy is used
*/
BackoffPerformer();
/**
* \brief Sets the backoff policy
*
* \param policy The backoff policy to be used
*/
void set_backoff_policy(BackoffPolicy policy);
/**
* \brief Sets the initial backoff
*
* The first time a commit fails, this will be the delay between the request is sent
* and we re-try doing so
*
* \param value The value to be used
*/
void set_initial_backoff(TimeUnit value);
/**
* \brief Sets the backoff step
*
* When using the linear backoff policy, this will be the delay between sending a request
* that fails and re-trying it
*
* \param value The value to be used
*/
void set_backoff_step(TimeUnit value);
/**
* \brief Sets the maximum backoff
*
* The backoff used will never be larger than this number
*
* \param value The value to be used
*/
void set_maximum_backoff(TimeUnit value);
/**
* \brief Sets the maximum number of retries for the commit operation
*
* \param value The number of retries before giving up
*
* \remark Setting value to 0 is equivalent to 1, i.e. it will try at least once
*/
void set_maximum_retries(size_t value);
/**
* \brief Executes an action and backs off if it fails
*
* This will call the functor and will retry in case it returns false
*
* \param callback The action to be executed
*/
template <typename Functor>
void perform(const Functor& callback) {
TimeUnit backoff = initial_backoff_;
size_t retries = maximum_retries_;
while (retries--) {
auto start = std::chrono::steady_clock::now();
// If the callback returns true, we're done
if (callback()) {
return;
}
auto end = std::chrono::steady_clock::now();
auto time_elapsed = end - start;
// If we still have time left, then sleep
if (time_elapsed < backoff) {
std::this_thread::sleep_for(backoff - time_elapsed);
}
// Increase out backoff depending on the policy being used
backoff = increase_backoff(backoff);
}
}
private:
TimeUnit increase_backoff(TimeUnit backoff);
TimeUnit initial_backoff_;
TimeUnit backoff_step_;
TimeUnit maximum_backoff_;
BackoffPolicy policy_;
size_t maximum_retries_;
};
} // cppkafka
#endif // CPPKAFKA_BACKOFF_PERFORMER_H
.cpp:
#include <algorithm>
#include <limits>
#include "utils\backoff_performer.h"
using std::min;
using std::numeric_limits;
namespace cppkafka {
const BackoffPerformer::TimeUnit BackoffPerformer::DEFAULT_INITIAL_BACKOFF{100};
const BackoffPerformer::TimeUnit BackoffPerformer::DEFAULT_BACKOFF_STEP{50};
const BackoffPerformer::TimeUnit BackoffPerformer::DEFAULT_MAXIMUM_BACKOFF{1000};
const size_t BackoffPerformer::DEFAULT_MAXIMUM_RETRIES{numeric_limits<size_t>::max()};
BackoffPerformer::BackoffPerformer()
: initial_backoff_(DEFAULT_INITIAL_BACKOFF),
backoff_step_(DEFAULT_BACKOFF_STEP), maximum_backoff_(DEFAULT_MAXIMUM_BACKOFF),
policy_(BackoffPolicy::LINEAR), maximum_retries_(DEFAULT_MAXIMUM_RETRIES) {
}
void BackoffPerformer::set_backoff_policy(BackoffPolicy policy) {
policy_ = policy;
}
void BackoffPerformer::set_initial_backoff(TimeUnit value) {
initial_backoff_ = value;
}
void BackoffPerformer::set_backoff_step(TimeUnit value) {
backoff_step_ = value;
}
void BackoffPerformer::set_maximum_backoff(TimeUnit value) {
maximum_backoff_ = value;
}
void BackoffPerformer::set_maximum_retries(size_t value) {
maximum_retries_ = value == 0 ? 1 : value;
}
BackoffPerformer::TimeUnit BackoffPerformer::increase_backoff(TimeUnit backoff) {
if (policy_ == BackoffPolicy::LINEAR) {
backoff = backoff + backoff_step_;
}
else {
backoff = backoff * 2;
}
return min(backoff, maximum_backoff_);
}
} // cppkafka
该语言的新手,请为我提供指导。