I would like to build two C++ projects in the same solution in Visual Studio 2010 that can interact with each other. I have created a solution under directory C:\Users\me\Desktop\SolutionDir
. The two projects have been created respectively under C:\Users\me\Desktop\SolutionDir\FirstProject
and C:\Users\me\Desktop\SolutionDir\SecondProject
.
My first project contains two files, a header function.h
and a cpp file function.cpp
#pragma once
void print_stuff();
#include "function.h"
#include <iostream>
void print_stuff() {
std::cout << "hello world" << std::endl;
}
My second project contains the main file main.cpp
#include "FirstProject\function.h"
#include <iostream>
int main(void) {
print_stuff();
int stop;
std::cin >> stop;
return 0;
}
I added the directory C:\Users\me\Desktop\SolutionDir\
in my SecondProject Configuration Properties > C/C++ > General > Additional Include Directories
. I still get the classical error : error LNK2019: unresolved external symbol
when calling the function print_stuff()
.
Any ideas ?
Try building the first project as a Static Library in Project Properties/Configuration Properties/General/Configuration Type.
Then in your project properties for the second project, you'll need to change two things:
.lib
is built..lib
file like FirstProject.lib
or whatever its name is.