Python flags: --cflags, --includes, --ldflags, --libs

Python flags: --cflags, --includes, --ldflags, --libs

如果將cpp檔案編譯成一個so檔,可以使用如下指令:

gcc $(python-config --cflags --ldflags) -shared -fPIC progr.cpp -o progr.so

其中的--cflags--ldflags是什麼呢?

參考python3-config (1) - Linux Manuals

--cflags
print the C compiler flags.
--ldflags
print the flags that should be passed to the linker.
--includes
similar to --cflags but only with -I options (path to python header files).
--libs
similar to --ldflags but only with -l options (used libraries).

--includes--cflags的子集,只包含-I的部份。

--libs--ldflags的子集,只包含-l的部份。

驗證如下:

python3-config --incldues展開來為:

-I/usr/include/python3.8 -I/usr/include/python3.8

python3-config --cflags展開來為:

-I/usr/include/python3.8 -I/usr/include/python3.8  -Wno-unused-result -Wsign-compare -g -fdebug-prefix-map=/build/python3.8-uvizni/python3.8-3.8.10=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector -Wformat -Werror=format-security  -DNDEBUG -g -fwrapv -O3 -Wall

包含了python3-config --incldues

python3-config --libs展開來為:

-lcrypt -lpthread -ldl  -lutil -lm -lm 

python3-config --ldflags展開來為:

-L/usr/lib/python3.8/config-3.8-x86_64-linux-gnu -L/usr/lib  -lcrypt -lpthread -ldl  -lutil -lm -lm

包含了python3-config --libs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值