为什么我在编译时收到无法识别的错误文件格式?
Why am I getting error file format not reognized while compiling?
我正在使用 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
.
我正在使用 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
.