[완료]초보자입니다... gcc 로 xml 사용하는 C 파일 컴파일 어케 해요 ㅡ.ㅡ;;;

hongtting의 이미지

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)
----

khiny의 이미지

쉘##> gcc -o ttt ttt.c -ldir
저기서 dir을 헤더파일이 있는 디렉토리경로명으로 대치해주시면 됩니다.
복수의 경로명도 추가로 지정가능합니다.
gcc -o ttt ttt.c -ldir -ldir 이런식으로요.

혹시 필요하다면 필요라이브러리도 옵션으로 추가해야합니다.

더 자세한 건 gcc 옵션에 대해서 찾아보세요.

hongtting의 이미지

우선 글 남겨주셔서 감사합니다 꾸벅 )__(

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 ^^

hys545의 이미지

즐린
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/
이렇게 해야 합니다.

즐린

cwryu의 이미지

gcc `pkg-config --cflags libxml-2.0` -o ttc ttc.c `pkg-config --libs libxml-2.0`

----
익명이나 오래전 글에 리플은 무조건 -1

hongtting의 이미지

gcc `pkg-config --cflags libxml-2.0` -o ttc ttc.c `pkg-config --libs libxml-2.0`

이것으로 성공하였습니다. 감사합니다 꾸벅 ^^

hongtting ^^

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.