Creating a DLL

I am trying to create a DLL by following https://msdn.microsoft.com/en-us/library/ms235636.aspx

I am using VS 2013. Here's the CPP file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 #include "stdafx.h"
#include "MathFuncs.h"
#include <stdexcept>
#define MATHFUNCSDLL_EXPORTS
using namespace std;

namespace MathFuncs
{
	double MathFuncs::Add(double a, double b)
	{
		return a + b;
	}

	double MathFuncs::Subtract(double a, double b)
	{
		return a - b;
	}

	double MathFuncs::Multiply(double a, double b)
	{
		return a * b;
	}

	double MathFuncs::Divide(double a, double b)
	{
		if (b == 0)
		{
			throw invalid_argument("b cannot be zero!");
		}

		return a / b;
	}
}


And this is the header file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifdef MATHFUNCSDLL_EXPORTS
#define MATHFUNCSDLL_API __declspec(dllexport) 
#else
#define MATHFUNCSDLL_API __declspec(dllimport) 
#endif

namespace MathFuncs
{
	// This class is exported from the MathFuncsDll.dll
	class MathFuncs
	{
	public:
		// Returns a + b
		static MATHFUNCSDLL_API double Add(double a, double b);

		// Returns a - b
		static MATHFUNCSDLL_API double Subtract(double a, double b);

		// Returns a * b
		static MATHFUNCSDLL_API double Multiply(double a, double b);

		// Returns a / b
		// Throws const std::invalid_argument& if b is 0
		static MATHFUNCSDLL_API double Divide(double a, double b);
	};
}


BUT when I compile I get these errors:

Warning 1 warning C4273: 'MathFuncs::MathFuncs::Add' : inconsistent dll linkage M:\c++\dynamiclibrary\mathfunc3\mathfunc3.cpp

Any help is gratefully received. I've looked at books on line for C++ dll tutorials but have not found any.

RON


Topic archived. No new replies allowed.