gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 9ff5f59: BuildProgram: all necessary linking f


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 9ff5f59: BuildProgram: all necessary linking flags now added
Date: Tue, 21 Sep 2021 12:26:37 -0400 (EDT)

branch: master
commit 9ff5f5993758625daeb40459c9ef95c9ad563c70
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    BuildProgram: all necessary linking flags now added
    
    Until now, when constructing the command to build custom programs,
    BuildProgram wouldn't include the commands to link with Gnuastro's
    dependencies. This was because all those dependencies were already written
    into Gnuastro's libtool file (the installed 'libgnuastro.la' file that
    BuildProgram uses). However, as part of bug #61192, we discovered that
    Debian (and thus all derivate OSs) apply patches to Libtool that disable
    this very useful behavior (to avoid complicating their packaging). As a
    result, building of custom programs with BuildProgram would fail due to
    linking errors when external libraries were necessary (for example 'sin' in
    the C math library: '-lm').
    
    With this commit, BuildProgram now includes all the necessary linking flags
    in the command it runs. When an un-modified Libtool is run, all the
    redundant library linking flags are automatically removed by Libtool. But
    when the modified Libtool is run, all those flags will be used and the
    program will be able to compile.
    
    This bug was reported by Raúl Infante-Sainz and fixed with this help.
    
    This fixes bug #61192.
---
 NEWS                      |  2 ++
 bin/buildprog/buildprog.c | 24 ++++++++++++++++++++++--
 configure.ac              |  2 ++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 738c3ee..5cc54c5 100644
--- a/NEWS
+++ b/NEWS
@@ -131,6 +131,8 @@ See the end of the file for license conditions.
               Vincenzo Testa and Zohreh Ghaffari.
   bug #61108: Plain text table metadata ignored when numeric data type was
               not understood, reported by Sepideh Eskandarlou.
+  bug #61192: BuildProgram custom program linking problems on Debian-based
+              OSs, reported by Raúl Infante-Sainz.
 
 
 
diff --git a/bin/buildprog/buildprog.c b/bin/buildprog/buildprog.c
index 1542121..1d822f5 100644
--- a/bin/buildprog/buildprog.c
+++ b/bin/buildprog/buildprog.c
@@ -68,6 +68,24 @@ buildprog_as_one_string(char *opt, gal_list_str_t *list)
 
 
 
+/* Create the build command and run it.
+
+   Necessity of CONFIG_GNUASTRO_LDADD: By default Libtool will look into
+   the 'dependency_libs' variable of a library's 'libXXXXX.la' file to find
+   the dependencies of that library and add them to the link
+   command. Through this feature if we simply give the '.la' file to
+   Libtool, it will automatically use the dependency libraries in the final
+   compile and link command, making it redundant to use the
+   'CONFIG_GNUASTRO_LDADD' macro discussed here (which has all the link
+   commands necessary to use all the features of Gnuastro's library for
+   this system and was created at configure time). However, on some OSs
+   (including Debian, and all derivative OSs like Ubuntu), this feature of
+   libtool (to parse the dependnecies of a library) is disabled with a
+   patch in the source of Libtool (that is not modifiable without root
+   permissions!). So it is necessary to add this macro here. On other OSs
+   that don't have a problem, Libtool will automatically remove duplicates
+   before executing the command, so for the user, it won't make any
+   difference.*/
 int
 buildprog(struct buildprogparams *p)
 {
@@ -112,7 +130,7 @@ buildprog(struct buildprogparams *p)
 
   /* Write the full Libtool command into a string (to run afterwards). */
   if( asprintf(&command, "%s -c \"%s %s %s%s --mode=link %s %s %s "
-               "%s %s %s %s %s %s %s -I%s %s -o %s\"",
+               "%s %s %s %s %s %s %s -I%s %s %s -o %s\"",
                GAL_CONFIG_GNULIBTOOL_SHELL,
                GAL_CONFIG_GNULIBTOOL_EXEC,
                p->cp.quiet ? "--quiet" : "",
@@ -130,13 +148,15 @@ buildprog(struct buildprogparams *p)
                linklib     ?linklib    : "",
                INCLUDEDIR,
                fullla,
+               CONFIG_GNUASTRO_LDADD, /* See comment on this macro above */
                p->cp.output)<0 )
     error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
 
   /* Compile (and link): */
   retval=system(command);
   if(retval!=EXIT_SUCCESS)
-    error(EXIT_FAILURE, 0, "failed to build, see libtool error above");
+    error(EXIT_FAILURE, 0, "failed to build (error code %d), "
+          "see above", retval);
   else if(p->onlybuild==0)
     {
       /* Free the initial command. */
diff --git a/configure.ac b/configure.ac
index 771bb48..c0d8728 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1018,6 +1018,8 @@ LIBS="$orig_LIBS"
 AC_SUBST(CONFIG_LDADD, [$LDADD])
 AC_SUBST(ENABLE_SHARED, [$enable_shared])
 AS_ECHO(["linking flags (LDADD) ... $LDADD"])
+AC_DEFINE_UNQUOTED([CONFIG_GNUASTRO_LDADD], ["$LDADD"],
+                   [Linking options for Gnuastro's library])
 
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]