Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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"
- Host: GitHub
- URL: https://github.com/ccmorataya/sistemasoperativos
- Owner: ccmorataya
- Created: 2016-09-05T16:50:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-05T22:41:12.000Z (over 8 years ago)
- Last Synced: 2024-11-07T03:38:00.972Z (2 months ago)
- Language: C
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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`