windows.h and undefined ref

I have the following programs:

astrowin.h
#ifndef ASTROWIN_H
#define ASTROWIN_H

#include <windows.h>

HBRUSH BuildBrush(BYTE,BYTE,BYTE);

#endif

astrowin.c
#include <windows.h>

HBRUSH BuildBrush(BYTE R,BYTE G,BYTE B) {
return CreateSolidBrush(RGB(R,G,B));
}

eepeople.cpp
#include "astrowin.h"
#include <windows.h>

const char g_szClassName[] = "EE Person";

// Step 4: the Window Procedure
LRESULT CALLBACK Process(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;

//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = Process;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = BuildBrush(0,0,0);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Enter/Edit People",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 340, 220,
NULL, NULL, hInstance, NULL);

if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
(mostly filched from forger's Win32 tutorial)

When I compile this, I give gcc:
gcc eepeople.cpp astrowin.c -lgdi32 -o ee.exe

And gcc returns this:
C:\Users\bby\AppData\Local\Temp/ccotcaaa.o:eepeople.cpp:(.text+0xf0): undefined
reference to `BuildBrush(unsigned char, unsigned char, unsigned char)'
collect2: ld returned 1 exit status

But as far as I can see, this should be a simple program to link together. When I test this in a program that does not use WinMain, it compiles fine. And when I move BuildBrush into eepeople.cpp, it compiles fine, so I don't think that there is any conflict with the parameters being passed to BuildBrush. What is wrong with the way that I am linking to BuildBrush in astrowin.c?
astrowin.h is only forward-declaring the BuildBrush() function. You need to extern it as opposed to forward-declare it.
Topic archived. No new replies allowed.