gpt4 book ai didi

Linux 中的 C 库链接

转载 作者:行者123 更新时间:2023-11-30 19:43:19 25 4
gpt4 key购买 nike

我一直在编写 C 代码,我需要 libxls.h 头文件的一些函数。我已经下载了相应的文件并按照安装说明进行操作。这些文件还包含我尝试编译的测试 C 代码 (test.c)。结果如下:

  1. 编译 test.c 文件的命令-gcc test.c -lm

结果:

[root@XXXXXXX95549 test]# gcc test.c -lm
test.c:28:24: error: libxls/xls.h: No such file or directory
test.c: In function ‘main’:
test.c:33: error: ‘xlsWorkBook’ undeclared (first use in this function)
test.c:33: error: (Each undeclared identifier is reported only once
test.c:33: error: for each function it appears in.)
test.c:33: error: ‘pWB’ undeclared (first use in this function)
test.c:34: error: ‘xlsWorkSheet’ undeclared (first use in this function)
test.c:34: error: ‘pWS’ undeclared (first use in this function)
test.c:39: error: ‘WORD’ undeclared (first use in this function)
test.c:39: error: expected ‘;’ before ‘t’
test.c:53: error: ‘t’ undeclared (first use in this function)
test.c:58: error: ‘tt’ undeclared (first use in this function)
test.c:60: error: dereferencing pointer to incomplete type
test.c:63: error: dereferencing pointer to incomplete type
test.c:64: error: dereferencing pointer to incomplete type
test.c:66: error: dereferencing pointer to incomplete type
test.c:67: error: dereferencing pointer to incomplete type
test.c:68: error: dereferencing pointer to incomplete type
test.c:70: error: dereferencing pointer to incomplete type
test.c:70: error: dereferencing pointer to incomplete type
test.c:71: error: dereferencing pointer to incomplete type
  • 为了解决这个问题,我将库文件复制到了“/user/include”位置
  • 之后相同编译命令的结果是:

    [root@XXXXXX95549 test]# gcc test.c -lm
    /tmp/cc8DJETV.o: In function `main':
    test.c:(.text+0x14): undefined reference to `xls_open'
    test.c:(.text+0xd4): undefined reference to `xls_getWorkSheet'
    test.c:(.text+0xe4): undefined reference to `xls_parseWorkSheet'
    test.c:(.text+0xf0): undefined reference to `xls_getCSS'
    test.c:(.text+0x49c): undefined reference to `xls_showBookInfo'
    collect2: ld returned 1 exit status

    请解释一下如何解决此问题。

    代码test.c如下:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>

    #include <libxls/xls.h>

    int main()
    {

    xlsWorkBook* pWB;
    xlsWorkSheet* pWS;
    FILE *f;
    int i;

    struct st_row_data* row;
    WORD t,tt;
    pWB=xls_open("files/test2.xls", "ASCII"); // "KOI8-R"

    if (pWB!=NULL)
    {
    f=fopen ("test.htm", "w");
    for (i=0;i<pWB->sheets.count;i++)
    printf("Sheet N%i (%s) pos %i\n",i,pWB->sheets.sheet[i].name,pWB->sheets.sheet[i].filepos);

    pWS=xls_getWorkSheet(pWB,0);
    xls_parseWorkSheet(pWS);
    fprintf(f,"<style type=\"text/css\">\n%s</style>\n",xls_getCSS(pWB));
    fprintf(f,"<table border=0 cellspacing=0 cellpadding=2>");

    for (t=0;t<=pWS->rows.lastrow;t++)
    {
    row=&pWS->rows.row[t];
    // xls_showROW(row->row);
    fprintf(f,"<tr>");
    for (tt=0;tt<=pWS->rows.lastcol;tt++)
    {
    if (!row->cells.cell[tt].ishiden)
    {
    fprintf(f,"<td");
    if (row->cells.cell[tt].colspan)
    fprintf(f," colspan=%i",row->cells.cell[tt].colspan);
    // if (t==0) fprintf(f," width=%i",row->cells.cell[tt].width/35);
    if (row->cells.cell[tt].rowspan)
    fprintf(f," rowspan=%i",row->cells.cell[tt].rowspan);
    fprintf(f," class=xf%i",row->cells.cell[tt].xf);
    fprintf(f,">");
    if (row->cells.cell[tt].str!=NULL && row->cells.cell[tt].str[0]!='\0')
    fprintf(f,"%s",row->cells.cell[tt].str);
    else
    fprintf(f,"%s","&nbsp;");
    fprintf(f,"</td>");
    }
    }
    fprintf(f,"</tr>\n");
    }
    fprintf(f,"</table>");
    printf("Count of rows: %i\n",pWS->rows.lastrow);
    printf("Max col: %i\n",pWS->rows.lastcol);
    printf("Count of sheets: %i\n",pWB->sheets.count);

    fclose(f);
    xls_showBookInfo(pWB);
    }

    return 0;
    }

    提前致谢,

    最佳答案

    在以下位置找到了此问题的答案:

    http://www.cprogramdevelop.com/2018568/

    那些可能遇到 libxls 库问题的人可以引用上述网站。

    干杯

    关于Linux 中的 C 库链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29764780/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com