0

I'm working on a program in which I use PDCurses3.5 functions using i686-w64-mingw32-gcc.exe. When I compile the program, I keep getting errors such as "undefined reference to 'COLS'", "undefined reference to 'lines'". I have checked that <curses.h> header and the library package properly installed. Here is my input line:

> i686-w64-mingw32-gcc.exe set.o read.o elements.o random.o
> -L../standard/test -lplotfit -lplotget -lgfortran -Wl,--subsystem,console -mwindows -o runtime/mingw/result -lm -static -lws2_32  -lpdcurses

And the first part of the error is:

../standard/bin/mingw/menu.o:menu.c:(.text+0xb): undefined reference to `COLS' 
../standard/bin/mingw/menu.o:menu.c:(.text+0x16): undefined reference to `COLS' 
../standard/bin/mingw/menu.o:menu.c:(.text+0x33): undefined reference to `LINES' 
../standard/bin/mingw/menu.o:menu.c:(.text+0x47): undefined reference to `MOVE' 
../standard/bin/mingw/menu.o:menu.c:(.text+0x74): undefined reference to `initscr'
...

It seems the program cannot refer to libpdcurses.a in its library file. What am I doing wrong?

  • Possible duplicate of https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – machine_1 Feb 11 '18 at 20:37
  • did you check path of libpdcurses.a you may try to copy libpdcurses.a to your current directory where gcc linker runs and try again. In Msys2 i successfully compile and run pdcurses libraries. – RedArrow Feb 11 '18 at 20:57
  • 4
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – MechMK1 Feb 11 '18 at 21:21

1 Answers1

0

When you use -lpdcurses, the linker looks for libpdcurses.a in certain predefined locations, plus those specified via -L. But, by default, the library is built as pdcurses.a. To link it, you can directly specify its location; e.g.:

gcc -oprogname.exe progname.c pdcurses.a

or

gcc -oprog2.exe prog2.c /pdcurses/win32/pdcurses.a

Alternatively, you can rename the library to libpdcurses.a, and either copy it to a location in the existing search path, or use -L:

gcc -oprogname.exe progname.c -lpdcurses

or

gcc -oprog2.exe prog2.c -L/pdcurses/win32 -lpdcurses
William McBrine
  • 2,166
  • 11
  • 7