diff --git a/setup.py b/setup.py index 3051035..526db00 100644 --- a/setup.py +++ b/setup.py @@ -20,9 +20,6 @@ def parse_library_names(libdir): # add system netcdf library library_names.extend(['netcdf']) - # move current library name to first - #current = [item for item in library_names if item.startswith('kintera')] - #other = [item for item in library_names if not item.startswith('kintera')] # 1) non-cuda libs first (consumers) kintera_non_cuda = [l for l in library_names if l.startswith("kintera") and "cuda" not in l] # 2) cuda libs last (providers) @@ -61,14 +58,26 @@ def parse_library_names(libdir): "-Wl,-rpath,@loader_path/../pyharp/lib", ] else: + # ubuntu system has an aggressive linker that removes unused shared libs + # add cuda library explicitly if built with cuda + cuda_linker = [] + cuda_libraries = [lib for lib in libraries if "cuda" in lib] + if cuda_libraries: + for lib in cuda_libraries: + libraries.remove(lib) + cuda_linker = ( + ["-Wl,--no-as-needed"] + + [f"-l{lib}" for lib in cuda_libraries] + + ["-Wl,--as-needed"] + ) + extra_link_args = [ - "-Wl,--no-as-needed", "-Wl,-rpath,$ORIGIN/lib", "-Wl,-rpath,$ORIGIN/../torch/lib", "-Wl,-rpath,$ORIGIN/../pydisort/lib", - "-Wl,-rpath,$ORIGIN/../pyharp/lib", - "-Wl,--as-needed", - ] + "-Wl,-rpath,$ORIGIN/../pyharp/lib" + ] + extra_link_args += cuda_linker ext_module = cpp_extension.CppExtension( name='kintera.kintera',