including c librarys
i think i am being silly but i cannot figure out how to include a library i have downloaded to use.
i got the openssl librarys as i wish to use some bits from them but how do i include them in my c file to work when i compile it and to use the functions in them?
i see people reference bits from it as openssl/file.h but i am confused about how to implement it.
Lookup the "-l" option in the manpage of your compiler.
thank you for that. Where do i put the library i want to use in relation to my code? will that work as long as i have make'ed and installed the openssl library?
gcc -I/path/to/header/files prog.c -L/path/to/library -lnameOfLib
Where the actual library you want to link against is
If you have a #include of
Then the full path will be
thank you for your replies, they have helped me but I have found another problem.
i have changed to the mhash library and this has installed correctly. the library is found under
/usr/local/lib - this holds the libmash.a, .la, .so etc files
so when compiling i use
gcc -L/usr/local/lib -o "filename" ./filename.o -lmhash
it now compiles absolutely fine but when i run "filename" it displays the error:
/home/user/filename/Debug/filename: error while loading shared libraries: libmhash.so.2: cannot open shared object file: No such file or directory
the .so.2 file also exists in /usr/local/lib.
am I still doing something silly with this somewhere? it is happy with the references in the code, now it just won't access the library externally it seems.
If you do
what do you see?
ldconfig -p | grep "libmhash.so.2"
sorry, i meant libmhash.a near the start of my post, everything else was pasted from either a terminal or ide.
when i try that last command it shows nothing. looking at the man page of that command do i need to run that to include this library for my executing code to work?
Thank you for your help.
I did some investigation on ldconfig and this pointed me at /etc/ld.so.conf.d/libc.conf
this had the path in that contained the library i needed to use.
I then ran ldconfig -p under sudo and it output alot, i run the same with | grep mhash and it is suddenly showing.
When you install libraries is this a command that needs to be run manually to re-index any libraries you have installed?
Yes. (Package managers, like syn and rpm etc, will run this for you; but one way or another it needs to run.)
Originally Posted by Terrak