简体   繁体   English

VC ++多项目解决方案

[英]VC++ Multiple Project Solution

I am very new to C++ and I am attempting to setup multiple projects in the same solution in VS2013. 我是C ++的新手,我试图在VS2013中的同一解决方案中设置多个项目。 Currently I have stepped back to a simpler example project to try to figure out my error. 目前,我已退回到一个更简单的示例项目来尝试找出我的错误。

Project 1: 项目1:
Main.cpp Main.cpp的

 #include "Test.h"
 #include <iostream>

 using namespace std;

 int main() 
 {
     cout << _MOVEMENTSPEED();
     system("pause");
     return 0;
 }

Project 2 Test.h 项目2 Test.h

 #ifndef TEST_H
 #define TEST_H

 int _MOVEMENTSPEED();

 #endif

Test.cpp TEST.CPP

 #include "Test.h"

 int _MOVEMENTSPEED() 
 {
     return 10;
 }

Whenever I attempt to build this I get the error "error LNK2019: unresolved external symbol "int __cdecl _MOVEMENTSPEED(void)" (?_MOVEMENTSPEED@@YAHXZ) referenced in function _main c:\\Users\\Max\\documents\\visual studio 2013\\Projects\\Project1\\Project2\\Main.obj" and "Error 2 error LNK1120: 1 unresolved externals c:\\users\\max\\documents\\visual studio 2013\\Projects\\Project1\\Debug\\Internal". 每当我尝试构建此文件时,我都会收到错误_main c:\\ Users \\ Max \\ documents \\ visual studio 2013 \\ Projects中引用的错误“错误LNK2019:无法解析的外部符号“ int __cdecl _MOVEMENTSPEED(void)”(?_MOVEMENTSPEED @@ YAHXZ) \\ Project1 \\ Project2 \\ Main.obj”和“错误2错误LNK1120:1无法解析的外部c:\\ users \\ max \\ documents \\ visual studio 2013 \\ Projects \\ Project1 \\ Debug \\ Internal”。

UPDATE I tested this same code but within one project file in visual studio and it worked fine. 更新我测试了相同的代码,但在Visual Studio的一个项目文件中进行了测试,效果很好。

When you create multiple projects you should do the following: 创建多个项目时,应执行以下操作:

Make sure the following: 确保以下内容:

  1. Include the .h file properly from other project(Generally every project has its own directory), so you need to include the file like below: #include "..\\Test\\Test.h" 正确包含其他项目中的.h文件(通常每个项目都有其自己的目录),因此您需要包含以下文件: #include“ .. \\ Test \\ Test.h”

  2. Export the function / class by using _ declspec(dllexport) and 通过使用_ declspec(dllexport)导出函数/类, 然后 _declspec(dllimport) _declspec(dllimport的)

  3. Include the .lib file properly in the project settings of Link tab. 在链接选项卡的项目设置中正确包含.lib文件。

  4. Set the project dependencies correctly. 正确设置项目依赖项。

The below links should help you: 以下链接应为您提供帮助:

http://support.microsoft.com/kb/815650 http://support.microsoft.com/kb/815650

http://msdn.microsoft.com/en-us/library/799kze2z.aspx http://msdn.microsoft.com/en-us/library/799kze2z.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM