使用i686-w64-mingw32-gcc编译PDCurses3.5遇未定义引用问题求助
Hey there, let's troubleshoot this linker error you're facing. Undefined reference errors almost always mean the linker can't find the symbols (like COLS and LINES) in the libraries you're linking—so let's go through the most common fixes step by step:
1. Make sure your compile command links PDCurses correctly
MinGW's GCC doesn't automatically link against PDCurses; you need to explicitly specify the library, and the order matters. Your compile command should look like this:
i686-w64-mingw32-gcc your_program.c -o your_program.exe -lpdcurses
If your libpdcurses.a isn't in MinGW's default library directory, add the -L flag to point to the folder containing the library:
i686-w64-mingw32-gcc your_program.c -o your_program.exe -L/path/to/your/pdcurses/lib -lpdcurses
Note: The -lpdcurses flag must come after your source files—GCC processes libraries in the order they're listed, so putting it first won't work.
2. Define the static library macro (if using libpdcurses.a)
PDCurses uses different symbols for static vs dynamic linking. Since you're using the static library libpdcurses.a, you need to tell the compiler to use static symbols. You can do this in two ways:
- In your code: Add this line before including
<curses.h>:#define PDCURSES_STATIC #include <curses.h> - Or in your compile command: Use the
-Dflag to define the macro at compile time:i686-w64-mingw32-gcc -DPDCURSES_STATIC your_program.c -o your_program.exe -lpdcurses
Without this macro, the compiler might look for dynamic library symbols that don't exist in your static libpdcurses.a.
3. Double-check library and architecture compatibility
Ensure your libpdcurses.a was compiled for the i686-w64-mingw32 architecture. If you downloaded a pre-built library, make sure it's labeled for 32-bit MinGW-w64. If you compiled PDCurses yourself, confirm you used the i686-w64-mingw32 toolchain (not regular MinGW, MSVC, or x86_64-w64-mingw32) to build it.
4. Verify symbol names in your code
Wait—PDCurses defines these as uppercase COLS and LINES, not lowercase lines. If your code uses lines (lowercase), that's a typo! Fix that to match the uppercase symbols declared in <curses.h>.
5. Ensure header and library versions match
Mismatched <curses.h> header and libpdcurses.a library versions can cause missing symbols. Make sure the header file you're including comes from the same PDCurses 3.5 package as your library file.
Give these steps a try—most likely, the issue is either missing the -lpdcurses flag in the right place, or forgetting to define PDCURSES_STATIC for static linking.
内容的提问来源于stack exchange,提问作者muramatsu reina

