尽管我列入“#包括”我的代码,当我使用内置qsort函数,铛给我的错误:铛链接错误:未定义参考“快速排序”
schedule.o: In function `chooseTicket':
schedule.c:(.text+0x16d): undefined reference to `qsort'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
启动该文件(schedule.c)是这样的:
#include "sched.h"
#include "schedproc.h"
#include <assert.h>
#include <minix/com.h>
#include <machine/archtypes.h>
#include <stdlib.h>
#include <lib.h>
#include <string.h>
#include <time.h>
这里是我使用的快速排序的内置函数的函数
int chooseTicket(int* ticketList,int length,int totalTicket){
int randomValue;
int temp=0,prevTemp=0,selectedTicket=0,selectedIndex = 0;
time_t t;
struct schedproc *rmp;
int* sortedTicketList = malloc(length*sizeof(int));
memcpy(sortedTicketList,ticketList,length);
srandom((unsigned)time(&t));
randomValue = (random() % totalTicket);
qsort(sortedTicketList,length,sizeof(int),cmpFunc);//this line
注意:同样的错误也发生在'rand()'和'srand()'函数,而我使用'random()'和'srandom()',那么问题就解决了。尽管'rand()'和'srand()'是普遍接受的函数,头文件包含这些函数,但我不明白为什么铿锵声给出了链接错误,而我正在使用'rand()'和'srand )。
旁白:。移动'srandom((无符号)时间(&t));'到'main()的'你应该播种RNG的[只有一次 –
可能的复制什么是未定义参考/解析的外部符号错误,我怎么修复它?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-doi-i-fix) –
Can你展示了你用来构建你的软件的clang命令? – chrisaycock