FS#79780 - [flex] Undefined reference to yywrap

Attached to Project: Arch Linux
Opened by Thomas Reim (rdratlos) - Monday, 25 September 2023, 14:24 GMT
Last edited by Buggy McBugFace (bugbot) - Saturday, 25 November 2023, 20:15 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Lukas Fleischer (lfleischer)
David Runge (dvzrv)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

When building packages that use flex as development tool linking may abort with following error notification:'undefined reference to yywrap'.

Analysis revealed that yywrap() is part of the provided flex include file FlexLexer.h and part of the provided shared libfl.so library. But flex yywrap() calls fail as shared library libfl.so cannot resolve required yylex() function. On the other hand when using static libraries for flex the error disappears and package build using flex succeeds. As shared libraries take precedence over static libraries during linking the trick here is to provide static library libl.a, which is linked to libfl.a. This is the configuration applied by main Linux distributions (Fedora, Ubuntu, etc.) in their development packages.

Even if we can think about much better fix strategies there is a further dealbraker, which blocks other solutions. Package autoconf provides macros for checking the availability of flex libraries. These macros use the same approach as outlined below in section 'Steps to reproduce'-

Proposal for a quick-fix would be to align ArchLinux package flex with other distributions and to provide also static libraries for using flex within other development projects. Attached is the required patch for PKGBUILD.

Additional info:
* all up to 2.6.4-5

Steps to reproduce:
- Download file conftest.c
- Execute gcc conftest.c
/usr/bin/ld: /tmp/ccLxBjIx.o: in function `main':
conftest.c:(.text+0xa): undefined reference to `yywrap'
collect2: error: ld returned 1 exit status
- Execute gcc conftest.c -lfl
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/libfl.so: undefined reference to `yylex'
collect2: error: ld returned 1 exit status
- Execute gcc conftest.c -ll
/usr/bin/ld: cannot find -ll: No such file or directory
collect2: error: ld returned 1 exit status
- Patch PKGBUILD using PKGBUILD.diff, rebuild flex and install
- Execute gcc conftest.c
/usr/bin/ld: /tmp/ccLxBjIx.o: in function `main':
conftest.c:(.text+0xa): undefined reference to `yywrap'
collect2: error: ld returned 1 exit status
- Execute gcc conftest.c -lfl
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/libfl.so: undefined reference to `yylex'
collect2: error: ld returned 1 exit status
- Execute gcc -o conftest conftest.c -ll
Build succeeds with result code 0 and executing ./conftest finishes with result code 1
This task depends upon

Closed by  Buggy McBugFace (bugbot)
Saturday, 25 November 2023, 20:15 GMT
Reason for closing:  Moved
Additional comments about closing:  https://gitlab.archlinux.org/archlinux/p ackaging/packages/flex/issues/1
Comment by loqs (loqs) - Monday, 25 September 2023, 22:28 GMT
With respect to the autoconf macros I found:
AC_PROG_LEX and AC_PROG_LEX(noyywrap) work while AC_PROG_LEX(yywrap) does not work. See attached archive for how I was testing.
Comment by Toolybird (Toolybird) - Monday, 25 September 2023, 23:49 GMT
The static libs were dropped from this pkg 9 years ago..which suggests this isn't much of a problem. As you're aware, Arch policy is to not ship static libs unless absolutely necessary. FWIW, the AUR pkg "flex-git.git" does use "options=('staticlibs')". It probably wouldn't hurt to make an exception here.
Comment by Thomas Reim (rdratlos) - Tuesday, 26 September 2023, 06:44 GMT
Mmmh. Difficult. What means "unless absolutely necessary"? I saw one or two complaints about broken Arch flex but no related further activities.

The package I work on uses AM_PROG_LEX macro:

without static lib:
checking for lex library... none needed
checking for library containing yywrap... no

with static lib:
checking for lex library... none needed
checking for library containing yywrap... -ll

Comment by Thomas Reim (rdratlos) - Tuesday, 26 September 2023, 06:55 GMT
My current understanding is that flex provides a shared library with function yywrap(), which can't be linked into dependent projects. And a corresponding static library, which provides the required functions. automake detects this correctly, so subsequent projects could decide how to handle missing yywrap(). E. g. write an own one. On the other hand providing a quick fix adding the missing static library would help others but violate Arch policy.

The ball is on your court :-)

Loading...