将make与库中的问题链接到单独的文件夹中

时间:2014-10-29 22:40:27

标签: makefile gnu-make

所以我试图在一个程序上运行make,该程序包含其他地方包含的目标文件和库。但是,当我尝试链接这些目标文件和库时,我得到一堆错误,链接说函数有一个未定义的引用。

$(OBJ)/monitor.o: monitor.c list.h $(PTDIR)/standards.h $(PTDIR)/os.h $(OBJ)
    $(CC) $(CCFLAGS) -c monitor.c -I. -o $@

$(OBJ)/reader-writer.o: reader-writer.h reader-writer.c $(PTDIR)/os.h $(PTDIR)/standards.h $(OBJ)
    $(CC) $(CCFLAGS) -c reader-writer.c -I. -o $@

$(OBJ)/reader-writer-monitor.o: reader-writer-monitor.c $(PTDIR)/os.h $(PTDIR)/standards.h $(OBJ)
    $(CC) $(CCFLAGS) -c reader-writer-monitor.c -I. -o $@

$(OBJ)/libMonitor.a: $(OBJ)/monitor.o $(OBJ)/list_adders.o $(OBJ)/list_removers.o    $(OBJ)/list_movers.o
    ar -crvs $@ $^

$(OBJ)/reader-writer-test.o: reader-writer-test.c
    $(CC) $(CCFLAGS) -c $^ -I. -o $@

$(OBJ)/reader-writer-test: $(OBJ)/reader-writer-test.o (OBJ)/reader-writer.o $(OBJ)/libMonitor.a $(PTDIR)/os.h $(PTDIR)/standards.h
    $(CC) $(CCFLAGS) $^ -o reader-writer-test

 $(OBJ)/reader-writer-monitor:  $(OBJ)/reader-writer-monitor.o $(OBJ)/reader-writer.o     $(OBJ)/libMonitor.a  $(PTDIR)/os.h $(PTDIR)/standards.h
    $(CC) $(CCFLAGS) $(OBJ)/reader-writer-monitor.o $(OBJ)/reader-writer.o -L./$(OBJ)/Monitor  -o     reader-writer-monitor

与读写器和读写器监视器同时进行。我知道这是一个链接问题,但我似乎无法找到指出的地方。我认为这与所有内容的.o声明有关,因为错误确实与pthreads的一些其他未定义的引用有关。有关如何解决此问题的任何帮助吗?

user@tux2:~/Desktop/CMPT332/group18/Trunk/A2> make all
gcc -Wall -g -pedantic -c list_adders.c -I. -o objdir/Linux/list_addersB.o -m64
list_adders.c: In function 'ListCreate':
list.h:91:4: warning: return makes pointer from integer without a cast [enabled by default]
    return NULL;\
    ^
list_adders.c:85:4: note: in expansion of macro 'HeaderGet'
    HeaderGet(headerRet);
    ^
gcc -Wall -g -pedantic -c list_movers.c -I. -o objdir/Linux/list_moversB.o -m64
gcc -Wall -g -pedantic -c list_removers.c -I. -o objdir/Linux/list_removersB.o -m64
ar -rcs objdir/Linux/libListB.a objdir/Linux/list_addersB.o objdir/Linux/list_moversB.o objdir/Linux/list_removersB.o
gcc -Wall -g -pedantic -c list_adders.c -I. -o objdir/Linux/list_adders.o -m32
gcc -Wall -g -pedantic -c list_movers.c -I. -o objdir/Linux/list_movers.o -m32
gcc -Wall -g -pedantic -c list_removers.c -I. -o objdir/Linux/list_removers.o -m32
ar -rcs objdir/Linux/libListC.a objdir/Linux/list_adders.o objdir/Linux/list_movers.o objdir/Linux/list_removers.o
gcc -Wall -g -pedantic -c monitor.c -I. -o objdir/Linux/monitor.o
ar -rcs objdir/Linux/libMonitor.a objdir/Linux/monitor.o objdir/Linux/list_adders.o objdir/Linux/list_removers.o objdir/Linux/list_movers.o
gcc -Wall -g -pedantic -c reader-writer-monitor.c -I. -o objdir/Linux/reader-writer-monitor.o
gcc -Wall -g -pedantic -c reader-writer.c -I. -o objdir/Linux/reader-writer.o
gcc -Wall -g -pedantic objdir/Linux/reader-writer-monitor.o objdir/Linux/reader-writer.o -L./objdir/Linux/Monitor  -o reader-writer-monitor
/usr/lib/gcc/x86_64-mageia-linux-gnu/4.8.2/../../../../lib64/crt1.o: In function '_start':
/home/iurt/rpmbuild/BUILD/glibc-2.18/csu/../sysdeps/x86_64/start.S:118: undefined reference to 'main'
objdir/Linux/reader-writer-monitor.o: In function 'StartRead':
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:36: undefined reference to 'MonEnter'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:41: undefined reference to 'MonWait'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:54: undefined reference to 'MonSignal'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:56: undefined reference to 'MonLeave'
objdir/Linux/reader-writer-monitor.o: In function 'StopRead':
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:62: undefined reference to 'MonEnter'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:66: undefined reference to 'MonSignal'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:67: undefined reference to 'MonLeave'
objdir/Linux/reader-writer-monitor.o: In function 'StartWrite':
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:74: undefined reference to 'MonEnter'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:78: undefined reference to 'MonWait'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:80: undefined reference to 'MonLeave'
objdir/Linux/reader-writer-monitor.o: In function 'StopWrite':
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:85: undefined reference to 'MonEnter'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:89: undefined reference to 'MyPid'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:96: undefined reference to 'MonSignal'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer-monitor.c:98: undefined reference to 'MonLeave'
objdir/Linux/reader-writer.o: In function 'reader':
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer.c:39: undefined reference to 'Sleep'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer.c:42: undefined reference to 'Sleep'
objdir/Linux/reader-writer.o: In function 'writer':
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer.c:59: undefined reference to 'Sleep'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer.c:62: undefined reference to 'Sleep'
objdir/Linux/reader-writer.o: In function 'mainp':
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer.c:73: undefined reference to 'MonInit'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer.c:77: undefined reference to 'Create'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer.c:79: undefined reference to 'Create'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer.c:81: undefined reference to 'Create'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer.c:83: undefined reference to 'Create'
/student/user/Desktop/CMPT332/group18/Trunk/A2/reader-writer.c:85: undefined reference to 'Create'
collect2: error: ld returned 1 exit status

0 个答案:

没有答案