Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 是否可以将macfuse链接到C++;静态库?_C++_Objective C_C - Fatal编程技术网

C++ 是否可以将macfuse链接到C++;静态库?

C++ 是否可以将macfuse链接到C++;静态库?,c++,objective-c,c,C++,Objective C,C,我已经成功地在OSX10.6.8上使用了C编程语言,而且效果非常好。 在某些时候,我需要开始函数调用到C++静态库(LBUTAOT.A)。从人们说,唯一可能的方法是修改C++源代码,使其可以从C(即在函数名和返回类型前准备好外部)C调用。不幸的是,我没有访问源代码,只是一个静态C++库*.file。p> 有什么方法可以将McFiSE转换成C++或ObjtoFeX程序,以便在静态库中调用C++函数?p> 我希望社区中的C/C++/Objective-C专家能够参与进来 我使用XCODE 4.3

我已经成功地在OSX10.6.8上使用了C编程语言,而且效果非常好。 在某些时候,我需要开始函数调用到C++静态库(LBUTAOT.A)。从人们说,唯一可能的方法是修改C++源代码,使其可以从C(即在函数名和返回类型前准备好外部)C调用。不幸的是,我没有访问源代码,只是一个静态C++库*.file。p>

有什么方法可以将McFiSE转换成C++或ObjtoFeX程序,以便在静态库中调用C++函数?p> 我希望社区中的C/C++/Objective-C专家能够参与进来


我使用XCODE 4.3

,可以提供一个包装器,将C++类暴露为C-API:

h:

class Something {
protected:
    int x;
public:
    Something() { x = 0; }
    void setX(int newX) { x = newX; }
    int getX() const { return x; }
};
h.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();
}
#包括
#包括“wrapper.h”
某物创造某物{
返回静态_cast(newsomething());
}
虚空破坏某物(某物){
删除静态施法(某物);
}
void setSomethingX(SOMETHING,int x){
静态施法(某物)->setX(x);
}
int getSomethingX(某物){
返回static_cast(something)->getX();
}

您可以提供包装器,将C++类暴露为C-API:

h:

class Something {
protected:
    int x;
public:
    Something() { x = 0; }
    void setX(int newX) { x = newX; }
    int getX() const { return x; }
};
h.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();
}
#包括
#包括“wrapper.h”
某物创造某物{
返回静态_cast(newsomething());
}
虚空破坏某物(某物){
删除静态施法(某物);
}
void setSomethingX(SOMETHING,int x){
静态施法(某物)->setX(x);
}
int getSomethingX(某物){
返回static_cast(something)->getX();
}