ヘッダーlab3p2.h基本的なメイクプログラム:メインエラー未定義の参照中に "電源"
#ifndef LAB3P2_H
#define LAB3P2_H
long power(int integer1, int integer2);
#endif
電源機能:
#include "lab3p2.h"
#include <stdio.h>
long power(int integer1, int integer2){
int i;
long ret =(long) integer1;
if(integer2 ==0)
{
ret = 1;
}else{
for(i =1 ; i < integer2; i++)
{
ret = ret * integer1;
}
}
return ret;
}
メインlab3p2f1.c:lab3p2.c
#include <stdio.h>
#include "lab3p2.h"
/*Takes in integers from the command line and returns the power function result*/
int main(int argc, char **argv){
int a = atoi(*(argv+1));
int b = atoi(*(argv+2));
int c =atoi(*(argv+3));
long functionResult;
functionResult = power(b,c);
printf("The result of the power function is %ld \n", functionResult);
}
MakeFile:メイクファイル
all: lab3p2
mkprog: lab3p2.o lab3p2f1.o
gcc lab3p2.o lab3p2f1.o -o lab3p2
lab3p2.o: lab3p2.c
gcc -ansi -pedantic -c lab3p2.c
lab3p2f1.o: lab3p2f1.c
gcc -ansi -pedantic -c lab3p2f1.c
clean:
rm -rf *.o lab3p2
なぜメインは機能にアクセスできませんか? 私はどのようにコンパイルしていますか? 何か助けていただければ幸いです。
ビルドログを表示してください。また、CとC++は異なる言語であることに注意してください。関連タグのみを使用してください(この場合はCと思われます)。 – kaylum
'make'や' make mkprog'だけでmakefileを起動していますか? – StoryTeller
'long'は' int'よりも広い範囲を持つと思いますか?そして、タグをスパムしないでください。これは明らかにCとしてコンパイルされています。 – Olaf