- Mastering Embedded Linux Programming
- Chris Simmonds
- 233字
- 2021-07-30 09:44:59
Looking at the components of the C library
The C library is not a single library file. It is composed of four main parts that together implement the POSIX functions API:
libc
: The main C library that contains the well-known POSIX functions such asprintf
,open
,close
,read
,write
, and so onlibm
: Maths functions such ascos
,exp
, andlog
libpthread
: All the POSIX thread functions with names beginning withpthread_
librt
: The real-time extensions to POSIX, including shared memory and asynchronous I/O
The first one, libc
, is always linked in but the others have to be explicitly linked with the -l
option. The parameter to -l
is the library name with lib
stripped off. So, for example, a program that calculates a sine function by calling sin()
would be linked with libm
using -lm
:
arm-cortex_a8-linux-gnueabihf-gcc myprog.c -o myprog -lm
You can verify which libraries have been linked in this or any other program by using the readelf
command:
$ arm-cortex_a8-linux-gnueabihf-readelf -a myprog | grep "Shared library" 0x00000001 (NEEDED) Shared library: [libm.so.6] 0x00000001 (NEEDED) Shared library: [libc.so.6]
Shared libraries need a run-time linker, which you can expose using:
$ arm-cortex_a8-linux-gnueabihf-readelf -a myprog | grep "program interpreter" [Requesting program interpreter: /lib/ld-linux-armhf.so.3]
This is so useful that I have a script file with these commands into a shell script:
#!/bin/sh ${CROSS_COMPILE}readelf -a $1 | grep "program interpreter" ${CROSS_COMPILE}readelf -a $1 | grep "Shared library"
推薦閱讀
- ServiceNow Application Development
- Python快樂(lè)編程:人工智能深度學(xué)習(xí)基礎(chǔ)
- Learning Spring 5.0
- Android Studio Essentials
- Vue.js前端開(kāi)發(fā)基礎(chǔ)與項(xiàng)目實(shí)戰(zhàn)
- Functional Programming in JavaScript
- 基于差分進(jìn)化的優(yōu)化方法及應(yīng)用
- 深度強(qiáng)化學(xué)習(xí)算法與實(shí)踐:基于PyTorch的實(shí)現(xiàn)
- SAS數(shù)據(jù)統(tǒng)計(jì)分析與編程實(shí)踐
- C語(yǔ)言程序設(shè)計(jì)
- 搞定J2EE:Struts+Spring+Hibernate整合詳解與典型案例
- Python一行流:像專家一樣寫(xiě)代碼
- Getting Started with Web Components
- Building Clouds with Windows Azure Pack
- RESTful Web API Design with Node.js(Second Edition)