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:
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"
Export the function / class by using _ declspec(dllexport) and _declspec(dllimport)
Include the .lib file properly in the project settings of Link tab.
Set the project dependencies correctly.
The below links should help you:
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.