error LNK2019 I have no idea...

Pages: 12
1
2
3
4
1>headerwork.obj : error LNK2019: unresolved external symbol "public: void __thiscall ColourController::setForeground(enum colour)" (?setForeground@ColourController@@QAEXW4colour@@@Z) referenced in function "public: void __thiscall CenteredInputBox::setPosition(int,int)" (?setPosition@CenteredInputBox@@QAEXHH@Z)
1>headerwork.obj : error LNK2019: unresolved external symbol "public: void __thiscall CursorController::clearAll(void)" (?clearAll@CursorController@@QAEXXZ) referenced in function "public: void __thiscall StickMan::setPosition(int,int)" (?setPosition@StickMan@@QAEXHH@Z)
1>headerwork.obj : error LNK2019: unresolved external symbol "public: void __thiscall ColourController::setBackground(enum colour)" (?setBackground@ColourController@@QAEXW4colour@@@Z) referenced in function "public: void __thiscall drawSquare::display(void)" (?display@drawSquare@@QAEXXZ)
1>EDITFOLDERSTRUCTURE\week14header.exe : fatal error LNK1120: 3 unresolved externals



What am I looking for with these problems?

I have pointers pointing to each of them from the classes.
Last edited on
The linker can't find the code for those functions. Where are they defined?
All the voids (functions) are defined in the same file I am debugging to get that message. I have a header file for classes and all the functions in this one... (part of uni work)
Am I mistaken in thinking that it means the linker isn't being linked with the library you are using (or headers)?
I have like.... a lot of classes and functions but these 3 are playing up... Probably all of them will as I solve each one I guess.
Are you sure you've coded these functions?
Yes... the middle one for example:

1
2
3
4
5
6
void StickMan::setPosition(int xpos, int ypos)//Stick man function.
{
	x=xpos;
	y=ypos;
	crs->clearAll();
}
It's not complaining about StickMan::setPosition, it's complaining about:
1
2
3
ColourController::setForeground
CursorController::clearAll
ColourController::setBackground
To me it looks like you are trying to use functions from a library that you haven't linked to properly. Whatever library you are using that has clearAll, setForeground, setBackground member functions isn't linked or connected properly to your project so it is spitting out errors about their calls in your functions. Of course I'm going off the compiler I use as it only shows that sort of thing if I am trying to use a library, if it is a function call to something else it normally just says it is undefined.
Last edited on by closed account z6A9GNh0
The header file I need is included, although it has also been split into a class header file and a function cpp file...

Could it be due to the pointers I created as all of my functions are needing to point to CursorController and ColourController.


Nothing to do with pointers. Did you find the implementation of those functions in your source file? That's really the question I've been asking but you're not answering it.
The header file I need is included, although it has also been split into a class header file and a function cpp file...

Open that function cpp file.
Check that
1
2
3
ColourController::setForeground
CursorController::clearAll
ColourController::setBackground

are defined in it.
Check that it's being compiled into an object file (if this means nothing to you, add "find out what a compiler does" to your list of things to do and check that it's being included in your "project" or whatever your chosen dev env uses).
Check that your linker is being told to link against the compiled object file.

One or more of these steps is failing.
Last edited on
They are defined as my lecturer created those files which I am including. I have created my classes like stickman and InputBox etc...

Those functions do exist, and have used them before, just in my project they are failing.
I am using VS Pro 2010.
Which step of the ones I gave in my post is failing? Are they being compiled? Is the linker linking to them?

A simple way to check they're being compiled is to stick XXXHFUDSHFKJSEBFIJDSGUIGHEUIR in the middle of them and then rebuild. If they refuse to compile because of XXXHFUDSHFKJSEBFIJDSGUIGHEUIR in the middle, then you know they are being compiled.

I am using VS Pro 2010.

I do wish academic institutions wouldn't do things like that. They've left you unable to solve this remarkably simple problem yourself because you don't know what to do when the magic buttons don't work :(
Last edited on
Stick that in the middle of the functions I created (StickMan etc) or the header file functions?
The function ColourController::setForeground. Not in the prototype declaration. In the code that actually does whatever that function does.

The intention is to test if the compiler is being fed that source code, by deliberately breaking it, so it has to go in the function definition (not the declaration). Typically, this is done in a cpp file.
I put that in and got the error that it was undeclared. :)

The thing is, both header files are included in my project and all of the functions for both are now in 1 cpp file....

I think that is how it should be?
This is most likely a problem wtih your property sheets, check your additional include directories, the input part of the linker section... etc. Your linker can't find your objects
Aye. Clearly it's being compiled - for whatever reason, your linker is not being fed the compiled object file.
Is all of this because of my pointers and maybe I am missing some & or * symbols somewhere? I am new to this, only a first year student haha...

Where should I be looking, the file I have created or the functions from ColourController and CursorController as that file is one my lecturer provided you see.

I would go and ask but it is due today you see and fancied working it out myself... Hm
Pages: 12