tags:

views:

205

answers:

1

When I try to compile the following:

#include <windows.h>
#include <shlwapi.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  char firstPart[MAX_PATH] = "c:\\windows";
  char secondPart[MAX_PATH] = "system32";
  PathAppend(firstPart, secondPart);

  return 0;
}

Using the command:

c:\mingw\bin\gcc -mwindows -mno-cygwin -o test test.c

It fails with the error:

undefined reference to `_imp__PathAppendA@8'

Surely this is some stupidity on my part, but can someone tell me what I'm missing here?

A: 

You need to add the shlwapi library for linking:

gcc -o test test.c -lshlwapi

Works for me

David Cournapeau
Perfect! I had tried using the -lshlwapi before the filenames, but I guess it goes after.
Ben Alpert
Hm, that's strange. It is a toolchain bug IMO: the order of options should not matter in this case. Using gcc on linux does not have this problem. Looking at gcc -v, I can see that the -lshlwapi is simply ignored when put before test.c. Maybe recent gcc (4.4 serie) do not have those problems.
David Cournapeau
Sorry, I means 4.* serie. The officially released mingw gcc is ancient (3.4 serie) - if that's an option, you should use more recent, either by compiling it yourself, or using available binary out there.
David Cournapeau