|
比如我用
test.h test.cpp 定义我的测试类,main.c是主文件
下面是test.h
class base
{
public:
base():i(0){}
base(int in){i = in;}
void print();
private:
int i;
};
test.cpp
#include "test.h"
#include <iostream>
using namespace std;
void base::print()
{
cout << "i = "<<i <<endl; //这里用printf("i = %d \n ", i);也是一样的
}
main.c
extern "C"
{
#include "test.h" // 这里我不用extern也试过了
}
int main()
{
base x;
base y(7);
x.print();
y.print();
return 1;
}
以及makefile
main: main.c test.o extern.o
gcc -o main main.c test.o -lstdc++
test.o: test.cpp test.h
gcc -c test.cpp -lstdc++
用上面这个makefile就不行,下面的就可以
main: main.c test.o extern.o
g++ -o main main.c test.o
test.o: test.cpp test.h
g++ -c test.cpp
但现在项目中的编译器没有g++,只有gcc,我该怎么办呢? |
|