简体   繁体   中英

VC++ Multiple Project Solution

I am very new to C++ and I am attempting to setup multiple projects in the same solution in VS2013. Currently I have stepped back to a simpler example project to try to figure out my error.

Project 1:
Main.cpp

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

 using namespace std;

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

Project 2 Test.h

 #ifndef TEST_H
 #define TEST_H

 int _MOVEMENTSPEED();

 #endif

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".

UPDATE I tested this same code but within one project file in visual studio and it worked fine.

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"

  2. Export the function / class by using _ declspec(dllexport) and _declspec(dllimport)

  3. Include the .lib file properly in the project settings of Link tab.

  4. Set the project dependencies correctly.

The below links should help you:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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