So I am having a bit of trouble with a few things. I am using c++ with SDL in Visual Studio 10. Firstly, I want to create a lib to be reused for other projects. I have created a new empty project, added the stuff I want for the libs inside of it, changed the Configuration Type to a static lib and now I am left with two projects, one for my lib and one for my game. My question is how to actually link my lib up with my game. It seems my game can read my libs header files but I get some errors.
~ error LNK2019: unresolved external symbol "public: __thiscall Vector2::Vector2(float,float)" (??0Vector2@@QAE@MM@Z) referenced in function "void __cdecl `dynamic initializer for 'm_oMenuPosition''(void)" (??__Em_oMenuPosition@@YAXXZ)
~ error LNK2001: unresolved external symbol "public: __thiscall Vector2::Vector2(float,float)" (??0Vector2@@QAE@MM@Z)
(times 14 for this one, but you get the idea with one of them)
and then the fatal error LNK1120
What should I be doing in my main.cpp? or what should I be trying to link, I thought about adding the libs to my linker but they are .vcxproj files, not actual libs.
Any help would be great, I will try and fill people in with any detail they need
If you built your library, then somewhere you have a *.lib file (as opposed to a *.dll for a dynamic library) containing the actual compiled code.
The header file you include in your code for that library tells the compiler about the functions in the lib. It doesn't provide the functions; you have to link the library. In your IDE's many menus, somewhere there is a line to tell it which library to link against, and where to find that library.
Right click the solution (in the solution explorer), and then click properties. You get a window with a tree view on the left, click Linker. After clicking General you will see an option Additional Library Directory on the right. Give this option a path to your lib. Then, back to the tree, click Command Line, type the name of your file in the edit box on the right.
By default, you will be changing the options for the current compile mode your in, debug/release. You can change this setting at the top of the properties window.
Sorry for the late reply, been busy but thanks a lot Moschops, I wish that crossed my mind beforehand, makes so much sense. All is working now, game runs perfectly, few warnings but that will be sorted out later. Thanks heaps.
Thanks LowestOne as well, problem was I actually didn't compile my lib in the first place, thanks for your help though