0

I created an empty C++ project in Visual Studio and added some code. Then following Microsoft's instructions I created a new Google Test project, selected "Add to solution" with my first project, and then in the next screen I selected the first project as the project under test.

I can get the main project to run, and I can get a test to run if it doesn't use my code. But I can't use my code in the tests.

Here is the current code that's trying to make its way to the test. You can also see in the explorer that the main project is indeed referenced in the test project.

But that is basically all I've done. I haven't played with any other settings anywhere at all. So don't assume I did something, or know something. Pretty n00by in these situations.

Thanks. enter image description here

The error: enter image description here

With regards to this being marked as a duplicate: while the question you've linked to does appear to make it clear that I have some sort of linker problem, there is so much information there -- over a dozen common causes -- that it doesn't actually help me answer my question, or at least not much more than telling me to, say, "read these 10 chapters of this C++ textbook". I would appreciate a response that points as close to "exactly" what I'm doing wrong as reasonably possible.

Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129
  • In native c++ I don't believe you can reference an executable. You can make HackAssembler a dll and link to the import library for this to work. – drescherjm Jan 12 '21 at 22:03
  • 1
    In order to answer your question you need to provide details of how you link to the project under test: Do you link statically, dynamically? Do you link the msvcrt statically or dynamically: /MT /MTD options? Which version of the msvcrt do you use? Do you link google test statically /dynamically? There's a lot of conflicting options which makes google test hard to use under some circumstances. Btw.: Don't think this is a duplicate. It's a configuration issue. The linker error is a secondary error resulting from a misconfiguration not from the lack of understanding howto link a function. – Wör Du Schnaffzig Jan 12 '21 at 22:22
  • @pqans, this is what I mean by "don't assume I did something, or know something." So sincere thanks for asking some useful questions :) Clearly the questions you're asking are the important ones, but my answer is, I have absolutely no idea, so "how to do any of that" will need to be part of the answer. – Jonathan Tuzman Jan 12 '21 at 22:25
  • 1
    Is your HackAssembler project producing a .lib (static lib) or a .dll and a .lib (dynamic lib)? In the wizard, when you created your google test project, did you select to link against googletest statically or dynamically? – Wör Du Schnaffzig Jan 12 '21 at 22:31
  • I selected to link gtest dynamically, which was the recommended default in the wizard. As for your first sentence, I have no idea, you're over my head. How can I find out? – Jonathan Tuzman Jan 12 '21 at 22:34
  • In the project settings on the first or second page you can see the option for linking as a static or dynamic lib. – Wör Du Schnaffzig Jan 13 '21 at 22:22
  • ... and there is also the option for the msvc runtime and the visual studio sdk. See: https://learn.microsoft.com/de-de/cpp/build/working-with-project-properties?view=msvc-160. On the compiler settings under code generation you find the option how to link the runtime (/MD = dynamic, /MT = static) – Wör Du Schnaffzig Jan 13 '21 at 22:29
  • Post code and error messages in question as text, not image. – June7 Jan 15 '21 at 01:06

0 Answers0