Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 无法在mxml中使用mxmlGetText和mxmlGetElemet #包括 #包括 void main() { 文件*fp; mxml_节点_t*树; mxml_node_t*node=NULL; fp=fopen(“1.xml”,“r”); tree=mxmloadfile(NULL,fp,MXML\u不透明\u回调); 节点=树; fprintf(stderr,“元素::%s\n”,mxmlGetElement(节点)); fprintf(stderr,“值::%s\n”,mxmlgetext(节点,0)); }_C_Gcc_Mxml - Fatal编程技术网

C 无法在mxml中使用mxmlGetText和mxmlGetElemet #包括 #包括 void main() { 文件*fp; mxml_节点_t*树; mxml_node_t*node=NULL; fp=fopen(“1.xml”,“r”); tree=mxmloadfile(NULL,fp,MXML\u不透明\u回调); 节点=树; fprintf(stderr,“元素::%s\n”,mxmlGetElement(节点)); fprintf(stderr,“值::%s\n”,mxmlgetext(节点,0)); }

C 无法在mxml中使用mxmlGetText和mxmlGetElemet #包括 #包括 void main() { 文件*fp; mxml_节点_t*树; mxml_node_t*node=NULL; fp=fopen(“1.xml”,“r”); tree=mxmloadfile(NULL,fp,MXML\u不透明\u回调); 节点=树; fprintf(stderr,“元素::%s\n”,mxmlGetElement(节点)); fprintf(stderr,“值::%s\n”,mxmlgetext(节点,0)); },c,gcc,mxml,C,Gcc,Mxml,上面是我的代码片段。。。错误是 #include <mxml.h> #include <stdio.h> void main() { FILE *fp; mxml_node_t *tree; mxml_node_t *node = NULL; fp = fopen("1.xml", "r"); tree = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK); node =

上面是我的代码片段。。。错误是

#include <mxml.h>
#include <stdio.h>

void main()
{
    FILE *fp;

    mxml_node_t *tree;
    mxml_node_t *node  = NULL;

    fp = fopen("1.xml", "r");

    tree = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK);

    node = tree;

    fprintf(stderr, "Element::%s\n", mxmlGetElement(node));
    fprintf(stderr, "Value::%s\n", mxmlGetText(node, 0));
}
c:在函数“main”中: c:20:2:警告:格式“%s”要求参数类型为“char*”,但参数3的类型为“int”[-Wformat] c:21:2:警告:格式“%s”要求参数类型为“char*”,但参数3的类型为“int”[-Wformat] /tmp/ccaysob.o:在函数“main”中: xmlparsing.c:(.text+0x58):对“mxmlGetElement”的未定义引用 xmlparsing.c:(.text+0x8c):对“mxmlgetext”的未定义引用 collect2:ld返回了1个退出状态
已经包含了mxml.h,为什么没有定义引用?我在Internet上搜索了有关此功能的信息,链接显示它位于mxml.h头文件中。

您的问题在于链接器,请参阅最后一条消息:

xmlparsing.c: In function ‘main’: xmlparsing.c:20:2: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat] xmlparsing.c:21:2: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat] /tmp/ccAYsMOB.o: In function `main': xmlparsing.c:(.text+0x58): undefined reference to `mxmlGetElement' xmlparsing.c:(.text+0x8c): undefined reference to `mxmlGetText' collect2: ld returned 1 exit status 您需要将include路径和library路径通知
gcc
(这是对编译器和链接器的调用)。 包含路径是找到
mxml.h
的地方,这将通过以下方式完成:

collect2: ld returned 1 exit status
-I
库路径包含以下内容:

-I<path/to/include/mxml.h>
-L
因此,总的来说,您应该:

-L<path/to/shared/libmxml.a> 
gcc yourfile.c-I-L
您可以根据需要包括其他路径。

您是如何调用编译器的?您是否向链接器传递了库的路径?
gcc yourfile.c -I <path/to/include/mxml.h> -L <path/to/shared/libmxml.a>