Prefer linking to dynamic rather than static libraries

Issue #23 resolved
Ben Woodcroft created an issue

Hi,

At GNU Guix, we package metabat using an up to date version of htslib (1.4.1) because (a) we wish to build software in a build environment isolated from the internet and (b) security updates, etc.

Unfortunately, linking with the static htslib.a fails because optional dependencies of htslib e.g. openssl are not included in the metabat scons. This patch prefers to link with dynamic libraries (where linking works in our environment) over static libraries.

Also, I suspect there might have been a (silent?) bug here before - I think the second for testfile.. should have been indented one more level.

Thanks.

diff --git a/SConstruct b/SConstruct
index 1150990..b3e2734 100755
--- a/SConstruct
+++ b/SConstruct
@@ -101,17 +101,17 @@ def findStaticOrShared( lib, testPaths, static_source_list, link_flag_list, stat
     for path in testPaths:
         if not os.path.isdir(path):
             continue
+        for testfile in ('%s/lib%s.so' % (path, lib), '%s/lib%s.dylib' % (path, lib)):
+            if os.path.isfile(testfile):
+                print "Found shared library %s as %s" % (lib, testfile)
+                link_flag_list.extend( ["-L%s" % (path), "-l%s" % (lib) ] )
+                return
         for suffix in staticSuffixes:
             testfile = '%s/lib%s%s' % (path, lib, suffix)
             if os.path.isfile(testfile):
                 static_source_list.append(testfile)
                 print "Found static library %s as %s" % (lib, testfile)
                 return
-    for testfile in ('%s/lib%s.so' % (path, lib), '%s/lib%s.dylib' % (path, lib)):
-            if os.path.isfile(testfile):
-                print "Found shared library %s as %s" % (lib, testfile)
-                link_flag_list.extend( ["-L%s" % (path), "-l%s" % (lib) ] )
-                return
     print "Could not find library for %s!!! Looked in %s" % (lib, testPaths)
     return

Comments (1)

  1. Log in to comment