- 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"
推薦閱讀
- Spring Boot 2實(shí)戰(zhàn)之旅
- Learning NServiceBus(Second Edition)
- SQL Server 2012數(shù)據(jù)庫(kù)技術(shù)及應(yīng)用(微課版·第5版)
- Learning Flask Framework
- Oracle 12c中文版數(shù)據(jù)庫(kù)管理、應(yīng)用與開(kāi)發(fā)實(shí)踐教程 (清華電腦學(xué)堂)
- Java軟件開(kāi)發(fā)基礎(chǔ)
- Python數(shù)據(jù)挖掘與機(jī)器學(xué)習(xí)實(shí)戰(zhàn)
- Python編程與幾何圖形
- C++新經(jīng)典
- NetBeans IDE 8 Cookbook
- Terraform:多云、混合云環(huán)境下實(shí)現(xiàn)基礎(chǔ)設(shè)施即代碼(第2版)
- Mastering Unity 2D Game Development(Second Edition)
- C/C++數(shù)據(jù)結(jié)構(gòu)與算法速學(xué)速用大辭典
- Mastering Web Application Development with AngularJS
- Spring MVC+MyBatis開(kāi)發(fā)從入門(mén)到項(xiàng)目實(shí)踐(超值版)