[英]Cannot Link between 2 projects in the same solution, and i dont have a .Lib File for additional dependencies
I have a main project and which there I implement some classes and functionality and also a main.cpp
to run everything.我有一个主项目,在那里我实现了一些类和功能,还有一个
main.cpp
来运行所有内容。
Now I try to add another project to test my main project, so I create another project in the same solution which will be my Unit Test Catch 2 for my original project.现在我尝试添加另一个项目来测试我的主项目,所以我在同一个解决方案中创建了另一个项目,这将是我原始项目的单元测试 Catch 2。
Now I try to reference my original project inside my test project - didn't work.现在我尝试在我的测试项目中引用我的原始项目 - 没有用。 I also try to add in linker input dependencies my whole original folders, the debug folder and the cpp folder - didn't work.
我还尝试在 linker 输入依赖项中添加我的整个原始文件夹、调试文件夹和 cpp 文件夹 - 不起作用。
Finally I understand that I try to search for lib file of the Original project to refer inside my Test project but cannot find lib file.最后,我了解到我尝试搜索原始项目的 lib 文件以在我的测试项目中引用,但找不到 lib 文件。 Is there another way to link between the two projects so I can call classes and functions inside my Test project and test them?
是否有另一种方法可以在两个项目之间进行链接,以便我可以在我的测试项目中调用类和函数并对其进行测试?
You can only link to another project if that project is build as a library.如果该项目是作为库构建的,则只能链接到另一个项目。 Your project is currently build as an application, so you cannot do this, unless you reorganize your project into a library and an application.
您的项目当前构建为应用程序,因此您不能这样做,除非您将项目重新组织为库和应用程序。
If you do not want to this, you can also add the sources files you want to test to your test project.如果您不想这样做,您还可以将要测试的源文件添加到您的测试项目中。 Do not copy the files but reference the existing files in the unit test project.
不要复制文件,而是引用单元测试项目中的现有文件。
Right click on "Header files" or "Source files" of your test project in the Solution Explorer, then "Add", "Existing item...".在解决方案资源管理器中右键单击测试项目的“头文件”或“源文件”,然后单击“添加”、“现有项目...”。 Now these sources files will also by compiled and linked when building your test project.
现在,这些源文件也将在构建您的测试项目时进行编译和链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.