KEMBAR78
util-linux: fix build, add LDFLAGS="-lm" on Linux by jacktose · Pull Request #214529 · Homebrew/homebrew-core · GitHub
Skip to content

Conversation

@jacktose
Copy link
Contributor

This fixes (on my machine) the build failure I reported in discussion #5421. It wasn't linking libm and now it does, with LDFLAGS="-LM", as suggested by @eviatarbach.

It built on the weird CentOS 7 machine where I encountered the error, and it built and tested fine on my normal WSL Ubuntu instance.

I previously tried this in #204576 and it didn't get any attention. I still believe it's needed.


  • Have you followed the guidelines for contributing?
  • Have you ensured that your commits follow the commit style guide?
  • Have you checked that there aren't other open pull requests for the same formula update/change?
  • Have you built your formula locally with HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>, where <formula> is the name of the formula you're submitting?
  • Is your test running fine brew test <formula>, where <formula> is the name of the formula you're submitting?
  • Does your build pass brew audit --strict <formula> (after doing HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>)? If this is a new formula, does it pass brew audit --new <formula>?

Install & test results
$ brew tests
Randomized with seed 11893
20 processes for 399 specs, ~ 19 specs per process
...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................*................................................................................................................................................................................................................................................................................................................................................................
.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
................................................................................................................................................................................................................................................................................................................................................................................................................................
................................................................................................................................................................................................................................................................................................................
..............
.......................
...............................................................
.........................

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) UnpackStrategy::Zip when unzip is available #extract
     # Unzip is not installed.
     # ./test/unpack_strategy/shared_examples.rb:12

...................................................................................................................................................................
........................................................................
................................................................*.*........................................................................
..........................................
..........................

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) UnpackStrategy::Jar is correctly detected
     # Unzip is not installed.
     # ./test/unpack_strategy/shared_examples.rb:6

  2) UnpackStrategy::Jar #extract
     # Unzip is not installed.
     # ./test/unpack_strategy/shared_examples.rb:12

.................
..................................................................................................................
..
....
.......................
..................................................................................................
............................................................................



Took 18 seconds


$ brew uninstall --force util-linux

$ HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source util-linux
==> Auto-updating Homebrew...
Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Fetching util-linux
==> Downloading https://github.com/util-linux/util-linux/commit/9445f477cfcfb3615ffde8f93b1b98c809ee4eca.patch?full_index=1
########################################################################################################################################################################################################## 100.0%
==> Downloading https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.40/util-linux-2.40.4.tar.xz
########################################################################################################################################################################################################## 100.0%
==> Patching
==> Applying 9445f477cfcfb3615ffde8f93b1b98c809ee4eca.patch
==> ./configure --disable-silent-rules --disable-asciidoc --with-bashcompletiondir=/home/linuxbrew/.linuxbrew/Cellar/util-linux/2.40.4/etc/bash_completion.d --disable-use-tty-group --disable-kill --without-sys
==> make install
==> Caveats
Bash completion has been installed to:
  /home/linuxbrew/.linuxbrew/etc/bash_completion.d
==> Summary
🍺  /home/linuxbrew/.linuxbrew/Cellar/util-linux/2.40.4: 443 files, 25.2MB, built in 25 seconds
==> Running `brew cleanup util-linux`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /home/jacktose/.cache/Homebrew/util-linux--patch--7a7fe4d32806e59f90ca0eb33a9b4eb306e59c9c148493cd6a57f0dea3eafc64.patch... (1.2KB)
==> Installation times
util-linux               25.014 s

$ brew test util-linux
==> Testing util-linux
==> /home/linuxbrew/.linuxbrew/Cellar/util-linux/2.40.4/bin/namei -lx /usr

$ brew audit --strict util-linux

$ brew style util-linux

1 file inspected, no offenses detected

@jacktose
Copy link
Contributor Author

jacktose commented Apr 2, 2025

Bump. Review anyone? This has been here 2 weeks and my last attempt never got reviewed.

@Bo98
Copy link
Member

Bo98 commented Apr 2, 2025

The discussion linked has someone needing to add it to multiple formulae, so seems clear this is a toolchain problem instead and not a util-linux one. I wonder if we can slim this down - does a gcc $(pkg-config --libs sqlite3) fail similarly?

@jacktose
Copy link
Contributor Author

jacktose commented Apr 3, 2025

Thanks for looking. I'm out of my depth here, but happy to experiment if you can help.

$ pkg-config --libs sqlite
Package sqlite was not found in the pkg-config search path.
Perhaps you should add the directory containing `sqlite.pc'
to the PKG_CONFIG_PATH environment variable
Package 'sqlite' not found

$ echo "$PKG_CONFIG_PATH"


$ brew --prefix pkg-config
/data/shared/lusers/jacktose/homebrew/opt/pkgconf

$ brew --prefix sqlite
/data/shared/lusers/jacktose/homebrew/opt/sqlite

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale No recent activity label Apr 24, 2025
@Bo98
Copy link
Member

Bo98 commented Apr 24, 2025

Sorry forgot about this. I'm finishing a glibc update this weekend so will take a look at this with that.

@Bo98 Bo98 removed the stale No recent activity label Apr 24, 2025
@jacktose
Copy link
Contributor Author

Thanks, Bo98. It won't get stale this time!

So, I misread your question last time (forgot the 3). pkg-config works fine with sqlite3:

$ which pkg-config
~/homebrew/bin/pkg-config

$ pkg-config --libs sqlite3
-L/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib -lsqlite3

homebrew's gcc fails like so:

$ ~/homebrew/bin/gcc-14 --version
gcc-14 (Homebrew GCC 14.2.0_1) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ ~/homebrew/bin/gcc-14 $(pkg-config --libs sqlite3)
/usr/bin/ld: /data/shared/lusers/jacktose/homebrew/Cellar/gcc/14.2.0_1/bin/../libexec/gcc/x86_64-pc-linux-gnu/14/liblto_plugin.so: error loading plugin: /usr/lib64/libc.so.6: version `GLIBC_2.33' not found (required by /data/shared/lusers/jacktose/homebrew/Cellar/gcc/14.2.0_1/bin/../libexec/gcc/x86_64-pc-linux-gnu/14/liblto_plugin.so)
collect2: error: ld returned 1 exit status

homebrew's gcc is not linked, and system gcc fails differently:

$ which gcc
/usr/bin/gcc

$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc $(pkg-config --libs sqlite3)
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `pthread_join@GLIBC_2.34'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `dlsym@GLIBC_2.34'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `pthread_mutex_trylock@GLIBC_2.34'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `dlclose@GLIBC_2.34'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `lstat64@GLIBC_2.33'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `fcntl64@GLIBC_2.28'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `exp@GLIBC_2.29'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `log@GLIBC_2.29'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `pthread_mutexattr_destroy@GLIBC_2.34'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `pthread_mutexattr_settype@GLIBC_2.34'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `log2@GLIBC_2.29'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `dlerror@GLIBC_2.34'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `pow@GLIBC_2.29'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `fstat64@GLIBC_2.33'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `pthread_mutexattr_init@GLIBC_2.34'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `pthread_create@GLIBC_2.34'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `stat64@GLIBC_2.33'
/data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `dlopen@GLIBC_2.34'
collect2: error: ld returned 1 exit status

Again, I don't know what that means, but I'm happy to mess with it.

@p-linnane p-linnane added the in progress Stale bot should stay away label Apr 24, 2025
@jacktose
Copy link
Contributor Author

Anything else I can do to help with this?

@Bo98
Copy link
Member

Bo98 commented May 22, 2025

Haven't quite gotten round to looking at glibc yet since patchelf fixes took longer than expected but does Homebrew GCC work if you can get it to use Homebrew binutils too rather than /usr/bin/ld?

@jacktose
Copy link
Contributor Author

I think -B is the way to do that?

NB: Homebrew GCC has updated since the last test:

$ ~/homebrew/bin/gcc-15 --version
gcc-15 (Homebrew GCC 15.1.0) 15.1.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Baseline: same failure as before:

$ ~/homebrew/bin/gcc-15 $(pkg-config --libs sqlite3)
/usr/bin/ld: /data/shared/lusers/jacktose/homebrew/Cellar/gcc/15.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/15/liblto_plugin.so: error loading plugin: /usr/lib64/libc.so.6: version `GLIBC_2.33' not found (required by /data/shared/lusers/jacktose/homebrew/Cellar/gcc/15.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/15/liblto_plugin.so)
collect2: error: ld returned 1 exit status

With brewed ld (I think):

$ ~/homebrew/bin/gcc-15 -B/usr/lusers/jacktose/homebrew/opt/binutils/bin $(pkg-config --libs sqlite3)
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: warning: libm.so.6, needed by /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so, not found (try using -rpath or -rpath-link)
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/Cellar/gcc/15.1.0/bin/../lib/gcc/current/gcc/x86_64-pc-linux-gnu/15/Scrt1.o: in function `_start':
/tmp/glibc-20231218-29651-42ziqa/glibc-2.35/csu/../sysdeps/x86_64/start.S:103:(.text+0x17): undefined reference to `main'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `sinh@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `atan@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `exp@GLIBC_2.29'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `tan@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `log@GLIBC_2.29'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `sqrt@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `cosh@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `acosh@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `fmod@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `log10@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `atanh@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `log2@GLIBC_2.29'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `sin@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `cos@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `atan2@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `acos@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `tanh@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `pow@GLIBC_2.29'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `asinh@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `asin@GLIBC_2.2.5'
/usr/lusers/jacktose/homebrew/opt/binutils/bin/ld: /data/shared/lusers/jacktose/homebrew/opt/sqlite/lib/libsqlite3.so: undefined reference to `trunc@GLIBC_2.2.5'
collect2: error: ld returned 1 exit status

@jacktose
Copy link
Contributor Author

I got it to upgrade by manually adding LDFLAGS="-lm" again. I'd be grateful to see this merged, or for attention to a toolchain/upstream/general fix.

I'm clueless with build chains and compiler flags, but happy to try stuff. Here's a gist of my most recent failure, pursuant to some interesting thoughts from @cho-m.


system "./configure", *args, *std_configure_args
system "make", "install"
system "make", "install", "LDFLAGS=\"-lm\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
system "make", "install", "LDFLAGS=\"-lm\""
ENV.append "LDFLAGS", "-lm" if OS.linux?
system "make", "install"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed. GH's suggested commit message didn't match HB style. Tried to fix it but failed check didn't clear. Hope I didn't mess it up too badly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dang, I should have tested! –famous last words

It turns out that command line arg variables can override the Makefile, but environment variables can't. I learned a lot and wrote it all up in the discussion. I'd appreciate your input.

jacktose added a commit to jacktose-forks/homebrew-core that referenced this pull request Aug 24, 2025
set LDFLAGS conditionally on Linux
Homebrew#214529 (comment)

Co-authored-by: Carlo Cabrera <github@carlo.cab>
@github-actions github-actions bot added the autosquash Automatically squash pull request commits according to Homebrew style. label Aug 24, 2025
jacktose added a commit to jacktose-forks/homebrew-core that referenced this pull request Aug 24, 2025
Homebrew#214529 (comment)

Co-authored-by: Carlo Cabrera <github@carlo.cab>
@carlocab carlocab added CI-no-bottles Merge without publishing bottles CI-skip-dependents Pass --skip-dependents to brew test-bot. labels Aug 25, 2025
@carlocab
Copy link
Member

I can't push to your fork; can you squash your commits together so we can merge this?

@github-actions github-actions bot removed the autosquash Automatically squash pull request commits according to Homebrew style. label Aug 26, 2025
@jacktose
Copy link
Contributor Author

I can't push to your fork

Sorry. It's because I organize my forks under an org: isaacs/github#1681,
https://github.com/orgs/community/discussions/5634

Anyway, squashed.

@jacktose jacktose changed the title util-linux: fix build failure, add LDFLAGS="-lm" util-linux: fix build, add LDFLAGS="-lm" on Linux Aug 26, 2025
@carlocab carlocab added this pull request to the merge queue Aug 26, 2025
Merged via the queue into Homebrew:main with commit fbb36e3 Aug 26, 2025
27 checks passed
jacktose added a commit to jacktose-forks/homebrew-core that referenced this pull request Aug 30, 2025
This was attempted in Homebrew#214529, but not actually fixed. This changes the
approach from an environment variable to a `make` command argument. Full
explanation in discussion:
https://github.com/orgs/Homebrew/discussions/5421#discussioncomment-14260165

Closes https://github.com/orgs/Homebrew/discussions/5421
@cho-m
Copy link
Member

cho-m commented Aug 30, 2025

My root-cause analysis and possible general fix (for brew binutils + brew glibc) at

Still deciding if this should be handled in Homebrew/brew instead via -rpath-link.

@jacktose
Copy link
Contributor Author

This didn't actually make a difference because the Makefile's LDFLAGS = overrides the environment variable.
Trying again in #235572.
Also watching #235571 for a more general fix—thanks @cho-m.

jacktose added a commit to jacktose-forks/homebrew-core that referenced this pull request Aug 31, 2025
This was attempted in Homebrew#214529, but not actually fixed. This changes the
approach from an environment variable to a `make` command argument. Full
explanation in discussion:
https://github.com/orgs/Homebrew/discussions/5421#discussioncomment-14260165

Closes https://github.com/orgs/Homebrew/discussions/5421

Co-authored-by: Carlo Cabrera <github@carlo.cab>
jacktose added a commit to jacktose-forks/homebrew-core that referenced this pull request Aug 31, 2025
This was attempted in Homebrew#214529, but not actually fixed. This changes the
approach from an environment variable to a `make` command argument. Full
explanation in discussion:
https://github.com/orgs/Homebrew/discussions/5421#discussioncomment-14260165

Closes https://github.com/orgs/Homebrew/discussions/5421

Co-authored-by: Carlo Cabrera <github@carlo.cab>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI-no-bottles Merge without publishing bottles CI-skip-dependents Pass --skip-dependents to brew test-bot. in progress Stale bot should stay away

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants