libxml/parser.h: in c++ ubuntu - c++

Even though I have installed libxml++2.6-2 libxml++2.6-doc etc in my ubuntu 12.04 version again I am getting the below error
fatal error: libxml/parser.h: No such file or directory
I am using make for building the project
Kindly suggest any other libxml libraries which I need to install

libxml/parser.h is a part o libxml library, not libxml++
For any given library, you need development packages (the ones with names ending in -dev) in order to build applications using that library.
You need to pass additional flags to your compiler: xml2-config --cflags and to linker xml2-config --libs.

I don't have access to an Ubuntu system now, but: Maybe you need to install the libxml developer package? Maybe you only have the library but not the include file(s)?
Check in /usr/include, /usr/local/include, ... for the directory libxml and the file parser.h.
If you find the file, you may need to adapt your makefile so that the parent-directory is in the list of include paths, e.g.:
INC = -I/usr/local/include
g++ $(INC) ...
If you did not find the file: Check the available libxml packages for a developer package and install that.

Before Posting the answer THANKS to the people who have answered, but those answers were not worked for me
I have just copied libxml folder from the directory usr/lib/libxml2 and pasted in usr/lib directory and compiled my code it is not giving any error. It is working fine now.

Please read #el.pescado answer before reading this. I wanted to comment on that answer but felt the need to format my code better.
gcc -c <files to compile> `xml2-config --cflags` -o <object files>
gcc <object files> -L<libxml2 lib location> `xml2-config --libs` -o <binary file>
Assuming we have a file names xmltest.c that have code that included libxml2 header like #include <libxml/parser.h>, standard location of libxml2 shared library i.e. /usr/lib64/libxml2, the above code will evaluate like this:
gcc -c xmltest.c -I/usr/include/libxml2 -o xmltest.o
gcc xmltest.o -L/usr/lib64/libxml2 -lxml2 -lz -lm -o xmltest
A better idea is to put together a Makefile that does this automatically.

Related

Building Chilkat with a .sh file

I downloaded chilkat and I need to build it... I got 2 .sh files. The README says:
To build the C and C++ samples, first edit the c_sampleBuild.sh and
linkSample.sh scripts and set the "-L" option's path for the system libraries.
LinkSample.sh:
g++ -Wl,--enable-auto-import linkSample.cpp -o"linkSample.exe" -L. -libchilkat-9.5.0 -L/c/MinGW/lib -lcrypt32 -lws2_32 -ldnsapi
c_sampleBuild.sh:
#!/bin/bash -ev
gcc -c c_Sample.c -o"c_Sample.o"
g++ c_Sample.o -o"c_Sample.exe" -L. -lchilkat-9.5.0 -L/c/MinGW/lib -lcrypt32
-lws2_32 -ldnsapi
It's now clear how I should make that.... Help please :) Thanks
You haven't said what platform you are building on. But if you are using Windows + MinGW then:
The libraries for crypt32, ws2_32 and dnsapi can be downloaded from: here
For the g++ command, the -l (lowercase) option tells g++ which additional libraries you want to link against, and the -L (uppercase) option is used to tell g++ where to look for the libraries.
If you have a library file called libbar.a in the current folder (.) then you add the option (-L. -lbar)
Or, if you have a library in /path/to/foo/libbar.a then you add (-L/path/to/foo -lbar).
You will need to check the MinGW documentation for the locations of the system libraries, they are likely to be found in /lib or /usr/lib.

What steps does gcc(or g++) take in searching for the location of libaries?

When using the -l flag in a c++ makefile, I couldn't find information on what steps gcc takes in searching for that library.
For clarity of what I'm asking, I'll make up an example answer (this is completely made up):
First searches the -L flag directory
Next searches the /lib directory
Something something etc
Some extra info:
The reason I'm stuck in this is because I currently have a program that uses libconfig in the makefile like so:
g++ $(CFLAGS) -o libvldsk_config.so $(SRCDIR)/config.cpp -Wall -shared -fPIC -I$(SRCDIR) -I$(COMMON_SRCDIR) -lconfig
but this was made assuming that libconfig is installed via a package manager. I installed via source because the linux version was too old to have it in a package manager. And so I'm trying to modify my program that uses libconfig to search for the libconfig .so file in the system's /lib directory, and if it doesn't exist search for it in the current project directory.

How to use sqlite3.c and sqlite3.h in eclipse C/C++ project

I am trying to use amalgamated version of sqlite3.c and sqlite3.h in my C/C++ project. It has code in both C and C++. I am using eclipse IDE in UBUNTU 12.04.
Now my problem is that after having include sqlite3.h in my file where I need sqlite3.c functions and having added ld and pthread libraries in linker, i am still getting errors and cant build the project.
This is weird and should not happen. Please take a look at following screenshots that explain my problem.
************************************************************************************
************************************************************************************
What am I missing?
Please Help!
Thanks
Make sure that the pthread library is linked before the dl library.
In other words, your compiler command (as generated by Eclipse) should be:
gcc shell.c sqlite3.c -lpthread -ldl
and not
gcc shell.c sqlite3.c -ldl -lpthread
See here for a correct command line:
http://www.sqlite.org/howtocompile.html

Weird things with libCurl and OpenSSL

It's me again. I just can't understand, why it goes that way!
I downloaded compiled static libs of OpenSSL, from here, this link is on the official cUrl site in Download page. I downloaded Zlib and compiled them, then I compiled libcurl with
mingw32-make mingw32-ssl-zlib
I changed in all makefile.m32 pathes to the Zlib and OpenSSL files. All went fine, I recieved libcurl.a and libcurldll.a. I added into lib folder of my project libcurl.a and libeay32.a, libssleay32.a and libz.a.
I built project - it says that everything is fine. I run - and it just terminated. I'm using MinGW and Eclipse.
It is compiled with this:
g++ -DCURL_STATICLIB -O0 -g3 -Wall -c -fmessage-length=0 -osrc\main.o ..\src\main.cpp
g++ -L..\lib -oYTUploader.exe src\main.o -lcurl -lws2_32 -lwldap32 -leay32 -lssleay32 -lz
I run DependencyWalker, and it says that it's missing ieshims.dll, libeay32.dll and ssleay32.dll. But WHY? Why it want OpenSSL dll, I'm using static linking! I built static libCurl library, with static libs of OpenSSL. About ieshims.dll I also can't get why it needs it!
Help, please, I have no idea what is wrong! I compiled cUrl according to the instruction, everything should be fine..
The openssl-libs you link against seem to be import-libraries. That means they only contain the information your code needs to call functions and then load and call the corresponding functions from the dll.
So the problem is: although you link to static libs, the libs then load and use dynamic dlls. They are no "real" static libs.
One solution is getting other libs (or compile them yourself), or even easier: you just copy the dlls into the directory where your .exe resides and you should be fine.
Use the configure script to tell ld where openssl has installed the files. the defaults are as follows:
tar -zxf curl-7.33.0.tar.gz
cd curl-7.33.0
./configure --prefix=/opt/curlssl --with-ssl=/usr/local/ssl --enable-http --enable-ftp LDFLAGS=-L/usr/local/ssl/lib CPPFLAGS=-I/usr/local/ssl/include
make
make install

How to use OpenSSL with GCC?

I'm trying to use openssl in a gcc program but it isn't working.
g++ server.cpp /usr/lib/libssl.a -o server
gives an error message, as does anything with the -l option. What must I type on the command line to link with openssl? The file /usr/lib/libssl.a exists, but nevertheless I still get the linker error no such function MD5() exists.
Without knowing the exact errors you are seeing, it is difficult to provide an exact solution. Here is my best attempt.
From the information you provided, it sounds as though the linker is failing because it cannot find a reference to the md5 function in libssl.a. I believe this function is actually in libcrypto so you may need to specify this library as well.
g++ server.cpp -L/usr/lib -lssl -lcrypto -o server
You or others may find this article developerWorks article helpful.
Secure programming with the OpenSSL API
https://developer.ibm.com/technologies/linux/tutorials/l-openssl
It describes most things you need to know to get off the ground with OpenSSL and C/C++. If you find you are following most of the same steps, it might help you see what needs doing.
Good luck.
update
revised link: https://developer.ibm.com/technologies/linux/tutorials/l-openssl
Which has been shuffled around
original link: http://www.ibm.com/developerworks/linux/library/l-openssl.html
Which now goes to a digest page including the article.
Note: keeping both links because they be used to find new discoveries.
In Eclipse IDE select Your Project property --> c/c++ Build --> Settings gcc c linker(from tools settings)--> add to Library Search Path (-L)
/usr/lib -lssl -lcrypto
The location of the library is not fixed. In my case (Ubuntu 18.04), the .a files are located in /usr/lib/x86_64-linux-gnu/. So here are the complete steps:
1) install the library,
sudo apt install libss-dev
2) check the installed files,
dpkg-query -L libssl-dev
3) change the gcc flags -L(library directory) -l(library name), e.g.,
gcc XXX.c XXXXX.c -L/usr/lib/x86_64-linux-gnu/ -lcrypto -lssl
On top of the accepted answers, I could not make compile the OpenSSL example for AES-CCM:
https://github.com/openssl/openssl/blob/master/demos/evp/aesccm.c
To make it work I needed to add two more things:
The Dinamic Linking Library : -ldl
The PThread library to use POSIX threading support: -pthread (Adding directly the library with -lpthread is not recommended )