I am just beginning to learn C++ and using Visual Studio 2017 as the IDE. I want to stay away from the CLR, and even Windows specific code as much as possible. Every new project option seems to say 'Windows', and thus suggest Windows OS dependencies, except for General > Empty Project, so that is the option I have chosen.
I am trying to write a static library with some functions. Here's a simple example of what I'm trying to do.
//Lib1.h (Project A)
#pragma once
#ifndef LIB_H
namespace Lib1
{
double Add(double, double);
}
//Lib1.cpp (Project A)
#include "Lib1.h"
namespace Lib1
{
double Add(double a, double b)
{
return a + b;
}
}
//Main.cpp (Project B)
#include "Lib1.h"
using namespace Lib1;
int main()
{
double c = Add(1, 2);
}
Project A compiles without warning/error. I changed the Project Properties > General > Configuration Type to be Static Library (.lib), but I cannot actually find the compiled .lib file in the project directory, just an .obj file.
When I try and build Project B it throws the following error message.
"LNK2019 unresolved external symbol "double __cdecl FrameTransformations::Add(double,double)" (?Add@FrameTransformations@@YANNN@Z) referenced in function _main FrameTransformationTests S:\Projects\Cpp\Code\FrameTransformations\FrameTransformationTests\Main.obj 1"
I've had a look and it seems that project B can't find the Add function from project A, although I get auto-completion for the function and arguments through Intellisense (is this just because it can find the Lib1.h file ok?).
I have tried adding in the path to the Project A folder in the Project B Properties > C/C++ > General > Additional #using Directories (both to the Project folder and to the Debug folder where I expected the Lib1.lib file to be generated), but that hasn't worked.
Can someone please point me to what I've done wrong, this has had me stumped for a couple of hours now.
Thank you.