c - 为什么我在编译时出现无法识别文件格式的错误?

标签 c libxml2

我正在使用 libxml2 解析器来解析 xml 文件。但是当我使用 gcc 编译器进行编译时:

gcc test.c note.xml -I/usr/include/libxml2 -lxml2 -o output

它给了我以下错误:

/usr/bin/ld:note.xml: file format not recognized; treating as linker script
/usr/bin/ld:note.xml:1: syntax error
collect2: error: ld returned 1 exit status

这是我的 test.c 文件:

#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>

void readfile(const char* filename) {
    xmlDocPtr doc;
    doc = xmlReadFile(filename,NULL,0);
    if(doc == NULL)
       return;
    xmlFreeDoc(doc);
}

int main(int argc,char* argv[]) {
    if(argc != 2)
        return 1;
    LIBXML_TEST_VERSION
    readfile(argv[1]);
    xmlCleanupParser();
    xmlMemoryDump();
    return 0; 
} 

这是我的 xml 文件:

<note>
  <to>Tove</to>
    <from>Jani</from>
      <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
   </note>

最佳答案

错误说明了一切:

/usr/bin/ld:note.xml: file format not recognized; treating as linker script

无法识别文件格式。哪个文件? note.xml。是代码吗?不,它不是 C 代码的一部分。它根本不应该被编译,所以不要将它作为参数传递给 gcc

关于c - 为什么我在编译时出现无法识别文件格式的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51274354/

相关文章:

c - 如何从函数内更改结构内部灵活数组的值?

gcc - Libxml2:对 xmlTextReaderConstName 的 undefined reference

在运行时检查 libxml2.so 的构建参数

c++ - 无法从 Eclipse 使用 libxml++

c - 如何修复由 realloc 越界引起的段错误?

linux - 编译器找不到 libxml/parser.h

c++ - 如何从采样率和单极点低通滤波器的alpha系数计算截止频率?

c/fortran函数内存分析工具

c - 如何用c语言实现gmail的Oauth2.0

c++ - Visual C++ 2012 可再发行版是否向后兼容 2010 版?