Search code examples
clinuxterminalstatic-librariesunix-ar

Converting .o file into static library in linux and make it usable in terminal


I want to create a simple library and after compilation and ar command I can get resulting .a file.

Now I want to add this file as a static library and use it in terminal, I dont know if its possible. but idea is from other library named Ctypes.sh on github. that library can be used to make syscalls from terminal or bash terminal.

I like to know how I can add my mylib.a as static libary and make it usable from terminal.

the library is simple I just want to invoke a few syscalls in linux from terminal.

I also looked into the code of ctypes.sh so my library is also be used to make some syscalls.

the reference I used above is here https://github.com/taviso/ctypes.sh/wiki


Solution

  • Every command that you run on linux are binary file that you execute. When you run a command like:

    ls -a
    

    it's like running:

    ./ls -a
    

    Where the ./ls is the binary and -a a parameter.

    All the binary used in a terminale is stocked in the bin (included in the default PATH). When you run a command your terminal will check in first, in the folder to find the binary and after, he gonna check every folder in the PATH environement variable. If you wan't to add a specific folder to the PATH to use a personnal folder for different baniry (check this link).

    In your probleme you have a library with different function (I suppose) that you wan't to use in a terminale. Have 2 solution:

    • Split your library in multiple micro programme, that you can execute in the terminale,
    • Create a programme whit param to run different function.