0

I am trying to use Visual Studio 2017 to create a C++ project and then test it with Google Test. I followed this guide to create my project and set Google Test for it: https://learn.microsoft.com/en-us/visualstudio/test/how-to-use-google-test-for-cpp

My solution has two projects Matrix and Matrix-Test (Google Test project). Project Matrix contains a class called Table. Project Matrix-Test contains a single test where a Table object is declared. Everything looks like this: enter image description here

If I try to build the solution I get the following errorsenter image description here:

However, if I don't declare the Table object in the test, then the solution builds successfully.
enter image description here

Please let me know if you have any idea why I get these errors. Thank you!

2
  • 2
    It's been a while since I did VisualStudio, but your Matrix project should be configured to create a library (.lib) output. And then your Matrix-Test needs to link using this library, which will fix the linker errors. Commented May 8, 2018 at 18:58
  • Based on your suggestion I tried to create static library project instead of a regular console application and add Google Test to it. It built without any errors. Maybe you can post as an answer for how to configure a console application project to create the library (.lib). Commented May 8, 2018 at 20:54

1 Answer 1

1

The walkthrough https://learn.microsoft.com/en-us/cpp/windows/walkthrough-creating-and-using-a-static-library-cpp?view=vs-2017 will guide you through the process of making your project Matix a static library.

Then you can add this library (e.g. Matrix.lib) as an input to the linker in the Matrix-Test project. This will solve the unresolved external symbol error in regard to your Table class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.