John P John P - 1 month ago 5x
Python Question

Why does python3-config list -ldl before the last lined library?


python2.7-config --libs
python3.5-config --libs
, etc. results in the following output:

-lpython<version> -lpthread -ldl -lutil -lm

Why isn't libdl the last linked library? I believe the order only matters when the preceding libraries reference the latter, but do neither libutil nor libm reference libdl, but libpthread does? I am unable to examine libpthread the way I normally might (readelf and/or nm) as it is apparently not in the right format.


Neither of the later libraries appear to reference libdl, so linking to libdl first is unnecessary. In fact, linking to libdl first appears to have no effect, nor does skipping it entirely.

#include "Python.h"
int main(int argc, const char **argv) {}


gcc -o main main.c `python3.5m-config --cflags` -lpython3.5m -lpthread -lutil -lm