遇到了一个 在linux上c的需求 需要调用调用c++的sdk 为了调通环境先做个demo
c++库
first.h
#include <iostream>
using namespace std;
class hello
{
public:
void method();
};
first.cpp
#include "first.h"
void hello::method()
{
cout<<"hello world!\n";
}
然后编译成.so库放到/lib下
sudo g++ -fpic -shared -g -o /lib/libfirst.so first.cpp
注:动态库命名标准是lib+xxx+.so
中间层
second.h
#ifdef _cplusplus
extern "C"
{
#endif
void secondHello();
#ifdef _cplusplus
}
#endif
second.cpp
#include "first.h"
#ifndef _cplusplus
#define _cplusplus
#include "second.h"
#endif
void secondHello()
{
hello h;
h.method();
}
中间层的特点是用c的风格写c++ 由于头文件被c和