Search code examples
cstatic-librariesstatic-linking

Can I save a C static library anywhere I want?


I have created a library in C and want to link it when compiled. Do I have to save in a certain folder in my computer's file system or can I create my own file structure within my application to save it?

Update: My error turned out to be not properly including a header file. My files and linker were fine but it was simple syntax error.


Solution

  • You can save it wherever you want. Just make sure that the compiler knows the location. In the case of gcc for example, you can use:

    gcc -L path/to/libdir -l:mylib.a ...
    

    (assuming mylib.a is in path/to/libdir)

    Or even:

    gcc path/to/libdir/mylib.a ...