Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ccmorataya/sistemasoperativos

Static and dynamic libraries with C for the course of "Sistemas Operativos I"
https://github.com/ccmorataya/sistemasoperativos

Last synced: 15 days ago
JSON representation

Static and dynamic libraries with C for the course of "Sistemas Operativos I"

Awesome Lists containing this project

README

        

# Static and Shared libraries in Linux

## Static libraries:

Files used:

`libreria.c`

`libreria.h`

`consume.c`

How to compile:

```
$ gcc -c -o
$ ar rcs lib.a
```

Linking the static library:

`$ gcc -static consume.c -L. -llibreria`

## Dynamic (Shared) libraries:

How to compile:

```
$ gcc -c -fPIC libreria.c -o libreria.o
$ gcc -shared -o liblibreria.so libreria.o
```

Linking the dynamic library:

`$ gcc consume.c -o dynamically_linked -L. -llibreria`

At this point if we execute the binary with:

`$ ./dynamically_linked`

We receive the following error:

`$ ./dynamically_linked: error while loading shared libraries: liblibreria.so: cannot open shared object file: No such file or directory`

To solve that is necesary to add a variable to the path, the LD_LIBRARY_PATH with two simple comands:

```
$ LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
$ export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
```

And that's all to do, now simple execute the bin as follow:

`$ ./dynamically_linked`