前提・実現したいこと
3つのソースコードを使ってプログラムを組んでいるのですが、エラーが出てき、そのエラーを解決する策がわかりません。
アドバイス等お願い致します。
発生している問題・エラーメッセージ
Undefined symbols for architecture x86_64: "_addList", referenced from: _main in kadai13-f84c84.o "_calcBMI", referenced from: _main in kadai13-f84c84.o "_listSize", referenced from: _main in kadai13-f84c84.o "_newList", referenced from: _main in kadai13-f84c84.o "_readPlayer", referenced from: _main in kadai13-f84c84.o "_top", referenced from: _main in kadai13-f84c84.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
該当のソースコード
c
1#include <stdio.h> 2#include <stdlib.h> 3#include "player.h" 4#include<errno.h> 5#include <string.h> 6 7Player player[100]; // 100人分の配列 8char fileIN[] = "z12-in.dat"; 9char fileOUT[]= "z12-out.dat"; 10 11// main 関数 12int main(int argc,char *argv[]) { 13 char *filename; 14 FILE *in,*out; 15 float sumWeight = 0.0; 16 int i; 17 Player *p; 18 List *lst; 19 20 if(argc>1) { 21 filename = argv[1]; 22 if((in = fopen(filename,"r")) == NULL) { 23 fprintf(stderr,"開けません(%s).\n", filename); 24 fprintf(stderr,"errno:[%d], strerror: [%s]\n", errno,strerror(errno)); 25 26 exit(1); 27 } 28 } else in = stdin; 29 30 if(argc>2) { 31 filename = argv[2]; 32 if((out = fopen(filename,"w")) == NULL) { 33 fprintf(stderr,"開けません(%s).\n", filename); 34 exit(1); 35 } 36 } else out = stdout; 37 38 while((p = readPlayer(in)) != NULL) { 39 sumWeight += p->weight; 40 calcBMI(p); 41 if(top == NULL) top = newList(p); 42 else if(top->player->VAR < p->VAR) { 43 List *nl = newList(p); 44 nl->next = top; 45 top = nl; 46 } else addList(top,p); 47 } 48 fclose(in); 49 50 fprintf(out,"苗字(家族名) 名前(個人名) 身長 体重 BMI\n"); 51 for(lst = top;lst != NULL; lst=lst->next) { 52 p = lst->player; 53 fprintf(out,"%-20s %-20s %3.0fcm %3.0fkg %6.2f\n", 54 p->familyName,p->personalName,p->height,p->weight,p->bmi); 55 } 56 // 統計データの出力(ここでは、平均体重) 57 fprintf(out, "平均体重は %6.2fkg\n", sumWeight/listSize(top)); 58 fclose(out); 59 return 0; 60} 61 62
list.c
1#include <stdio.h> 2#include <stdlib.h> 3#include "player.h" 4 5List *top = NULL; 6List *newList(Player *p) { 7 List *l = (List *)malloc(sizeof (List)); 8 l->player = p; 9 l->next = NULL; 10 return l; 11} 12 13 14void addList(List *l,Player *p) { 15 if(l->player->VAR < p->VAR) return ; 16 while(l->next) { 17 if(l->next->player->VAR < p->VAR) { 18 List *n = newList(p); 19 n->next = l->next; 20 l->next = n; 21 return; 22 } 23 l = l->next; 24 } 25 l->next = newList(p); 26} 27 28 29int listSize(List *t) { 30 int n = 0; 31 while(t != NULL) { 32 n++; 33 t = t->next; 34 } 35 return n; 36} 37 38 39Player *newPlayer() { 40 Player *p = (Player *)calloc(sizeof(Player),1); 41 return p; 42} 43 44 45Player *readPlayer(FILE *fh) { 46 Player *p = newPlayer(); 47 int n = fscanf(fh,"%s%s%f%f",&(p->familyName),&(p->personalName), 48 &(p->height),&(p->weight)); 49 if(n == 4) return p; 50 free(p); 51 return NULL; 52} 53 54 55void calcBMI(Player *p) { 56 p->bmi = p->weight / ((p->height/100)*(p->height/100)); 57}
player.h
1#ifndef __PLAYER_H__ 2#define __PLAYER_H__ 3#include <stdio.h> 4 5#define VAR height 6 7typedef struct { 8 char familyName[20]; 9 char personalName[20]; 10 float height; 11 float weight; 12 float bmi; 13} Player; 14 15typedef struct LIST { 16 Player *player; 17 struct LIST *next; 18} List; 19 20 21extern List *top; 22// 関数プロトタイプ宣言 23List *newList(Player *p); 24void addList(List *l,Player *p); 25int listSize(List *t); 26 27Player *newPlayer(); 28Player *readPlayer(FILE *fh); 29void calcBMI(Player *p); 30 31#endif
回答2件
あなたの回答
tips
プレビュー