gpt4 book ai didi

c++ - 如何解析 "relocation truncated to fit: R_X86_64_PC32 against undefined symbol ` xmlStrcmp'”

转载 作者:行者123 更新时间:2023-11-30 02:27:29 31 4
gpt4 key购买 nike

我正在尝试在 C++ 中使用 libxml2 库,但出现一些我不知道如何解决的错误。我的代码是该库的一个基本示例。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

void
parseStory (xmlDocPtr doc, xmlNodePtr cur) {

xmlChar *key;
cur = cur->xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))) {
key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
printf("keyword: %s\n", key);
xmlFree(key);
}
cur = cur->next;
}
return;
}

static void
parseDoc(char *docname) {

xmlDocPtr doc;
xmlNodePtr cur;

doc = xmlParseFile(docname);

if (doc == NULL ) {
fprintf(stderr,"Document not parsed successfully. \n");
return;
}

cur = xmlDocGetRootElement(doc);

if (cur == NULL) {
fprintf(stderr,"empty document\n");
xmlFreeDoc(doc);
return;
}

if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
fprintf(stderr,"document of the wrong type, root node != story");
xmlFreeDoc(doc);
return;
}

cur = cur->xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){
parseStory (doc, cur);
}

cur = cur->next;
}

xmlFreeDoc(doc);
return;
}

int
main(int argc, char **argv) {

char *docname;

if (argc <= 1) {
printf("Usage: %s docname\n", argv[0]);
return(0);
}

docname = argv[1];
parseDoc (docname);

return (1);
}

我在构建项目时遇到了这些错误。

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:26: undefined reference to `xmlStrcmp'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:26:(.text+0x36): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `xmlStrcmp'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:27: undefined reference to `xmlNodeListGetString'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:27:(.text+0x59): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `xmlNodeListGetString'

build/Debug/Cygwin-Windows/main.o: In function parseDoc':
/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:42:
undefined reference to
xmlParseFile'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:42:(.text+0xad): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `xmlParseFile'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:49: undefined reference to `xmlDocGetRootElement'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:49:(.text+0xec): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `xmlDocGetRootElement'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:53: undefined reference to `xmlFreeDoc'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:53:(.text+0x126): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `xmlFreeDoc'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:57: undefined reference to `xmlStrcmp'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:57:(.text+0x142): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `xmlStrcmp'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:59: undefined reference to `xmlFreeDoc'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:59:(.text+0x17a): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `xmlFreeDoc'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:65: undefined reference to `xmlStrcmp'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:65:(.text+0x1a6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `xmlStrcmp'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:72: undefined reference to `xmlFreeDoc'

/cygdrive/c/Users/robin/Documents/NetBeansProjects/xml/main.cpp:72:(.text+0x1d9): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `xmlFreeDoc'

build/Debug/Cygwin-Windows/main.o:main.cpp:(.rdata$.refptr.xmlFree[.refptr.xmlFree]+0x0): undefined reference to `xmlFree'

我读过这篇文章 What does this GCC error "... relocation truncated to fit..." mean? ,但我不知道如何解决我的问题。我的 IDE 是在 Windows 10 64 位机器上使用 Cygwin64 的 Netbeans 8.2。我包括了 libxml2-2.9.3-win32-x86_64.7ziconv-1.14-win32-x86_64.7z。希望您能帮帮我,谢谢。

最佳答案

你是如何安装这个库的?

我几天前遇到了同样的问题 Curl ,经过数小时的谷歌搜索和挖掘网络的每个角落以找到解决方案(因为我还是个新手),我终于找到了。

适用于我的解决方案可能不适用于您,但仍然值得尝试一下,请按照以下步骤操作:

  • 尝试将您的库构建为静态库而不是包含它(Google 会帮助您,但它就像./configuremake 一样简单)<
  • 确保程序可以在不包含它的情况下使用该库(-v 标志可以提供帮助)
  • 添加编译器选项-llibname(例如-llibxml)。此选项 Search the library named libname when linking.
  • 尝试照常编译和运行程序。

祝你好运!

关于c++ - 如何解析 "relocation truncated to fit: R_X86_64_PC32 against undefined symbol ` xmlStrcmp'”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41721908/

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