9

I have a source file that I can run via the terminal using

gcc source.c -I/usr/include/libxml2 -lxml2 -o output

but when I #include the source file which includes the libxml source files, the compiler complains that the libxml/xmlmemory.h: , libxml/parser.h:, libxml/xpath.h cannot be found : no such file or directory.

3 Answers 3

6

You need always to keep the -I/usr/include/libxml2 in your gcc statement, so that it can find the header files.

Sign up to request clarification or add additional context in comments.

4 Comments

What if this file needs to compiled as part of a much larger system? Should I just copy the needed files into the directory where this source file kept?
Ahah. I hope you're not including the headers from your header files. That would suck. Make sure you depend on libxml2 only internally (in your compilation units, i.e. .c/.cxx/.cpp files)
I include in the .c files. but doesnt work. I dont have the libxml files in the same directory as the .c I am compiling
@Helium3, yes whatever c files that needs to use libxml will have to be compiled with the -I option.
5

You can also use xml2-config --cflags --libs to retrieve the compilation flags to add.

kjp@vbox:~/Dev/ScratchDir$ xml2-config --cflags --libs
-I/usr/include/libxml2
-lxml2
kjp@vbox:~/Dev/ScratchDir$

Comments

0

It seems like the source is referencing libxml, not libxml2 Can you verify that

/usr/include/libxml2/libxml/xmlmemory.h

is in fact accessible? (try to view it)

You don't compile the headers, the headers just have to be accessible as 'description' of the what the libraries implement

9 Comments

Is it possible the files cannot be found because they arent in the same folder as the code being compiled? I include like so #include <libxml/xpath.h> . i dont specify /usr/include/libxml2/libxml
It's what -I/usr/include/libxml2 is for
So how do I do this without calling I/usr/include/libxml2 -lxml2 when compiling?
Why would you do that? Make a compile script/makefile if you think it tedious. Using absolute paths is going to make your code unportable to other machines
The thing is that my code is part of a much larger system. Its an embedded project with multiple parts to the system. So it shouldnt have to be compiled with loads of command line arguments. So I should write a makefile?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.