Share class between projects in single solution?

So I have a class which contains a function that I would like to use in another project. I am 100% positive that it is possible and have seen it done, which might be because of std::shared_ptr<class to share> but am not positive. How would I call functions from a class in another project with out getting external symbol errors.

P.S. I have already referenced and added includes to what needs to be added, the problem is to do with actually calling the function in the class. For example I can put a "float i = 10" and call for "i" easily but when I call for "vec2 CheckMousePos()" is gives me an external symbol error
What you want to do is place the function in a separately compiled file. You would create a .h file with the header declarations for your shared function(s). Include the new .h file in both projects. Compile the .cpp file for your function into a .o file, then include the .o file in both projects. If you have a number of shared functions, you can create a .lib file. Details of including the .o or .lib file in your project depend on what IDE you're using. In Visual Studio, there is a property page that allows you to specify additional object or library files. Other IDEs should be similar.


Last edited on
vec2 CheckMousePos()Is an 'usual' way to call a function.

vec2.CheckMousePos()Is a very familiar way to call a function in some class where vec2 is an instance/object of that class.

The #include'd files need to be in the right path/directory so the project has access to them/it

std::shared_ptr<class to share> is not relevant here.
If your class is in one .h file and one .cpp file you need to reference these two files in the project you want to use it. How to do it depends on the IDE or build system you are using.
Using Visual Studio:
Walkthrough: Create and use a static library (C++) - https://docs.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-static-library-cpp?view=msvc-160
Topic archived. No new replies allowed.