0

A python module build command

$ python setup.py build

shows the linker is "clang" as below but I want to change it to "ld." Using clang++ command for linking does not work on my Mac and changing it to "ld" works. I don't know how to change the link command in setup.py to use "ld". Could you let me know how to change the link command?

os.environ["CC"] = "clang"   # need this setting to use clang instead of gcc
os.environ["CXX"] = "clang"  # need this setting to use clang instead of gcc
...
...
clang++ -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.9-x86_64-3.8/Volumes/SSD256/Projects/MONAI.yoshi/monai/csrc/ext.o build/temp.macosx-10.9-x86_64-3.8/Volumes/SSD256/Projects/MONAI.yoshi/monai/csrc/GeodisTK/geodesic_distance.o build/temp.macosx-10.9-x86_64-3.8/Volumes/SSD256/Projects/MONAI.yoshi/monai/csrc/GeodisTK/geodesic_distance_2d.o build/temp.macosx-10.9-x86_64-3.8/Volumes/SSD256/Projects/MONAI.yoshi/monai/csrc/GeodisTK/geodesic_distance_3d.o build/temp.macosx-10.9-x86_64-3.8/Volumes/SSD256/Projects/MONAI.yoshi/monai/csrc/GeodisTK/geodesic_distance_interface.o build/temp.macosx-10.9-x86_64-3.8/Volumes/SSD256/Projects/MONAI.yoshi/monai/csrc/GeodisTK/util.o build/temp.macosx-10.9-x86_64-3.8/Volumes/SSD256/Projects/MONAI.yoshi/monai/csrc/filtering/bilateral/bilateralfilter_cpu.o build/temp.macosx-10.9-x86_64-3.8/Volumes/SSD256/Projects/MONAI.yoshi/monai/csrc/filtering/bilateral/bilateralfilter_cpu_phl.o build/temp.macosx-10.9-x86_64-3.8/Volumes/SSD256/Projects/MONAI.yoshi/monai/csrc/filtering/permutohedral/permutohedral.o build/temp.macosx-10.9-x86_64-3.8/Volumes/SSD256/Projects/MONAI.yoshi/monai/csrc/filtering/permutohedral/permutohedral_cpu.o build/temp.macosx-10.9-x86_64-3.8/Volumes/SSD256/Projects/MONAI.yoshi/monai/csrc/lltm/lltm_cpu.o build/temp.macosx-10.9-x86_64-3.8/Volumes/SSD256/Projects/MONAI.yoshi/monai/csrc/resample/pushpull_cpu.o -L/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torch/lib -lc10 -ltorch -ltorch_cpu -ltorch_python -o build/lib.macosx-10.9-x86_64-3.8/monai/_C.so
yoshi
  • 1,070
  • 9
  • 16

1 Answers1

2

You can use the LDSHARED environment variable to set the linker command:

LDSHARED=/usr/bin/ld python setup.py build_ext

I suggest you read the source code of the distutils package to see how it works.

jubnzv
  • 1,526
  • 2
  • 8
  • 20
  • Thank you. I tried but I couldn't get it work. But I will be able one day. Your pointing the distutils code is helpful. This problem didn't occur when I built it on Ubuntu server. This was a problem with MacOSX (Catalina). – yoshi Mar 12 '21 at 06:14