I wrote a small Python extension that bundles, compiles and statically links with a small C library with one optional .S (assembler) file. Distutils's Extension() doesn't recognize the .S by default. Is there a good way to compile that file, or should I just shell out to make
? Right now I compile the C code only for a slightly slower library.
I don't know how new it is, but the Extension
class has an extra_objects
argument, which I found can specify assembly files. So for example, my setup.py
looks something like this:
example_module = Extension('_example',
extra_compile_args = ['-Wall', '-g', '-std=c++11'],
sources=['something.cpp'],
extra_objects=['asm_amd64.s'])
I double checked, and if you inspect the generated library with nm -D example.so
, the assembly functions are properly assembled and linked if you include it in the extra_objects
, but they are not linked if you don't include it in that argument. So it seems to work.
As distributed, distutils don't know about assembly code, and I don't know of extensions to it that let it deal automatically with it. In a similar situation I've always built the library separately (with C and assembly as needed and feasible) and only used the resulting .a
with setup.py.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With