Hi guys
I'm rather new to Visual Studio 2008 and C++. Recently, I was coding some classes for a 3D vector and 4x4 matrices. I wanted to test the operator overloading for multiplication between a vector and a matrix, so I wrote a MessageBox function within WinMain to output the x-coordinate of the resultant vector when a vector (1.0f, 1.0f, 1.0f) was multiplied by a translation matrix which was to translate by (1.0f, 1.0f, 1.0f) (so the result would have been 2.0f). All the code compiled fine, but I then encountered a slew of linker errors which looked like this:
Error 1 error LNK2019: unresolved external symbol "public: float __thiscall cn::vector3::X(void)const " (?X@vector3@cn@@QBEMXZ) referenced in function _WinMain@16 testm.obj cyanide
Error 2 error LNK2019: unresolved external symbol "public: class cn::vector3 & __thiscall cn::vector3::operator=(class cn::vector3 const &)" (??4vector3@cn@@QAEAAV01@ABV01@@Z) referenced in function _WinMain@16 testm.obj cyanide
I searched on Google for this error but all the advice given was something about not being able to find libraries. However, in this case, I was not using any libraries. In addition, all the files (header and cpp) were in the same place, which was the same folder that the .vcproj file was in. Since all my files were in the same place, how is it that linker errors can still occur.
Furthermore, I tried editing the VC++ Directories to make it point to my project folder for both Include and Source. Didn't work. Does anyone have suggestions as to how I can get around this problem?
Thanks!
errorLNK2019 - I need some help!
Moderator: Coders of Rage
Re: errorLNK2019 - I need some help!
I could be wrong; but that looks like a similar error I got earlier, check the method your calling, and make sure you properly defined it in a cpp file.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: errorLNK2019 - I need some help!
Just making sure, but you did add both the header and source files to your project, correct? Files in the same directory aren't automatically compiled and linked with the project.
Re: errorLNK2019 - I need some help!
Hey guys I realised what the problem was... the functions were inline!
When I removed the inline keyword from the functions, the project built just fine.
Can you guys advise me on how to add inline functions to a project and have it build?
When I removed the inline keyword from the functions, the project built just fine.
Can you guys advise me on how to add inline functions to a project and have it build?
- short
- ES Beta Backer
- Posts: 548
- Joined: Thu Apr 30, 2009 2:22 am
- Current Project: c++, c
- Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
- Programming Language of Choice: c, c++
- Location: Oregon, US
Re: errorLNK2019 - I need some help!
I can't exactly help you directly, not at least with more information or perhaps some source code, but I can attempt to explain how the inline keyword works.
The way I understand it is, and I would love it if someone would jump in and correct anything,
If you are at all familiar with loop unwinding, it's essentially the same thing except instead of unwinding a loop, you are unwinding function calls.
In loop unwinding, the idea is to take your loop and rewrite it so there exists no loop, by hand.
For example, say you had the following code:
to unwind the loop, you would rewrite the code as:
The output will always be the same, but notice the size difference (the size of the code, and the size of the instructions the compiler will turn your code into).
When I was learning assembly, we learned about how this was useful. When you create a loop your computer spends time moving things between different registers, various other movements, keeping track of counters etc... If you unwind the loop above, as I have done, it will run faster because you skip unnecessary register operations such as keeping track of variables and performing numerical computations (ie comparing count and your upper limit for a for loop).
To relate all this back to the inline keyword, when you designate an inline function you are telling the compiler to try and unwind that function.
to inline a function is essentially the same as unwinding a loop. Function calls, on the assembly level, involve pushing and popping the stack, changing certain registers, etc... calling a function, at the assembly level, is much more taxing then if you don't have to call said function. If your compiler can get away with it, instead of doing these micro-memory management with function calls, it will try and unwind your inline function. Perhaps it will take more memory to store the unwound function call (your executable will grow in size), but you will eliminate various reading and writing calls, and in theory speed up your program by removing low level memory redundancy's.
As for knowing when and when not to use the inline keyword, that's something I am not comfortable with myself. I hope my explanation makes sense.
The way I understand it is, and I would love it if someone would jump in and correct anything,
If you are at all familiar with loop unwinding, it's essentially the same thing except instead of unwinding a loop, you are unwinding function calls.
In loop unwinding, the idea is to take your loop and rewrite it so there exists no loop, by hand.
For example, say you had the following code:
Code: Select all
int i;
for(i = 0;i<5;i++)
{
printf("the number is %d \n", i);
}
Code: Select all
printf("the number is 0 \n");
printf("the number is 1 \n");
printf("the number is 2 \n");
printf("the number is 3 \n");
printf("the number is 4 \n");
When I was learning assembly, we learned about how this was useful. When you create a loop your computer spends time moving things between different registers, various other movements, keeping track of counters etc... If you unwind the loop above, as I have done, it will run faster because you skip unnecessary register operations such as keeping track of variables and performing numerical computations (ie comparing count and your upper limit for a for loop).
To relate all this back to the inline keyword, when you designate an inline function you are telling the compiler to try and unwind that function.
to inline a function is essentially the same as unwinding a loop. Function calls, on the assembly level, involve pushing and popping the stack, changing certain registers, etc... calling a function, at the assembly level, is much more taxing then if you don't have to call said function. If your compiler can get away with it, instead of doing these micro-memory management with function calls, it will try and unwind your inline function. Perhaps it will take more memory to store the unwound function call (your executable will grow in size), but you will eliminate various reading and writing calls, and in theory speed up your program by removing low level memory redundancy's.
As for knowing when and when not to use the inline keyword, that's something I am not comfortable with myself. I hope my explanation makes sense.
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
link: https://github.com/bjadamson
Re: errorLNK2019 - I need some help!
Haha thanks for the info! I understand quite a lot more about inline functions now.
Also, I found a solution to the problem that I initially posted about... I realised that I had to include the .cpp/.inl file instead of the header file when using inline functions.
Thanks to all who had taken the time to reply to this thread!
Also, I found a solution to the problem that I initially posted about... I realised that I had to include the .cpp/.inl file instead of the header file when using inline functions.
Thanks to all who had taken the time to reply to this thread!
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: errorLNK2019 - I need some help!
Yeah, when you use an inline function, you have to have the definition of that function immediately available.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.