免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3600 | 回复: 3
打印 上一主题 下一主题

包含libxml2库时编译出错,麻烦各位大神帮帮忙! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-02 16:17 |只看该作者 |倒序浏览
我的源程序是这样的
#include<libxml/parser.h>//使用libxml库
#include<libxml/tree.h>
int main(int argc, char** argv)
{
          xmlDocPtr doc = NULL;       /* document pointer */
          xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;/* node pointers */
    // Creates a new document, a node and set it as a root node
          doc = xmlNewDoc(BAD_CAST "1.0";
          root_node = xmlNewNode(NULL, BAD_CAST "root";
          xmlDocSetRootElement(doc, root_node);
          //creates a new node, which is "attached" as child node of root_node node.
          xmlNewChild(root_node, NULL, BAD_CAST "node1",BAD_CAST "content of node1";
          // xmlNewProp() creates attributes, which is "attached" to an node.
          node=xmlNewChild(root_node, NULL, BAD_CAST "node3", BAD_CAST"node has attributes";
          xmlNewProp(node, BAD_CAST "attribute", BAD_CAST "yes";
          //Here goes another way to create nodes.
          node = xmlNewNode(NULL, BAD_CAST "node4";
          node1 = xmlNewText(BAD_CAST"other way to create content";
          xmlAddChild(node, node1);
          xmlAddChild(root_node, node);
          //Dumping document to stdio or file
          xmlSaveFormatFileEnc(argc > 1 ? argv[1] : "-", doc, "UTF-8", 1);
          /*free the document */
          xmlFreeDoc(doc);
          xmlCleanupParser();
          xmlMemoryDump();//debug memory for regression tests
          return(0);
}


错误提示为:[root@cloud1 mycode]# gcc -o test main.c fileprocess.c
/tmp/ccCZCM5v.o: In function `xmlparse':
fileprocess.c.text+0x2b): undefined reference to `xmlNewDoc'
fileprocess.c.text+0x43): undefined reference to `xmlNewNode'
fileprocess.c.text+0x5: undefined reference to `xmlDocSetRootElement'
fileprocess.c.text+0x7d): undefined reference to `xmlNewChild'
fileprocess.c.text+0xa2): undefined reference to `xmlNewChild'
fileprocess.c.text+0xc2): undefined reference to `xmlNewProp'
fileprocess.c.text+0xd7): undefined reference to `xmlNewNode'
fileprocess.c.text+0xe7): undefined reference to `xmlNewText'
fileprocess.c.text+0xfc): undefined reference to `xmlAddChild'
fileprocess.c.text+0x10e): undefined reference to `xmlAddChild'
fileprocess.c:(.text+0x142): undefined reference to `xmlSaveFormatFileEnc'
fileprocess.c:(.text+0x14d): undefined reference to `xmlFreeDoc'
fileprocess.c:(.text+0x152): undefined reference to `xmlCleanupParser'
fileprocess.c:(.text+0x157): undefined reference to `xmlMemoryDump'

论坛徽章:
0
2 [报告]
发表于 2012-03-02 16:54 |只看该作者
库放在/usr/lib下面
然后
gcc -o xxx -lxxx xxx.c xxx.c
试试。

论坛徽章:
0
3 [报告]
发表于 2012-03-02 16:56 |只看该作者
库放在/usr/lib下面
然后
gcc -o xxx -lxxx xxx.c xxx.c
试试。

论坛徽章:
0
4 [报告]
发表于 2012-03-03 02:49 |只看该作者
undefined reference to 说明有些文件没链接进来...
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP