Jump to content
  • Advertisement
Sign in to follow this  
RoundPotato

Custom C++ Classes in Visual Studio Express 2012

This topic is 2140 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.

 

This problem should be pretty common so hopefully someone can fire the answer I seek straight away.

 

I made a few C++ classes in the regular "myClass.h" + "myClass.cpp" manner. Naturally I collected the classes in a folder, now I want to pretend that this is a valid "library" and want to include the path to this folder in Visual Studio. .cpp and .h files are at the same location, if I add the path to that folder in "Project Settings -> C/C++ -> General -> Additional Include directories" it does not complain about the "#include "path/to/myClass.h" , however it throws a Linker error when I attempt to build (also "Go to Definition on mouse Context fails or takes me to the header").

 

I don't know how or what those ".dll" libraries are and hopefully I can get away without building any.

 

unsure.png

Share this post


Link to post
Share on other sites
Advertisement
Just adding a header to your #include path does not include the .cpp file in your project. You need to have the .cpp file in the project itself so the linker knows where to find all the code you wrote :-)

The other alternative would be to create a static library project with your classes in it, and link to that .lib instead of compiling the .cpp file directly. If this code doesn't change often and you want to reuse it in many projects, that's a good route to take.

Share this post


Link to post
Share on other sites

Yes, there are 2 different choices on "reusing" class in C++, and you are accidentally trying a hybrid between them.

1.  The CODE sharing route.  Include the code itself into your project directly ... and #include it using relative paths with quotes.

2.  The LIBRARY sharing route.  Put the code into a separate project, compile that into a library.  Add the path to the HEADER files to your include configuration, and #include it using traditional style includes (angle-brackets instead of quotes).  Then ALSO add a reference to the library to your project.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!