0

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

8
  • Write a bash builtin that uses the library.
    – KamilCuk
    Commented Dec 8, 2020 at 10:26
  • @KamilCuk what do u mean by bash builtin? do u mean add object file to /usr/bin/ and and add library to where ever the libraries are installed
    – user786
    Commented Dec 8, 2020 at 11:19
  • drdobbs.com/shell-corner-bash-dynamically-loadable-b/… o this. Dynamically loadable bash builtin. You can then write a C source file to open that .o file and make syscalls. But I would just write it all as a builtin.
    – KamilCuk
    Commented Dec 8, 2020 at 11:23
  • @KamilCuk if I create bash builtin file then then what will be its extension and where will it go in which folder so I dont need to be in specific folder to run it?
    – user786
    Commented Dec 8, 2020 at 11:30
  • It's a shared library, as I understand it right now, bash calls dlopen on your_builtin.so when adding the builtin and then executes some function from the shared library. Here it is. You can even compile your .o into .so and enable it from bash as a builtin itself. Please explain what you exactly mean by "make the static library usable in terminal". "Usable" - in what way?
    – KamilCuk
    Commented Dec 8, 2020 at 11:35

1 Answer 1

1

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.
5
  • I like to go with bash builtin. can u add something about that in answer? especially how can I create bash builtin file and enabling it
    – user786
    Commented Dec 8, 2020 at 13:17
  • I don't know how to do bash builtin from personnal C library... sorry
    – DipStax
    Commented Dec 8, 2020 at 13:30
  • 1
    I have up voted u but I am also looking something about bash builtin especially how to add c file or object (.o) file to bash builtin using enable command and use it as bash builtin if someone include that in answer then thats what I am looking for
    – user786
    Commented Dec 8, 2020 at 13:36
  • I have accepted the answer since I am not getting any details on other thing I asked in comments
    – user786
    Commented Dec 9, 2020 at 8:01
  • ok, if you wan't some precision ask about it in a new question with every precision as you can.
    – DipStax
    Commented Dec 9, 2020 at 8:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.