0

I have some problems compiling my test program using PDCurses library. I have compiled PDCurses 3.4 with MinGW compiler 8.2.0. In output I have 2 files panel.a and pdcurses.a. I copied them to C:\MinGW\lib plus the header file curses.h in C:\MinGW\include. But when I try to compile test program I have errors. It seems I have done everything correctly according to instructions and how-to`s.

Some testing C code:

#include <C:\MinGW\include\curses.h>

int main () {
    initscr();
    mvprintw( 5, 5, "Hello, World!" );
    getch();
    endwin();
    return 0;
}

ERRORS:

c:/Users/username/Dropbox/rakshasa/main.c:4: undefined reference to `initscr'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:/Users/username/Dropbox/rakshasa/main.c:5: undefined reference to `mvprintw'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:/Users/username/Dropbox/rakshasa/main.c:6: undefined reference to `stdscr'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:/Users/username/Dropbox/rakshasa/main.c:6: undefined reference to `wgetch'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:/Users/username/Dropbox/rakshasa/main.c:7: undefined reference to `endwin'

I have no idea why it is not compiling properly. It looks like compiler cant find libraries in linking stage but I do not know why.

I was try to compile like gcc -g main.c -o main.exe

Thanks in advance.

Ermac
  • 1
  • 1
  • You might start by finding out why the compiler couldn't find the reference to `initscr`. – Scott Hunter Apr 19 '19 at 13:26
  • You have to tell the linker step whoch objects to link and which libraries to use. Simply placing files in a lib dir often isn't enough. You may need to adapt the makefile. – Paul Ogilvie Apr 19 '19 at 13:50
  • 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) – Mike Kinghan Apr 22 '19 at 08:23
  • ...and the relevant answer is [Failure to link against appropriate libraries/object files or compile implementation files](https://stackoverflow.com/a/12574400/1362568) – Mike Kinghan Apr 22 '19 at 08:24

1 Answers1

0

Never use absolute paths in #include directives. Instead of #include <C:\MinGW\include\curses.h> you should put #include <curses.h> and compile with -IC:\MinGW\include flag if needed.

Next you need to link with the relevant library using -lpdcurses. If needed you can add the location of the library using -LC:\MinGW\lib.

So if we split compilation and linking steps you need the following commands:

gcc -g main.c -c -o main.o -IC:\MinGW\include
gcc main.o -o main.exe -lpdcurses -LC:\MinGW\lib

though I think you can leave out the -I and -L flags as they point to the location of your compiler's include and lib folders.

Finally: MinGW is a bit outdated and so is GCC 8.2.0. I recommend you switch to MinGW-w64 (which supports both 32-bit and 64-bit Windows). To get a more recent MinGW-w64 GCC build, you can try the standalone builds from https://winlibs.com/.

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40