Jump to content
  • Advertisement
Sign in to follow this  
KaelisAsur

MSVC++ linking troubles

This topic is 3966 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

Hello there. Im an intermediate C++ coder. My IDE of choice is MSVC++. Right now im learning how to use HGE (2d graphics library) with Guichan (GUI library supporting HGE). Admittedly, im quite new to the whole concept of organizing my project code. Ive read the 'Organizing Code Files in C and C++' on GameDev and gathered as much information as i could. However, im having a problem with using classes defined/declared in separate files which i cant seem to resolve. I have a class inheriting from ActionListener and implementing action function. ButtonActionListener.h:
#ifndef INC_BUTTONACTIONLISTENER_H
#define INC_BUTTONACTIONLISTENER_H

#include <guichan.hpp>
#include <guichan/hge.hpp>

class ButtonActionListener : public gcn::ActionListener
{
public:
void gActionListener(void);

void action(const gcn::ActionEvent& actionEvent);
};

#endif /* INC_BUTTONACTIONLISTENER_H */

ButtonActionListener.cpp:
#include "ButtonActionListener.h"
#include "main.h" // extern imageButton is in here

void ButtonActionListener::gActionListener(void)
{
}

void action(const gcn::ActionEvent& actionEvent)
{
if (actionEvent.getSource() == imageButton)
{

}
}

An external pointer to ButtonActionListener is declared in in main.h:
#include "ButtonActionListener.h"

extern ButtonActionListener* buttonActionListener;

Now i want to use this pointer as a handle for new ButtonActionListener object in funcion initWidgets() located in initWidgets.h and initWidgets.cpp. initWidgets.cpp:
#include "main.h"

ButtonActionListener* buttonActionListener;
(...)
void initWidgets()
{
(...)
buttonActionListener = new ButtonActionListener();
}

This is where it fails with this error: initWidgets.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall ButtonActionListener::action(class gcn::ActionEvent const &)" (?action@ButtonActionListener@@UAEXABVActionEvent@gcn@@@Z) Any help appreciated.

Share this post


Link to post
Share on other sites
Advertisement
When you wrote the function definition for action() you didn't put the ButtonActionListener:: in front of the name.

Share this post


Link to post
Share on other sites
Hahaha, thats grand! Im searching all over the internet for linking errors, trying various include configurantions when its such a simple mistake! Thanks, and sorry for wasting your time.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!