linux下编译运行c程序出现有关问题
linux下编译运行c程序出现问题
大家好,问题比较多,请大家尽量帮忙解答,小可不胜感激!!
我在linux下尝试编译和运行c程序, 这个程序中用到了zlib 函数库, 其中有些函数如gzopen, gzclose之类的在我用gcc编译的时候出现了
/tmp/ccGlj7Is.o(.text+0x4d6): In function 'main':
:undefined reference to 'gzopen'的错误, 感觉应该还是函数库的事,我已经安装了zlib,查了很多网页都无法解决,但是似乎编译没有问题,是链接的问题,但是我不知道怎么处理,请各位帮忙。
2.顺便问下,我还有一个parser.c的文件中用到了一个parser.h的头文件,我必须把parser.h放在与parser.c的同一目录下吗?还需要什么其他的操作让parser.c可以用到parser.h吗?
由于小弟是linux新手,所以请各位尽量详细一点的说下步骤。
以下是小弟的相关代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
int main(int argc, char* argv[])
{
FILE *fPosting, *fDocId, *indexFileList, *statistic;
gzFile *fData, *fIndex;
char *indexBuf;
char *dataFileNamePool,*indexPool;
int len;
char * pch, *pch1;
char *url;
uLong begin, length;
int i=0;
int docId=0,ret=0;
char *pool = (char*)malloc(100000000);
char *buf=(char*)malloc(10000000);
char* docIdBuf;
char *docIdBufPtr;
char *dataPtr;
char *data = (char*)malloc(100000000);
char *index = (char*)malloc(10000000);
char *dataFileName = (char*)malloc(32*sizeof(char));
char *indexFileName = (char*)malloc(32*sizeof(char));
long long totalLength = 0;
int totalDoc=0;
int averageLength=0;
char * tmp=(char *)malloc(128);
//open and read the indexFileList.txt
indexFileList=fopen(argv[1],"r");
if (indexFileList == NULL)
{
printf("%s can not be opened!\n", argv[1]);
exit(1);
}
fseek(indexFileList,0,SEEK_END);
len=ftell(indexFileList);
fseek(indexFileList,0,SEEK_SET);
dataFileNamePool = (char*)malloc(len+1);
fread(dataFileNamePool,len,1,indexFileList);
fclose(indexFileList);
//for each data file and its correspending index file,
//first parer data page by page with the informtaion in index file
//then create postions and store in postionPool
//printf("%s",dataFileNamePool);
pch = strtok_r (dataFileNamePool,"\n",&dataFileNamePool);
docIdBuf =(char*)malloc(100000000);
memset(docIdBuf,'\0',sizeof(docIdBuf));
docIdBufPtr = docIdBuf;
while (pch != NULL)
{
//memory allocate
memset(data,'\0',sizeof(data));
memset(index,'\0',sizeof(index));
memset(dataFileName,'\0',sizeof(dataFileName));
memset(indexFileName,'\0',sizeof(indexFileName));
//concate to get file name
strcpy(dataFileName,"./");
strcat(dataFileName,pch);
strcat(dataFileName,"_data");
strcpy(indexFileName,"./");
strcat(indexFileName,pch);
strcat(indexFileName,"_index");
printf("reading data from file %s\n",dataFileName);
printf("reading index from file %s\n",indexFileName);
//open dataFile
fData=gzopen(dataFileName,"r");
if (fData == NULL)
{
printf("%s can not be opened!\n", dataFileName);
exit(1);
}
gzread(fData,data,100000000);
gzclose(fData);
//open index file
fIndex=gzopen(indexFileName,"r");
if (fIndex == NULL)
{
printf("%s can not be opened!\n", index);
大家好,问题比较多,请大家尽量帮忙解答,小可不胜感激!!
我在linux下尝试编译和运行c程序, 这个程序中用到了zlib 函数库, 其中有些函数如gzopen, gzclose之类的在我用gcc编译的时候出现了
/tmp/ccGlj7Is.o(.text+0x4d6): In function 'main':
:undefined reference to 'gzopen'的错误, 感觉应该还是函数库的事,我已经安装了zlib,查了很多网页都无法解决,但是似乎编译没有问题,是链接的问题,但是我不知道怎么处理,请各位帮忙。
2.顺便问下,我还有一个parser.c的文件中用到了一个parser.h的头文件,我必须把parser.h放在与parser.c的同一目录下吗?还需要什么其他的操作让parser.c可以用到parser.h吗?
由于小弟是linux新手,所以请各位尽量详细一点的说下步骤。
以下是小弟的相关代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
int main(int argc, char* argv[])
{
FILE *fPosting, *fDocId, *indexFileList, *statistic;
gzFile *fData, *fIndex;
char *indexBuf;
char *dataFileNamePool,*indexPool;
int len;
char * pch, *pch1;
char *url;
uLong begin, length;
int i=0;
int docId=0,ret=0;
char *pool = (char*)malloc(100000000);
char *buf=(char*)malloc(10000000);
char* docIdBuf;
char *docIdBufPtr;
char *dataPtr;
char *data = (char*)malloc(100000000);
char *index = (char*)malloc(10000000);
char *dataFileName = (char*)malloc(32*sizeof(char));
char *indexFileName = (char*)malloc(32*sizeof(char));
long long totalLength = 0;
int totalDoc=0;
int averageLength=0;
char * tmp=(char *)malloc(128);
//open and read the indexFileList.txt
indexFileList=fopen(argv[1],"r");
if (indexFileList == NULL)
{
printf("%s can not be opened!\n", argv[1]);
exit(1);
}
fseek(indexFileList,0,SEEK_END);
len=ftell(indexFileList);
fseek(indexFileList,0,SEEK_SET);
dataFileNamePool = (char*)malloc(len+1);
fread(dataFileNamePool,len,1,indexFileList);
fclose(indexFileList);
//for each data file and its correspending index file,
//first parer data page by page with the informtaion in index file
//then create postions and store in postionPool
//printf("%s",dataFileNamePool);
pch = strtok_r (dataFileNamePool,"\n",&dataFileNamePool);
docIdBuf =(char*)malloc(100000000);
memset(docIdBuf,'\0',sizeof(docIdBuf));
docIdBufPtr = docIdBuf;
while (pch != NULL)
{
//memory allocate
memset(data,'\0',sizeof(data));
memset(index,'\0',sizeof(index));
memset(dataFileName,'\0',sizeof(dataFileName));
memset(indexFileName,'\0',sizeof(indexFileName));
//concate to get file name
strcpy(dataFileName,"./");
strcat(dataFileName,pch);
strcat(dataFileName,"_data");
strcpy(indexFileName,"./");
strcat(indexFileName,pch);
strcat(indexFileName,"_index");
printf("reading data from file %s\n",dataFileName);
printf("reading index from file %s\n",indexFileName);
//open dataFile
fData=gzopen(dataFileName,"r");
if (fData == NULL)
{
printf("%s can not be opened!\n", dataFileName);
exit(1);
}
gzread(fData,data,100000000);
gzclose(fData);
//open index file
fIndex=gzopen(indexFileName,"r");
if (fIndex == NULL)
{
printf("%s can not be opened!\n", index);