Sign in to follow this  
rkaganda

undefine reference linker error?

Recommended Posts

've been trying to compile and link a projec in dev c++ with 3 files it compiles fine but when it tries to link i get the error C:\Dev-Cpp\projects\winclassproject\main.o(.text+0xb2) In function `Z11MainWndProcP6HWND__jjl': [Linker error] undefined reference to `_ZN10MainWindow9MyWndProcEP6HWND__jjl@20' i declare the function in one (mainwindow.h) as funtion of class MainWindow with this bit class MainWindow { ....other code public: LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); ....other code }; then define it in mainwindow.cpp with this LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { .... } then reference it in main.cpp here LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { return AppWindow.MyWndProc(hwnd,msg,wParam,lParam); } i also reference other member funtions of class MainWIndow with my instance AppWindow and they link fine? (i dont get linker errors when i reference them) i've tried to add to add mainwindow.o to the linker param when i buid but then i end up just getting many mutiple defintions errors the compile log is as follows: Compiler: Default compiler Building Makefile: "C:\Dev-Cpp\projects\winclassproject\Makefile.win" Executing make clean rm -f mainwindow.o main.o winclassproject.exe g++.exe -D__DEBUG__ -c mainwindow.cpp -o mainwindow.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -g3 g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -g3 g++.exe -D__DEBUG__ mainwindow.o main.o -o "winclassproject.exe" -L"C:/Dev-Cpp/lib" -L"gdi32.lib" -mwindows -g3 main.o(.text+0xb2): In function `Z11MainWndProcP6HWND__jjl': C:/Dev-Cpp/projects/winclassproject/main.cpp:28: undefined reference to `_ZN10MainWindow9MyWndProcEP6HWND__jjl@20' collect2: ld returned 1 exit status make.exe: *** [winclassproject.exe] Error 1 Execution terminated -- aahhhh thx for the help

Share this post


Link to post
Share on other sites
Quote:
then define it in mainwindow.cpp with this
LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
....
}
You need to add MainWindow:: to the name of the function, else the compiler won't know that you're implementing a function from the class MainWindow:

LRESULT CALLBACK MainWindow::MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
....
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this