[英]Is it possible to link macfuse to a C++ static library?
I have successfully used MacFUSE in the C programming language on OS X 10.6.8 and it works great. 我已经在OS X 10.6.8的C编程语言中成功使用了MacFUSE ,并且效果很好。 At some point I need to start making functions calls to a C++ static library (libSomething.a). 在某个时候,我需要开始对C ++静态库(libSomething.a)进行函数调用。 From this question people are saying the only way this is possible is modify the c++ source code to make it callable from C (ie prepend extern "C" before function name and return type). 人们从这个问题开始说,唯一可行的方法是修改c ++源代码以使其可从C调用(即在函数名称和返回类型之前加前缀“ C”)。 Unfortunately, I do not have access to the source code, just a static C++ library *.a file. 不幸的是,我无权访问源代码,只有静态C ++库* .a文件。
Is there some way I can convert MacFUSE into a C++ or Objective-C program to allow for invoking C++ functions inside a static library? 有什么方法可以将MacFUSE转换为C ++或Objective-C程序,以允许在静态库中调用C ++函数?
I would appreciate the C/C++/Objective-C experts in the community to weigh in on this. 我希望社区中的C / C ++ / Objective-C专家对此有所帮助。
I'm using Xcode 4.3 我正在使用Xcode 4.3
You could provide a wrapper, exposing the C++ class as a C-API: 您可以提供包装器,将C ++类公开为C-API:
Something.h: Something.h:
class Something {
protected:
int x;
public:
Something() { x = 0; }
void setX(int newX) { x = newX; }
int getX() const { return x; }
};
wrapper.h: 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: 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.