[완료]초보자입니다... gcc 로 xml 사용하는 C 파일 컴파일 어케 해요 ㅡ.ㅡ;;;
libxml2 설치된 경로는
usr/include/libxml2/libxml/ 이쪽에 설치되어 있는 상태입니다.
---- 파일명 ttt.c --------
#include
#include
#include
#include
#include
xmlDocPtr
parseDoc(char *docname, char *uri) {
xmlDocPtr doc;
xmlNodePtr cur;
xmlNodePtr newnode;
xmlAttrPtr newattr;
doc = xmlParseFile(docname);
if (doc == NULL ) {
fprintf(stderr,"Document not parsed successfully. \n");
return (NULL);
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
fprintf(stderr,"empty document\n");
xmlFreeDoc(doc);
return (NULL);
}
if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
fprintf(stderr,"document of the wrong type, root node != story");
xmlFreeDoc(doc);
return (NULL);
}
newnode = xmlNewTextChild (cur, NULL, "reference", NULL);
newattr = xmlNewProp (newnode, "uri", uri);
return(doc);
}
int
main(int argc, char **argv) {
char *docname;
char *uri;
xmlDocPtr doc;
if (argc <= 2) {
printf("Usage: %s docname, uri\n", argv[0]);
return(0);
}
docname = argv[1];
uri = argv[2];
doc = parseDoc (docname, uri);
if (doc != NULL) {
xmlSaveFormatFile (docname, doc, 1);
xmlFreeDoc(doc);
}
return (1);
}
----------
쉘##> gcc -o ttt ttt.c
test.c:4:30: error: libxml/xmlmemory.h: No such file or directory
test.c:5:27: error: libxml/parser.h: No such file or directory
test.c:8: error: syntax error before ?arseDoc?
test.c: In function ?arseDoc?
test.c:9: error: ?mlDocPtr?undeclared (first use in this function)
test.c:9: error: (Each undeclared identifier is reported only once
test.c:9: error: for each function it appears in.)
test.c:9: error: syntax error before ?oc?
test.c:10: error: ?mlNodePtr?undeclared (first use in this function)
test.c:12: error: ?mlAttrPtr?undeclared (first use in this function)
test.c:13: error: ?oc?undeclared (first use in this function)
test.c:16: warning: return makes integer from pointer without a cast
test.c:18: error: ?ur?undeclared (first use in this function)
test.c:22: warning: return makes integer from pointer without a cast
test.c:24: error: syntax error before ?mlChar?
test.c:27: warning: return makes integer from pointer without a cast
test.c: At top level:
test.c:29: error: ?ur?undeclared here (not in a function)
test.c:29: error: initializer element is not constant
test.c:29: warning: data definition has no type or storage class
test.c:30: error: ?ri?undeclared here (not in a function)
test.c:30: error: initializer element is not constant
test.c:30: warning: data definition has no type or storage class
test.c:31: error: syntax error before ?eturn?
test.c: In function ?ain?
test.c:37: error: ?mlDocPtr?undeclared (first use in this function)
test.c:37: error: syntax error before ?oc?
test.c:44: error: ?oc?undeclared (first use in this function)
----
옵션으로 헤더파일이 있는 곳을 지정해주면 됩니다.
쉘##> gcc -o ttt ttt.c -ldir
저기서 dir을 헤더파일이 있는 디렉토리경로명으로 대치해주시면 됩니다.
복수의 경로명도 추가로 지정가능합니다.
gcc -o ttt ttt.c -ldir -ldir 이런식으로요.
혹시 필요하다면 필요라이브러리도 옵션으로 추가해야합니다.
더 자세한 건 gcc 옵션에 대해서 찾아보세요.
헤더 파일들이 있는 경로로 지정했습니다만...
우선 글 남겨주셔서 감사합니다 꾸벅 )__(
gcc -o ttt ttt.c -l/usr/include/libxml2/libxml/
이렇게 했습니다.. 혹시나 해서
#include "xmlmemory.h" 해도 해보고
#include
했는대 결과는 마찬가지로
test.c:4:30: error: libxml/xmlmemory.h: No such file or directory
test.c:5:27: error: libxml/parser.h: No such file or directory
test.c:8: error: syntax error before ?arseDoc?
test.c: In function ?arseDoc?
test.c:9: error: ?mlDocPtr?undeclared (first use in this function)
test.c:9: error: (Each undeclared identifier is reported only once
test.c:9: error: for each function it appears in.)
test.c:9: error: syntax error before ?oc?
test.c:10: error: ?mlNodePtr?undeclared (first use in this function)
test.c:12: error: ?mlAttrPtr?undeclared (first use in this function)
.....
나와요 아구 아구
hongtting ^^
gcc -o ttt ttt.c -l/usr/include/libxml2/libxml/
즐린
gcc -o ttt ttt.c -l/usr/include/libxml2/libxml/
이 상태에서
#include < libxml / xmlmemory.h >
이걸 찾으면
gcc는 /usr/include/libxml2/libxml/libxml/ xmlmemory.h릋 찾습니다.
"xmlmemory.h"는 같은 디렉토리에서 찾고
제대로 하려면
gcc -o ttt ttt.c -l/usr/include/libxml2/
이렇게 해야 합니다.
즐린
gcc `pkg-config --cflags
gcc `pkg-config --cflags libxml-2.0` -o ttc ttc.c `pkg-config --libs libxml-2.0`
----
익명이나 오래전 글에 리플은 무조건 -1
말씀 감사합니다.
gcc `pkg-config --cflags libxml-2.0` -o ttc ttc.c `pkg-config --libs libxml-2.0`
이것으로 성공하였습니다. 감사합니다 꾸벅 ^^
hongtting ^^
댓글 달기