0

関数を持つtemp1.cファイルがあります

int add(int a, int b){ return (a+b); }

temp1.h ファイル

int add(int,int)

コンパイルして.oファイルを作成しました

g++ -o temp1.o -c temp1.cpp

ここで、別のディレクトリに配置された temp2.​​cpp で add 関数を使用する必要があります。私はやった

#include "temp1.h"
int main(){
int x = add(5,2);
}

関数 add を呼び出すことができる temp2.​​exe を作成できるように、temp1.o で temp2.​​cpp をコンパイルする必要があります。それをコンパイルする方法は?

4

2 に答える 2

1
 g++ temp2.cpp temp1.o -o temp2.exe
于 2012-11-01T07:00:40.173 に答える
1

このような:

temp2: temp1.o temp2.o
     g++ temp1.o temp2.o -o temp

temp1.o: temp1.cpp
     g++ -c temp1.cpp -o temp1.o

temp2.o: temp2.cpp
     g++ -c your/path/to/temp2.cpp -o temp2.o
于 2012-11-01T07:01:47.427 に答える