Undefined reference to yywrap
Task Info (Flyspray) | |
---|---|
Opened By | Thomas Reim (rdratlos) |
Task ID | 79780 |
Type | Bug Report |
Project | Arch Linux |
Category | Packages: Core |
Version | None |
OS | All |
Opened | 2023-09-25 14:24:09 UTC |
Status | Assigned |
Assignee | Lukas Fleischer (lfleischer) |
Assignee | David Runge (dvzrv) |
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