python下面lib和libs,从Python中返回包含和运行时lib目录

Lets say I want to use gcc from the command line in order to compile a C extension of Python. I'd structure the call something like this:

gcc -o applesauce.pyd -I C:/Python35/include -L C:/Python35/libs -l python35 applesauce.c

I noticed that the -I, -L, and -l options are absolutely necessary, or else you will get an error that looks something like this. These commands tell gcc where to look for the headers (-I), where to look for the static libraries (-L), and which static library to actually use (python35, which actually translates to libpython35.a).

Now, this is obviously really easy to get the libs and include directories if its your machine, as they never change if you don't want them to. However, I was writing a program that calls gcc from the command line, that other people will be using. The line where this call occurs looks something like this:

from subprocess import call

import sys

filename = applesauce.c

include_directory = os.path.join(sys.exec_prefix, 'include')

libs_directory = os.path.join(sys.exec_prefix, 'libs')

call(['gcc', ..., '-I', include_direcory, '-L', libs_directory, ...])

However, others will have different platforms and different Python installation structures, so just joining the paths won't always work.

Instead, I need a solution from within Python that will reliably return the include and libs directories.

Edit:

I looked at the module distutils.ccompiler, and found many useful functions that would in part use distutils, but make it customizable for me to make my compiler entirely cross platform. The only thing is, I need to pass it the include and runtime libraries...

Edit 2:

I looked at distutils.sysconfig an I am able to reliably return the 'include' directory including all the header files. I still have no idea how to get the runtime library.

The distutils.ccompiler docs are here

The program that needs this functionality is named Cyther

解决方案

If you look at the source of build_ext.py from distutils in the method finalize_options you will find code for different platforms used to locate libs.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值