• Viernes 29 de Marzo de 2024, 14:48

Autor Tema:  error con libxml2  (Leído 2643 veces)

ttenay

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
error con libxml2
« en: Miércoles 4 de Julio de 2012, 23:27 »
0
Hola nose porque a la hora de compilar un programa para leer un archivo xml me manda error, si ya instale, actualice libxml2-dev me sigue enviando error y ya he buscado informacion pero la mayoria dicen que hay que tener intalada la libreria y actualizada pero pues nada que sigue enviandome el siguiente error y esta es un codigo que encontre para  ver como funciona

#include <stdio.h>
#include <string.h>
#include <libxml/parser.h>
#include <ctype.h>

char *trim(char *s)
{
  char *start = s;

  /* Nos comemos los espacios al inicio */
  while(*start && isspace(*start))
    ++start;

  char *i = start;
  char *end = start;

  /* Nos comemos los espacios al final */
  while(*i)
  {
    if( !isspace(*(i++)) )
      end = i;
  }

  /* Escribimos el terminados */
  *end = 0;

  return start;
}

void print_nodes(xmlNode *first_child, int level)
{
  xmlNode *node;
  int l;
  xmlChar *value;
  xmlAttr *prop;

  for (node = first_child; node; node = node->next) {

    /* Si el nodo hijo es de texto y no tiene contenido... */
    if ( (node->type==3) && (strlen(trim((char*)xmlNodeGetContent(node)))==0) )
      continue;

    /* Escribimos tabs para dirigirnos al nivel deseado */
    for (l=0; l<level; l++)
      printf("\t");
   
    /* Averiguamos el valor del nodo */
    value=xmlNodeGetContent(node);
    printf("Child <%s> (t:%d) => \"%s\" ", node->name, node->type, trim((char*)value));

    /* Si tengo propiedades (atributos del nodo) las proceso */
    if (node->properties!=NULL)
      {
    printf (" props (");
    prop=node->properties;
    while (prop!=NULL)  /* Mientras haya una propiedad, la */
      {         /* voy a mostrar */
        value=xmlGetProp(node, prop->name);
        /* Si el valor no es NULL lo pongo en pantalla */
        if (value!=NULL)
          printf ("[%s]=\"%s\" ", prop->name, xmlGetProp(node, prop->name));
        /* Me dirijo a la siguiente propiedad */
        prop=prop->next;
      }
    printf(")");
      }
    printf ("\n");
    /* Si el nodo tiene sub-nodos, los proceso recursivamente */
    if (node->children!=NULL)
      print_nodes(node->children, level+1);
  }

}

int main(int argc, char **argv) {
   xmlDoc *document;
   xmlNode *root, *first_child;
   char *filename;

   if (argc < 2) {
     fprintf(stderr, "Usage: %s filename.xml\n", argv[0]);
     return 1;
   }
   filename = argv[1];

  document = xmlReadFile(filename, NULL, 0);
  root = xmlDocGetRootElement(document);
  fprintf(stdout, "Root is <%s> (%i)\n", root->name, root->type);
  first_child = root->children;
  print_nodes(first_child, 1);
  fprintf(stdout, "Fin\n");
  return 0;
}

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: se ingresa al directorio `/home/ser/NetBeansProjects/archivo2'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/archivo2
make[2]: se ingresa al directorio `/home/ser/NetBeansProjects/archivo2'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
gcc    -c -g -I/usr/include/libxml2 -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.c
mkdir -p dist/Debug/GNU-Linux-x86
gcc     -o dist/Debug/GNU-Linux-x86/archivo2 build/Debug/GNU-Linux-x86/main.o 
build/Debug/GNU-Linux-x86/main.o: In function `print_nodes':
/home/ser/NetBeansProjects/archivo2/main.c:41: undefined reference to `xmlNodeGetContent'
/home/ser/NetBeansProjects/archivo2/main.c:49: undefined reference to `xmlNodeGetContent'
/home/ser/NetBeansProjects/archivo2/main.c:59: undefined reference to `xmlGetProp'
/home/ser/NetBeansProjects/archivo2/main.c:62: undefined reference to `xmlGetProp'
build/Debug/GNU-Linux-x86/main.o: In function `main':
/home/ser/NetBeansProjects/archivo2/main.c:87: undefined reference to `xmlReadFile'
/home/ser/NetBeansProjects/archivo2/main.c:88: undefined reference to `xmlDocGetRootElement'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/archivo2] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: se sale del directorio `/home/ser/NetBeansProjects/archivo2'
make[1]: se sale del directorio `/home/ser/NetBeansProjects/archivo2'

BUILD FAILED (exit value 2, total time: 622ms)

aun compilando por linea de comando en linux
gcc -o main -I/usr/include/libxml2 -lxml2 main.c
me sigue enviando esos errores que hago que me falta auxilio no se que pasa
gracias

rfog

  • Miembro MUY activo
  • ***
  • Mensajes: 166
    • Ver Perfil
Re:error con libxml2
« Respuesta #1 en: Martes 7 de Agosto de 2012, 16:43 »
0
Lo primero es que este es un foro de Visual C++, no de GCC, así que la pregunta debería haber sido hecha en el padre.

Lo segundo es que el compilador desconoce de dónde vienen xmlNodeGetContent y demás, por lo que, de momento, al menos te falta incluir algunos ficheros .h más. ¿Cuáles, pues ni idea?
Microsoft Visual C++ MVP - Mi blog sobre programación: http://geeks.ms/blogs/rfog