- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我为此搜索了很多,但我真的想不通。我的项目包含 5 个 .c 文件和 4 个 .h header 。都在同一个文件夹中。我分别成功地编译了它们但是当涉及到组编译时(gcc -o progname 和 linux 环境中的所有代码文件或 dev-c++ 中的编译所有选项)我在这两种情况下都有这些错误:
C:\Users\user\...\main.o(.text+0x9a) In function `main':
[Linker error] undefined reference to `dhmiourgia_Words'
[Linker error] undefined reference to `katastrofh_Words'
C:\Users\user\...\main.o(.text+0x1fb) In function `InitialiseTree':
[Linker error] undefined reference to `InsertWord'
....
它继续无法识别我在 main.c 中使用的所有函数,在 Words.h 中定义并在 Words.c 中实现
我最初以为我错过了 header #include 预处理器命令,但正如您在这里看到的那样!我怎样才能克服这些错误?下面是问题所在的代码文件,欢迎大家指教,再次感谢
/* file: main.c */
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h> /* for gettimeofday() */
#include "typos_stoixeiouDDA.h"
#include "Words.h"
void InitialiseTree(FILE *wordlist, typosWords W, int totalwordsin);
void SearchUpdateTree(FILE *wordlist, typosWords W);
void Results(typosWords W, int totalwordsin);
int main(void)
{ typosWords A;
FILE *FirstList, *SecondList;
char ap;
char ylop='B';
char arxeio[25];
int totalwordsin=0;
printf("Den exei dhmiourgithei ATD-Words\nDhmiourgia? (n/N gia epivevaiwsh)\n");
fflush(stdin);
ap=getchar();
if((ap=='n')||(ap=='N')){
do{
printf("Epilekste ylopoihsh dendrou (A gia AVL, B gia BST)\n");
fflush(stdin);
ylop=getchar();
if((ylop=='B')||(ylop=='A')){
A=dhmiourgia_Words();
printf("Dwse onoma arxeiou-listas leksewn pros anazithsh(ston idio ypofakelo!)\n");
scanf(" %s ", arxeio);
if((FirstList=fopen(arxeio, "r"))==NULL)
printf("Sfalma kata to anoigma tou arxeiou\n");
InitialiseTree(FirstList, A, totalwordsin);
fclose(FirstList);
printf("Arxeio pros eksetash: RomeoAndJuliet.txt\n");
if((SecondList=fopen("RomeAndJuliet.txt", "r"))==NULL)
printf("Sfalma kata to anoigma tou arxeiou\n");
SearchUpdateTree(SecondList, A);
fclose(SecondList);
Results(A, totalwordsin);
katastrofh_Words(&A);
}
else printf("Lathos apantisi\n");
}while((ylop!='A')&&(ylop!='B'));
}
printf("Eyxaristoyme poy mas protimhsate!\n");
return 0;
}
void InitialiseTree(FILE *wordlist, typosWords W, int totalwordsin)
{
int i=0, res;
char word[20];
struct timeval start, t0, t1, t2, t3, t4, t5, t6, tALL;
double elapsedTime;
gettimeofday(&start, NULL); /* start timer */
do{
res=fscanf(wordlist,"%s\n", word);
InsertWord(W, word);
i++;
if(i==1024*(2^0))
gettimeofday(&t0, NULL); /* save time */
if(i==1024*(2^1))
gettimeofday(&t1, NULL); /* save time */
if(i==1024*(2^2))
gettimeofday(&t2, NULL); /* save time */
if(i==1024*(2^3))
gettimeofday(&t3, NULL); /* save time */
if(i==1024*(2^4))
gettimeofday(&t4, NULL); /* save time */
if(i==1024*(2^5))
gettimeofday(&t5, NULL); /* save time */
if(i==1024*(2^6))
gettimeofday(&t6, NULL); /* save time */
}while(res!=EOF);
totalwordsin=i;
gettimeofday(&tALL, NULL); /* save total time */
/* calculating time for 1024*2^0 words to be inserted */
elapsedTime = (t0.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t0.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 0);
/* calculating time for 1024*2^1 words to be inserted */
elapsedTime = (t1.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t1.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 1);
/* calculating time for 1024*2^2 words to be inserted */
elapsedTime = (t2.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t2.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 2);
/* calculating time for 1024*2^3 words to be inserted */
elapsedTime = (t3.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t3.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 3);
/* calculating time for 1024*2^4 words to be inserted */
elapsedTime = (t4.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t4.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 4);
/* calculating time for 1024*2^5 words to be inserted */
elapsedTime = (t5.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t5.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 5);
/* calculating time for 1024*2^6 words to be inserted */
elapsedTime = (t6.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t6.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 6);
/* calculating time for all words to be inserted */
elapsedTime = (tALL.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (tALL.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 7);
/* Reads words from wordlist(1)
inserts into DDA/AVL using InsertWord after 1024, 2048, 4096,... words
sets array times using SetInsertTime */
}
void SearchUpdateTree(FILE *wordlist, typosWords W)
{
struct timeval start, end;
double elapsedTime;
int res;
char word[20];
gettimeofday(&start, NULL); /* start timer */
do{
res=fscanf(wordlist,"%s\n", word);
CheckWord(W, word);
}while(res!=EOF);
gettimeofday(&end, NULL); /* stop timer */
elapsedTime = (end.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (end.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetCheckTime(W, elapsedTime);
/* Reads words from wordlist(2)-RandJ
calls CheckWord
saves total Check time */
}
void Results(typosWords W, int totalwordsin)
{
struct timeval start, end;
double elapsedTime;
char ap;
int fileout;
char arxeio[25];
FILE* out;
do{
printf("Pathste O gia emfanisi apotelesmatwn sthn othoni\n");
printf(" F gia emfanisi apotelesmatwn se arxeio keimenou\n");
fflush(stdin);
ap=getchar();
if(ap=='O')
fileout=0;
else if(ap=='F'){
fileout=1;
printf("Dwse onoma arxeiou gia emfanisi apotelesmatwn (ston idio ypofakelo!)\n");
scanf(" %s ", arxeio);
if((out=fopen(arxeio, "w"))==NULL)
printf("Sfalma kata to anoigma tou arxeiou\n");
}
else
printf("Lathos apantisi\n");
}while((ap!='O')&&(ap!='F'));
gettimeofday(&start, NULL); /* start timer */
ShowCommonWords(out, W, fileout);
gettimeofday(&end, NULL); /* stop timer */
elapsedTime = (end.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (end.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetDiadromhTime(W, elapsedTime);
fclose(out);
PrintTimes(out, W, fileout, totalwordsin);
}
/* file: Words.c */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "typos_stoixeiouDDA.h"
#include "Words.h"
#if ylop == 'B'
#include "BST_pointer-Recursive.h"
#elif ylop == 'A'
#include "AVL_pointer.h"
#endif
extern char ylop;
#if ylop == 'B' /* Ylopoihsh tou ATD-Words me aplo DDA(BST) */
typedef struct RecWords
{
typos_deikti WordsRiza; /* to Words apoteleitai apo to DDA */
float InsertTime [10]; /* xronoi eisagvghs ana 1024, 2048,... (7 sto synolo)
kai o xronos eisagogis OLWN twn leksevn
apo to epilegmeno arxeio eisodoy */
float CheckTime; /* xronos anazhthshs OLWN twn leksevn
apo to epilegmeno arxeio eisodoy */
float DiadromhTime; /* xronos diadromhs */
} RecWords;
typosWords dhmiourgia_Words()
{
typosWords WordsNew=malloc(sizeof(RecWords));
Tree_dimiourgia(&(WordsNew->WordsRiza));
return WordsNew;
}
void katastrofh_Words(typosWords * Wordsptr)
{
Tree_katastrofi(&(*Wordsptr)->WordsRiza);
free(*Wordsptr);
*Wordsptr=NULL;
}
void InsertWord(typosWords Words, char * w)
{
TStoixeioyTree stoixeio;
int* error=0;
strcpy(stoixeio.word, w);
stoixeio.frequency=0;
Tree_eisagogi(Words->WordsRiza, stoixeio, error);
if(*error) printf("Sfalma eisagogis stoixeioy sto dentro\n");
/*Input w
sets stoixeio DDA (kai ta 2 melh)
calls eisagogi_komvou sto DDA
*/
}
void CheckWord(typosWords Words, char * w)
{
TStoixeioyTree stoixeio;
int* error=0;
int* found=0;
typos_deikti* deiktis;
strcpy(stoixeio.word, w);
stoixeio.frequency=0;
Tree_anazitisi(Words->WordsRiza, stoixeio, deiktis, found);
if(*found) deiktis->frequency++;
/* Input w
sets stoixeio DDA (kai ta 2 melh)
calls anazitisi_komvou and
??if found
calls periexomena and set???
*/
}
void ShowCommonWords(FILE *out, typosWords Words, int fileout)
{
Tree_endodiat(Words->WordsRiza, fileout, out);
/* diadromh DDA me parametro function for testing if In2nd==1 */
}
/* praxeis poy diaxeirizontai toys xronoys */
void SetInsertTime(typosWords Words, float time, int position)
{
Words.InsertTime[position]=time;
/* Input time, position
sets Words.InsertTime[position]=time;
*/
}
void SetDiadromhTime(typosWords Words, float time)
{
Words.DiadromhTime=time;
/* Input time
sets Words.DiadromhTime=time;
*/
}
void PrintTimes(FILE *out, typosWords Words, int fileout, int totalwordsin)
{
int i;
if(!fileout){
for(i=0; i<=6 ; i++){
printf("Xronos eisagogis %d leksewn sto Words: %f\n", 1024*(2^i), Words->InsertTime[i]);
}
printf("Xronos eisagogis OLWN twn leksewn sto Words: %f\n", Words->InsertTime[7]);
printf("Xronos plhrous endodiatetagmenis diadromhs: %f\n", Words->DiadromiTime);
printf("Mesos xronos diadromis ana leksi: %f\n", (Words->DiadromiTime)/totalwordsin);
}
else{
for(i=0; i<=6 ; i++){
fprintf(out, "Xronos eisagogis %d leksewn sto Words: %f\n", 1024*(2^i), Words->InsertTime[i]);
}
fprintf(out, "Xronos eisagogis OLWN twn leksewn sto Words: %f\n", Words->InsertTime[7]);
fprintf(out, "Xronos plhrous endodiatetagmenis diadromhs: %f\n", Words->DiadromiTime);
fprintf(out, "Mesos xronos diadromis ana leksi: %f\n", (Words->DiadromiTime)/totalwordsin);
}
/* emfanizei sthn othoni InsertTimes, DiadromhTime */
}
#elif ylop == 'A' /* Ylopoihsh tou ATD-Words me AVL-Tree */
typedef struct RecWords
{
typos_deikti WordsRiza; /* to Words apoteleitai apo to AVL */
float InsertTime [10]; /* xronoi eisagvghs ana 1024, 2048,... (7 sto synolo)
kai o xronos eisagogis OLWN twn leksevn
apo to epilegmeno arxeio eisodoy */
float CheckTime; /* xronos anazhthshs OLWN twn leksevn
apo to epilegmeno arxeio eisodoy */
float DiadromhTime; /* xronos diadromhs */
} RecWords;
typosWords dhmiourgia_Words()
{
typosWords WordsNew=malloc(sizeof(RecWords));
AVLTree_dimiourgia(&(WordsNew->WordsRiza));
return WordsNew;
}
void katastrofh_Words(typosWords * Wordsptr)
{
AVLTree_katastrofi(&(*Wordsptr)->WordsRiza);
free(*Wordsptr);
*Wordsptr=NULL;
}
void InsertWord(typosWords Words, char * w)
{
TStoixeioyTree stoixeio;
int* error=0;
strcpy(stoixeio.word, w);
stoixeio.frequency=0;
AVLTree_eisagogi(Words->WordsRiza, stoixeio, error);
if(*error) printf("Sfalma eisagogis stoixeioy sto dentro\n");
/*Input w
sets stoixeio AVL (kai ta 2 melh)
calls eisagogi_komvou sto AVL
*/
}
void CheckWord(typosWords Words, char * w)
{
TStoixeioyTree stoixeio;
int* error=0;
int* found=0;
typos_deikti* deiktis;
strcpy(stoixeio.word, w);
stoixeio.frequency=0;
AVLTree_anazitisi(Words->WordsRiza, stoixeio, deiktis, found);
if(*found) deiktis->frequency++;
/* Input w
sets stoixeio AVL (kai ta 2 melh)
calls anazitisi_komvou and
??if found
calls periexomena and set???
*/
}
void ShowCommonWords(FILE *out, typosWords Words, int fileout)
{
AVLTree_endodiat(Words->WordsRiza, fileout, out);
/* diadromh DDA me parametro function for testing if In2nd==1 */
}
/* praxeis poy diaxeirizontai toys xronoys */
void SetInsertTime(typosWords Words, float time, int position)
{
Words.InsertTime[position]=time;
/* Input time, position
sets Words.InsertTime[position]=time;
*/
}
void SetDiadromhTime(typosWords Words, float time)
{
Words.DiadromhTime=time;
/* Input time
sets Words.DiadromhTime=time;
*/
}
void PrintTimes(FILE *out, typosWords Words, int fileout, int totalwordsin)
{
int i;
if(!fileout){
for(i=0; i<=6 ; i++){
printf("Xronos eisagogis %d leksewn sto Words: %f\n", 1024*(2^i), Words->InsertTime[i]);
}
printf("Xronos eisagogis OLWN twn leksewn sto Words: %f\n", Words->InsertTime[7]);
printf("Xronos plhrous endodiatetagmenis diadromhs: %f\n", Words->DiadromiTime);
printf("Mesos xronos diadromis ana leksi: %f\n", (Words->DiadromiTime)/totalwordsin);
}
else{
for(i=0; i<=6 ; i++){
fprintf(out, "Xronos eisagogis %d leksewn sto Words: %f\n", 1024*(2^i), Words->InsertTime[i]);
}
fprintf(out, "Xronos eisagogis OLWN twn leksewn sto Words: %f\n", Words->InsertTime[7]);
fprintf(out, "Xronos plhrous endodiatetagmenis diadromhs: %f\n", Words->DiadromiTime);
fprintf(out, "Mesos xronos diadromis ana leksi: %f\n", (Words->DiadromiTime)/totalwordsin);
}
/* emfanizei sthn othoni InsertTimes, DiadromhTime */
}
#endif
/* file: Words.h */
#ifndef __TYPOS_WORDS__
#define __TYPOS_WORDS__
#include <stdio.h>
/*orismos typou Words */
typedef struct RecWords * typosWords;
/* epikefalides praxewn */
/* praxeis poy yloioyntai me praxeis DDA */
typosWords dhmiourgia_Words();
void katastrofh_Words(typosWords * Wordsptr);
void InsertWord(typosWords Words, char * w);
void CheckWord(typosWords Words, char * w);
void ShowCommonWords(FILE *out, typosWords Words, int fileout);
/* praxeis poy diaxeirizontai toys xronoys */
void SetInsertTime(typosWords Words, float time, int position);
void SetCheckTime(typosWords Words, float time);
void SetDiadromhTime(typosWords Words, float time);
void PrintTimes(FILE *out, typosWords Words, int fileout, int totalwordsin);
#endif
命令行是: gcc -c Words.c main.c 和其他三个没有问题的源代码文件
(没问题)
然后 gcc -o Words.o main.o 和上面编译的三个目标文件
(这里弹出“ undefined reference ”)
与单个相同:gcc -o test Words.c main.c 和其他三个源代码文件
(再次弹出“ undefined reference ”)
最佳答案
在某些地方,您将 ylop
视为变量名,而在其他地方,您将其视为预处理器符号,您似乎没有在任何地方定义它。您需要先解决这个问题,然后才能正常工作。
关于c - 链接器错误 undefined reference ... c 中包含的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16693630/
我有一个类似于以下的结构。 class A { string title; List bItem; } class B { int pric
本地流 和 远程流 两者都是“媒体流列表 ”。 本地流 包含“本地媒体流 ” 对象 但是,远程流 包含“媒体流 ” 对象 为什么差别这么大? 当我使用“本地流 “- 这个对我有用: localVide
我正在尝试将 8 列虚拟变量转换为 8 级排名的一列。 我试图用这个公式来做到这一点: =IF(OR(A1="1");"1";IF(OR(B1="1");"2";IF(OR(C1="1");"3";I
我正在使用面向对象编程在 Python 中创建一个有点复杂的棋盘游戏的实现。 我的问题是,许多这些对象应该能够与其他对象交互,即使它们不包含在其中。 例如Game是一个对象,其中包含PointTrac
有没有办法获取与 contains 语句匹配的最深元素? 基本上,如果我有嵌套的 div,我想要最后一个元素而不是父元素: Needle $("div:contains('Needle')")
出于某种原因,我无法在 Google 上找到答案!但是使用 SQL contains 函数我怎么能告诉它从字符串的开头开始,即我正在寻找等同于的全文 喜欢 'some_term%'。 我知道我可以使用
我正在尝试创建一个正则表达式来匹配具有 3 个或更多元音的字符串。 我试过这个: [aeiou]{3,} 但它仅在元音按顺序排列时才有效。有什么建议吗? 例如: 塞缪尔 -> 有效 琼 -> 无效 S
嘿所以我遇到了这样的情况,我从数据库中拉回一个客户,并通过包含的方式包含所有案例研究 return (from c in db.Clients.Include("CaseStudies")
如果关键字是子字符串,我无法弄清楚为什么这个函数不返回结果。 const string = 'cake'; const substring = 'cak'; console.log(string.in
我正在尝试将包含特定文本字符串的任何元素更改为红色。在我的示例中,我可以将子元素变为蓝色,但是我编写“替换我”行的方式有些不正确;红色不会发生变化。我注意到“contains”方法通常写为 :cont
我想问一下我是否可以要求/包含一个语法错误的文件,如果不能,则require/include返回一个值,这样我就知道所需/包含的文件存在语法错误并且不能被要求/包含? file.php语法错误 inc
我想为所有包含youtube链接的链接添加一个rel。 这就是我正在使用的东西-但它没有用。有任何想法吗? $('a [href:contains(“youtube.com”)]')。attr('re
我正在尝试在 Elasticsearch 中查询。除搜索中出现“/”外,此功能均正常运行。查询如下所示 GET styling_rules/product_line_filters/_search {
我正在开发名为eBookRepository的ASP.NET MVC应用程序,其中包含在线图书。 电子书具有自己的标题,作者等。因此,现在我正在尝试实现搜索机制。我必须使用Elasticsearch作
我已阅读Firebase Documentation并且不明白什么是 .contains()。 以下是文档中 Firebase 数据库的示例规则: { "rules": { "rooms"
我的问题是我可以给出条件[ 'BookTitleMaster.id' => $xtitid, ] 如下所示 $bbookinfs = $this->BookStockin->BookIssue->fi
我需要能够使用 | 检查模式在他们中。例如,对于像“dtest|test”这样的字符串,像 d*|*t 这样的表达式应该返回 true。 我不是正则表达式英雄,所以我只是尝试了一些事情,例如: Reg
我想创建一个正则表达式来不匹配某些单词... 我的字符:var test = "é123rr;and;ià456;or;456543" 我的正则表达式:test.match(\((?!and)(?!o
我在 XSLT 中有一个名为 variable_name 的变量,如果相关产品具有名称为 A 或 B 或两者均为 A & 的属性,我将尝试将其设置为 1 B.
您好,我想让接待员和经理能够查看工作类型和费率并随后进行更新。但是技术人员只能查看不能更新。该图是否有效? 我读到扩展用例是由发起基本用例的参与者发起的。我应该如何区分技术人员只能启动基本案例而不能启
我是一名优秀的程序员,十分优秀!