You are not logged in.

#1 2024-05-15 02:06:51

luizSchmidt
Member
Registered: 2024-05-15
Posts: 5

[Solved]GCC and Clangd won't find my shared libraries

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_PATH

and

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 -lcolors

How 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

#2 2024-05-15 02:36:05

Scimmia
Fellow
Registered: 2012-09-01
Posts: 13,726

Re: [Solved]GCC and Clangd won't find my shared libraries

.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

#3 2024-05-15 11:35:17

luizSchmidt
Member
Registered: 2024-05-15
Posts: 5

Re: [Solved]GCC and Clangd won't find my shared libraries

Thanks for that. But if I wanted to write a shared library and make it available system-wide, how could I do that?

Offline

#4 2024-05-15 12:19:10

loqs
Member
Registered: 2014-03-06
Posts: 18,911

Re: [Solved]GCC and Clangd won't find my shared libraries

luizSchmidt wrote:

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

#5 2024-05-15 15:45:35

luizSchmidt
Member
Registered: 2024-05-15
Posts: 5

Re: [Solved]GCC and Clangd won't find my shared libraries

Thanks for the answer. I included the header in /usr/include and it worked just fine

Offline

Board footer

Powered by FluxBB