a.c (main)
#include
#include "b.h"

int main()
{
printf("%d\n", sum(3,2));
show_name("clockwork");
return 0;
}


b.h (宣告)
#ifdef __cplusplus
extern "C" {
#endif
int sum(int, int);
void show_name(char*);
#ifdef __cplusplus
}
#endif


b.cpp (be called function)
#include
#include
#include "b.h"
using namespace std;

int sum(int a, int b)
{
return a+b;
}
void show_name(char* name)
{
string str(name);
cout << "Hi, " << str << endl;
}

++++++++++++編譯方法+++++++++++++++++++++
gcc -c a.c
g++ -c b.cpp
g++ -o test a.o b.o
arrow
arrow
    全站熱搜

    gordli 發表在 痞客邦 留言(1) 人氣()