[英]Is it possible to link macfuse to a C++ static library?
您可以提供包裝器,將C ++類公開為C-API:
Something.h:
class Something {
protected:
int x;
public:
Something() { x = 0; }
void setX(int newX) { x = newX; }
int getX() const { return x; }
};
wrapper.h:
#pragma once
typedef void *SOMETHING;
#ifdef __cplusplus
extern "C" {
#endif
SOMETHING createSomething();
void destroySomething(SOMETHING something);
void setSomethingX(SOMETHING something, int x);
int getSomethingX(SOMETHING something);
#ifdef __cplusplus
} // extern "C"
#endif
wrapper.cpp:
#include <Something.h>
#include "wrapper.h"
SOMETHING createSomething() {
return static_cast<SOMETHING>(new Something());
}
void destroySomething(SOMETHING something) {
delete static_cast<Something *>(something);
}
void setSomethingX(SOMETHING something, int x) {
static_cast<Something *>(something)->setX(x);
}
int getSomethingX(SOMETHING something) {
return static_cast<Something *>(something)->getX();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.