I'm writing some utils functions to my project. I got a strange LNK2019 error when I tried to use some functions from nested namespace. I tried to search in google and in stackoverflow but I didn't get something to help me.
My files
Header file X.h
:
#pragma once
namespace A {
namespace B {
/**
* A função recebe edValue e devolve em ponto flutuante
* o inteiro mais próximo de edValue.
*
* Método usado: http://en.wikipedia.org/wiki/Directed_rounding#Round_half_up
*
* @param edValue valor que será arredondado.
* @return o inteiro mais próximo à edValue (em ponto flutuante).
*/
double round(double edValue);
}
}
CPP file X.cpp
#include "StdAfx.h"
#include "X.h"
#include <cmath>
double A::B::round(double edValue)
{
return floor(edValue + 0.5);
}
Error message
7>D.obj : error LNK2019: unresolved external symbol "double __cdecl A::B::round(double)" (?round@A@B@@YANN@Z) referenced in function "public: void __thiscall
Edit (solution to my problem)
My files X.{h,cpp}
are in project A and Im using those functions in project B. If I use __declspec(dllexport)
in my function's prototype I can use those functions in project B, cause it uses A like DLL. I got this tip in How to use functions from different C++ projects in Visual Studio 2010? (replied by @Luchian Grigore) and Visual studio: question about linking functions between two projects (replied by @dascandy).