Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linking with internal libraries. #339

Merged
merged 1 commit into from Sep 14, 2021

Conversation

orbea
Copy link
Contributor

@orbea orbea commented May 3, 2021

When building fflas-ffpack with slibtool (https://dev.midipix.org/cross/slibtool) it fails.

rdlibtool --tag=CXX --mode=link g++ -O2 -march=native -Wall -DNDEBUG -UDEBUG -I/tmp/delme/usr/local/include -L/tmp/delme/usr/local/lib -lgivaro -lgmpxx -lgmp -lcblas -lblas -version-info 1:0:0 -no-undefined -lfflas -lffpack -o libffpack_c.la -rpath /usr/local/lib ffpack.lo

rdlibtool: lconf: {.name="libtool"}.
rdlibtool: fdcwd: {.fdcwd=AT_FDCWD, .realpath="/tmp/fflas-ffpack/fflas-ffpack/interfaces/libs"}.
rdlibtool: lconf: fstatat(AT_FDCWD,".",...) = 0 {.st_dev = 45, .st_ino = 3171}.
rdlibtool: lconf: openat(AT_FDCWD,"libtool",O_RDONLY,0) = -1 [ENOENT].
rdlibtool: lconf: openat(AT_FDCWD,"../",O_DIRECTORY,0) = 3.
rdlibtool: lconf: fstat(3,...) = 0 {.st_dev = 45, .st_ino = 3168}.
rdlibtool: lconf: openat(3,"libtool",O_RDONLY,0) = -1 [ENOENT].
rdlibtool: lconf: openat(3,"../",O_DIRECTORY,0) = 4.
rdlibtool: lconf: fstat(4,...) = 0 {.st_dev = 45, .st_ino = 2962}.
rdlibtool: lconf: openat(4,"libtool",O_RDONLY,0) = -1 [ENOENT].
rdlibtool: lconf: openat(4,"../",O_DIRECTORY,0) = 3.
rdlibtool: lconf: fstat(3,...) = 0 {.st_dev = 45, .st_ino = 2819}.
rdlibtool: lconf: openat(3,"libtool",O_RDONLY,0) = 4.
rdlibtool: lconf: found "/tmp/fflas-ffpack/libtool".
rdlibtool: link: x86_64-pc-linux-gnu-ar crs .libs/libffpack_c.a .libs/ffpack.o
rdlibtool: link: g++ .libs/ffpack.o -O2 -march=native -Wall -DNDEBUG -UDEBUG -I/tmp/delme/usr/local/include -L/tmp/delme/usr/local/lib -lgivaro -lgmpxx -lgmp -lcblas -lblas -lfflas -lffpack -shared -fPIC -Wl,--no-undefined -Wl,-soname -Wl,libffpack_c.so.1 -o .libs/libffpack_c.so.1.0.0
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lfflas
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lffpack
collect2: error: ld returned 1 exit status
rdlibtool: exec error upon slbt_exec_link_create_library(), line 1598: (see child process error messages).
rdlibtool: < returned to > slbt_exec_link(), line 2055.
make[3]: *** [Makefile:578: libffpack_c.la] Error 2
make[3]: Leaving directory '/tmp/fflas-ffpack/fflas-ffpack/interfaces/libs'
make[2]: *** [Makefile:415: install-recursive] Error 1
make[2]: Leaving directory '/tmp/fflas-ffpack/fflas-ffpack/interfaces'
make[1]: *** [Makefile:476: install-recursive] Error 1
make[1]: Leaving directory '/tmp/fflas-ffpack/fflas-ffpack'
make: *** [Makefile:567: install-recursive] Error 1

This reveals several issues.

  • Internal libraries should never link with linker flags and should use the libtool archive (.la) files instead.
  • These should be added to LIBADD for libraries or LDADD for programs and never to LDFLAGS which is only for other linker flags.
  • The _DEPENDENCIES do not need to be set manually since the defaults will be correct if the LIBADD/LDADD variables are set correctly.
  • This issue is masked if fflas-ffpack is already installed where -lfflas and -lffpack are found installed on the system and not in the build directory.
  • There is overlinking of dependencies where the same dependencies are linked repeatedly.

Making these changes allows both slibtool and GNU libtool to build correctly, the latter is far more permissive and silently hides this issue.

See this downstream issue: https://bugs.gentoo.org/787746

Also as a side note, GNU libtool has a long standing issue where is silently ignores -no-undefined while slibtool does not have this issue. This is not a problem here, but it is something to keep in mind. :)

When building fflas-ffpack with slibtool it fails.

ld: cannot find -lfflas
ld: cannot find -lffpack

This reveals several issues.

* Internal libraries should never link with linker flags and
  should use the libtool archive (.la) files instead.
* These should be added to LIBADD for libraries or LDADD for
  programs and never to LDFLAGS which is only for other linker
  flags.
* The _DEPENDENCIES do not need to be set manually since the
  defaults will be correct if the LIBADD/LDADD variables are
  set correctly.
* This issue is masked if fflas-ffpack is already installed
  where -lfflas and -lffpack are found installed on the system
  and not in the build directory.
* There is overlinking of dependencies where the same
  dependencies are linked repeatedly.

Making these changes allows both slibtool and GNU libtool to
build correctly, the latter is far more permissive and silently
hides this issue.
@orlitzky
Copy link

I have yet to try them, but these changes look correct in spirit: https://www.gnu.org/software/automake/manual/automake.html#Libtool-Flags

@ClementPernet
Copy link
Member

Thanks for this report and fix, and for pointing us to the correct usage of LDADD and LIBADD.
Merging.

@ClementPernet ClementPernet merged commit f4d3d81 into linbox-team:master Sep 14, 2021
@orbea orbea deleted the libtool branch September 14, 2021 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants