You are not logged in.
I wrote a library (call it 'colors.h' for the sake of this thread), compiled it as a shared library with the -c and -fPIC flags as usual, added it to
/usr/lib/and
/usr/local/lib/, exported both to
C_INCLUDE_PATHand
LD_LIBRARY_PATH,
sudo ldconfig'd and created a file in
/etc/lib.so.conf.d/ to include the .so file's path in the compiler search path.
And yet, none of that works. Clangd still accuses an error whenever I
#include <colors.h>or
#include "colors.h"if there is no "colors.h" file in the same directory, and GCC gives the following error:
test.c:1:10: fatal error: colors.h: No such file or directory
1 | #include <colors.h>
| ^~~~~~~~~~
compilation terminated.For documentation, I compiled the program with the following line:
gcc test.c -o test -lcolorsHow can I install the shared library in GCC's search path so that I can
#include <colors.h>from anywhere in my system?
Last edited by luizSchmidt (2024-05-15 15:46:33)
Offline
.h isn't a shared library, it's a header. It goes in the include path, ie /usr/include/, or you add the path to the include path with -I
Offline
Thanks for that. But if I wanted to write a shared library and make it available system-wide, how could I do that?
Offline
Thanks for that. But if I wanted to write a shared library and make it available system-wide, how could I do that?
/usr/lib or /usr/local/lib that you have already mentioned are standard locations for libraries with the headers going in /usr/include/ or /usr/local/include/.
Offline
Thanks for the answer. I included the header in /usr/include and it worked just fine
Offline