Reputation: 187
I am in the process of developing a Python extension to allow a script running on a Raspberry Pi to control a sensor. The sensor manufacturer provided my organization with the source code to their C API, and I am trying to create a set of bindings to make the sensor accessible in Python scrips.
The makefile that came with the API source created a set of object files that I then linked together into a library (libvl53l1.a) using the command:
ar -cvq libvl53l1.a *.o
I then added this library to the setup.py script o my extension by adding this flag:
extra_compile_args=["-l:libvl53l1.a"]
The code, library, and setup.py script are currently in the same directory for convenience. Installing the library into Python using the command (python3 setup.py build_ext --inplace) runs without errors, however, when I try to import my library in a Python interpreter, the import fails because of an undefined symbol "VL53L1_WaitDeviceBooted" in the extension's .so file. Listing the symbols in libvl54l1.a:
nm libvl53l1.a | grep "VL53L1_WaitDeviceBooted"
shows that the library does expose a symbol of this name. Therefore, I believe that the linker is failing to link the extension with this static library. Is there a step I am missing that is causing this? I have also tried removing the .a extension as recommended in the Python documentation, to no avail.
Thank you
Upvotes: 0
Views: 310
Reputation: 213526
extra_compile_args=["-l:libvl53l1.a"]
This setting adds -l:...
to the compilation command, but the compiler ignores that option, because it's a linking option, and no linking is done by the compiler.
You want: extra_link_args=["-lvl53l1"]
, which would add -lvl53l1
to the link command (the linker wouldn't ignore that option while performing the linking).
Upvotes: 1