Bug 27242 - multiple definition of `UP'; ../readline/readline/libreadline.a(terminal.o):terminal.c:(.bss+0x98): first defined here
Summary: multiple definition of `UP'; ../readline/readline/libreadline.a(terminal.o):t...
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: win32 (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 28433 28434 (view as bug list)
Depends on:
Blocks:
 
Reported: 2021-01-25 13:35 UTC by Christian Biesinger
Modified: 2022-08-18 09:19 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Biesinger 2021-01-25 13:35:08 UTC
On mingw64, I get this link error:

make[2]: Entering directory '/home/Christian/binutils-gdb/mingw-obj/gdb'
  CXXLD  gdb.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib/libncursesw.a(lib_termcap.o):(.bss+0x8): multiple definition of `UP'; ../readline/readline/libreadline.a(terminal.o):terminal.c:(.bss+0x98): first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib/libncursesw.a(lib_termcap.o):(.bss+0x0): multiple definition of `BC'; ../readline/readline/libreadline.a(terminal.o):terminal.c:(.bss+0xa0): first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../lib/libncursesw.a(lib_tputs.o):(.bss+0x6): multiple definition of `PC'; ../readline/readline/libreadline.a(terminal.o):terminal.c:(.bss+0xa8): first defined here
collect2.exe: error: ld returned 1 exit status
make[2]: *** [Makefile:1881: gdb.exe] Error 1


$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\msys64\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-10.1.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++ --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --disable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev3, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.1.0 (Rev3, Built by MSYS2 project)

$ ld -v
GNU ld (GNU Binutils) 2.34
Comment 1 Christian Biesinger 2021-10-07 17:28:56 UTC
*** Bug 28434 has been marked as a duplicate of this bug. ***
Comment 2 Christian Biesinger 2021-10-08 21:33:42 UTC
So this could be worked around by using system readline, presumably. But still investigating what's going on. This is the code in readline:

#if !defined (__linux__) && !defined (NCURSES_VERSION)
#  if defined (__EMX__) || defined (NEED_EXTERN_PC)
extern 
#  endif /* __EMX__ || NEED_EXTERN_PC */
char PC, *BC, *UP;
#endif /* !__linux__ && !NCURSES_VERSION */

As far as I can tell, NEED_EXTERN_PC is never defined anywhere (??)
Comment 3 Christian Biesinger 2021-10-08 21:45:01 UTC
Hmm... so readline doesn't uses curses (I did not pass --with-curses), so it just uses termcap, so that doesn't define NCURSES_VERSION. Interestingly, even termcap.h declares UP/BC/PC so it seems readline wouldn't have to.

Anyway, gdb does use ncurses, so it uses -lncursesw, so that definition conflicts with readline's.
Comment 4 Christian Biesinger 2021-10-08 21:56:47 UTC
Though --with-curses doesn't help because readline prefers termcap.h over ncurses/termcap.h
Comment 5 Hannes Domani 2022-03-18 12:41:48 UTC
*** Bug 28433 has been marked as a duplicate of this bug. ***
Comment 6 Ari Hannula 2022-08-18 09:19:04 UTC
(In reply to Christian Biesinger from comment #3)
> Hmm... so readline doesn't uses curses (I did not pass --with-curses), so it
> just uses termcap, so that doesn't define NCURSES_VERSION. Interestingly,
> even termcap.h declares UP/BC/PC so it seems readline wouldn't have to.
> 
> Anyway, gdb does use ncurses, so it uses -lncursesw, so that definition
> conflicts with readline's.

I ran into this issue too when compiling gdb in MSYS2/MinGW64 on Windows.
It's strange since indeed termcap.h already has those UP/BC/PC declared. So not declaring those in terminal.c again made the error go away.

Maybe a solution would be to check if termcap.h has already been included e.g.

#if !defined (__linux__) && !defined (NCURSES_VERSION) && !defined (_TERMCAP_H)
...

Then at least this problem would go away..

Another issue I faced was that int tgetnum (const char *) method was not found during linking, I solved it by giving -DNCURSES_STATIC to compiler CXXFLAGS. It is supposed (?) to be defined when building in MinGW but somehow was not.