简体   繁体   English

无法在同一解决方案中的 2 个项目之间链接,并且我没有用于其他依赖项的 .Lib 文件

[英]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.

相关问题 同一解决方案中项目之间的链接问题(Exe依赖于Lib) - Link problem between projects in same solution (Exe depends on Lib) 如何在同一解决方案中的项目之间共享变量? - How to share variable between projects in the same solution? 在同一解决方案中的项目之间传递CString - Passing CStrings between projects in same solution LNK1104:无法打开文件'libboost_date_time-vc110-mt-gd-1_51.lib'; 文件甚至不包含在依赖项或其他lib目录中 - LNK1104: cannot open file 'libboost_date_time-vc110-mt-gd-1_51.lib' ; File is not even included in dependencies or additional lib directories 如何链接到同一VC ++ 2010解决方案中项目产生的.lib - How to link to .lib produced by project in same VC++ 2010 solution 无法为 clang 指定额外的链接文件 - Cannot specify additional link file for clang 同一解决方案中不同项目之间的引用(Visual Studio 2012) - Reference between different projects in the same solution (Visual Studio 2012) 无法使用MSVC链接到Boost库:无法打开文件* .lib - Cannot link to Boost library with MSVC: Cannot open file *.lib 升级到VS10后无法链接到lib文件 - Cannot link to lib file after upgrading to VS10 我实际上是否必须链接Ws2_32.lib? - Do I actually have to link Ws2_32.lib?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM