Sign in to follow this  

undefine reference linker error?

This topic is 4456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
is mainwindow.cpp in the project with the main.cpp file? If so, you dont need to link the mainwindow.o file.
EDIT: nevermind, the guy above me got it correct.

Share this post


Link to post
Share on other sites

This topic is 4456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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