Hello, I am trying to build a custom cling interpreter with libxml2 already loaded using the cling Interpreter source file attached below. I build my cling Interpreter using the command below:
If i try and run the attached script using the compile executable, it fails with the attached error.
input_line_4:1:10: fatal error: 'libxml/parser.h' file not found
#include <libxml/parser.h>
^~~~~~~~~~~~~~~~~
input_line_5:1:10: fatal error: 'libxml/tree.h' file not found
#include <libxml/tree.h>
****************** CLING ******************
* Type C++ code and press enter to run it *
* Type .q to exit *
*******************************************
[cling]$ .I /usr/include/libxml2
[cling]$ .L xml2
[clin]$ .x cling_bin/script.cxx
This is a test 6
Let us take a basic c++ application below which uses libxml2 library to read an xml file.
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <iostream>
/**
* example1Func:
* @filename: a filename or an URL
*
* Parse the resource and free the resulting tree
*/
static void
example1Func(const char *filename) {
xmlDocPtr doc; /* the resulting document tree */
doc = xmlReadFile(filename, NULL, 0);
if (doc == NULL) {
fprintf(stderr, "Failed to parse %s\n", filename);
return;
}
std::cout << "Xml has been read" << std::endl;
xmlFreeDoc(doc);
}
int main(int argc, char **argv) {
if (argc != 2)
return(1);
/*
* this initialize the library and check potential ABI mismatches
* between the version it was compiled for and the actual shared
* library used.
*/
LIBXML_TEST_VERSION
example1Func(argv[1]);
/*
* Cleanup function for the XML library.
*/
xmlCleanupParser();
/*
* this is to debug memory for regression tests
*/
xmlMemoryDump();
return(0);
}
In c++ i can compile this file with the libxml2 library and generate the executable using the following commands:
Executing this file with a test xml file runs with no error.
./xml.exe test.xml
Xml has been read
I am trying to do something similar to this with cling. I wanted to generate a cling Interpreter executable with some shared or external libraries embedded into it. This interprete when used to interprete c++ code, will know where to find the source files of those libraries and call appropriate functions.
I misread the original command. You compile the cling with gcc and you pass an include path to gcc. Now cling is a compiler that lives in your binary and you should pass the include path to it. That is why this works.
if you add #pragma cling add_include_path("/usr/include/libxml2") before you include the libxml headers it might work.
Probably it’d be more helpful if you describe the problem you are trying to solve first.