marteli@marteli-Aspire-E5-575G:~/Downloads/Lab06$ make all
gcc -c -g -Wall -o scheduler.o scheduler.c
scheduler.c: In function ‘update_run_time’:
scheduler.c:47:37: warning: passing argument 2 of ‘clock_gettime’ from incompatible pointer type [-Wincompatible-pointer-types]
if (clock_gettime( CLOCK_REALTIME, &final)== -1)
^
In file included from scheduler.c:6:0:
/usr/include/time.h:342:12: note: expected ‘struct timespec *’ but argument is of type ‘struct timespec **’
extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
^
scheduler.c: In function ‘update_wait_time’:
scheduler.c:71:37: warning: passing argument 2 of ‘clock_gettime’ from incompatible pointer type [-Wincompatible-pointer-types]
if (clock_gettime( CLOCK_REALTIME, &final)== -1)
^
In file included from scheduler.c:6:0:
/usr/include/time.h:342:12: note: expected ‘struct timespec *’ but argument is of type ‘struct timespec **’
extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
^
scheduler.c: In function ‘main’:
scheduler.c:375:3: warning: implicit declaration of function ‘print_help’ [-Wimplicit-function-declaration]
print_help(argv[0]);
^
gcc -c -g -Wall -o worker.o worker.c
gcc -c -g -Wall -o list.o list.c
list.c: In function ‘print_list’:
list.c:90:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
printf("0x%X,", (unsigned int)le->info);
^
gcc -g -lpthread -lrt -Wall -o scheduler scheduler.o worker.o list.o
scheduler.o: In function `init_sched_queue':
/home/marteli/Downloads/Lab06/scheduler.c:89: undefined reference to `sem_init'
/home/marteli/Downloads/Lab06/scheduler.c:96: undefined reference to `timer_create'
scheduler.o: In function `resume_worker':
/home/marteli/Downloads/Lab06/scheduler.c:112: undefined reference to `pthread_kill'
scheduler.o: In function `cancel_worker':
/home/marteli/Downloads/Lab06/scheduler.c:126: undefined reference to `pthread_kill'
scheduler.o: In function `suspend_worker':
/home/marteli/Downloads/Lab06/scheduler.c:169: undefined reference to `pthread_kill'
scheduler.o: In function `clean_up':
/home/marteli/Downloads/Lab06/scheduler.c:287: undefined reference to `sem_destroy'
scheduler.o: In function `create_workers':
/home/marteli/Downloads/Lab06/scheduler.c:312: undefined reference to `pthread_create'
/home/marteli/Downloads/Lab06/scheduler.c:316: undefined reference to `pthread_detach'
scheduler.o: In function `scheduler_run':
/home/marteli/Downloads/Lab06/scheduler.c:341: undefined reference to `timer_settime'
scheduler.o: In function `start_scheduler':
/home/marteli/Downloads/Lab06/scheduler.c:356: undefined reference to `pthread_create'
scheduler.o: In function `main':
/home/marteli/Downloads/Lab06/scheduler.c:375: undefined reference to `print_help'
/home/marteli/Downloads/Lab06/scheduler.c:383: undefined reference to `print_help'
/home/marteli/Downloads/Lab06/scheduler.c:409: undefined reference to `pthread_join'
worker.o: In function `cancel_thread':
/home/marteli/Downloads/Lab06/worker.c:16: undefined reference to `sem_post'
worker.o: In function `enter_scheduler_queue':
/home/marteli/Downloads/Lab06/worker.c:50: undefined reference to `sem_wait'
worker.o: In function `start_worker':
/home/marteli/Downloads/Lab06/worker.c:95: undefined reference to `pthread_sigmask'
/home/marteli/Downloads/Lab06/worker.c:105: undefined reference to `pthread_sigmask'
collect2: error: ld returned 1 exit status
Makefile:11: recipe for target 'scheduler' failed
make: *** [scheduler] Error 1
marteli@marteli-Aspire-E5-575G:~/Downloads/Lab06$ ^C
marteli@marteli-Aspire-E5-575G:~/Downloads/Lab06$ make all
gcc -g -pthread -lrt -Wall -o scheduler scheduler.o worker.o list.o
scheduler.o: In function `init_sched_queue':
/home/marteli/Downloads/Lab06/scheduler.c:96: undefined reference to `timer_create'
scheduler.o: In function `scheduler_run':
/home/marteli/Downloads/Lab06/scheduler.c:341: undefined reference to `timer_settime'
scheduler.o: In function `main':
/home/marteli/Downloads/Lab06/scheduler.c:375: undefined reference to `print_help'
/home/marteli/Downloads/Lab06/scheduler.c:383: undefined reference to `print_help'
collect2: error: ld returned 1 exit status
Makefile:11: recipe for target 'scheduler' failed
make: *** [scheduler] Error 1
包含所有未定义引用的第一个编译是在makefile运行-lpthread时。当我将-lpthread更改为-pthread时,我得到了更好的结果,但我仍然得到未定义的引用。我无法找到" print_help"的任何内容,但我明白-lrt应该解决我现在拥有的问题,但你可以看到它已经包含在make中了。 编辑:修复我的clock_gettime()错误后,我编译,这是新的日志
marteli@marteli-Aspire-E5-575G:~/Downloads/Lab06$ make all
gcc -c -g -Wall -o scheduler.o scheduler.c
scheduler.c: In function ‘main’:
scheduler.c:375:3: warning: implicit declaration of function ‘print_help’ [-Wimplicit-function-declaration]
print_help(argv[0]);
^
gcc -g -pthread -lrt -Wall -o scheduler scheduler.o worker.o list.o
scheduler.o: In function `init_sched_queue':
/home/marteli/Downloads/Lab06/scheduler.c:96: undefined reference to `timer_create'
scheduler.o: In function `scheduler_run':
/home/marteli/Downloads/Lab06/scheduler.c:341: undefined reference to `timer_settime'
scheduler.o: In function `main':
/home/marteli/Downloads/Lab06/scheduler.c:375: undefined reference to `print_help'
/home/marteli/Downloads/Lab06/scheduler.c:383: undefined reference to `print_help'
collect2: error: ld returned 1 exit status
Makefile:11: recipe for target 'scheduler' failed
make: *** [scheduler] Error 1
更新2:省略print_help后,这是终端
marteli@marteli-Aspire-E5-575G:~/Downloads/Lab06$ make all
gcc -c -g -Wall -o scheduler.o scheduler.c
gcc -g -pthread -lrt -Wall -o scheduler scheduler.o worker.o list.o
scheduler.o: In function `init_sched_queue':
/home/marteli/Downloads/Lab06/scheduler.c:96: undefined reference to `timer_create'
scheduler.o: In function `scheduler_run':
/home/marteli/Downloads/Lab06/scheduler.c:341: undefined reference to `timer_settime'
collect2: error: ld returned 1 exit status
Makefile:11: recipe for target 'scheduler' failed
make: *** [scheduler] Error 1
答案 0 :(得分:3)
库必须在之后在编译器命令行上依赖于它们的目标文件,而不是在开头。所以:
gcc -g -Wall -o scheduler scheduler.o worker.o list.o -lpthread -lrt
除此之外,您需要在程序运行之前纠正(请参阅警告)中的一些严重错误。