API.h (in dll & in the test.exe)
class Math
{
public:
// Pi || π = 3.14159265358979
static __declspec(dllexport) double Pi;
// Returns the square root of a specified number.
static __declspec(dllexport) double sqrt(double value);
// Returns the cube root of a specified number.
static __declspec(dllexport) double cbrt(double value);
};
API.cpp (in the dll)
#include <iostream>
#include <math.h>
double Math::Pi = 3.14159265358979;
double Math::sqrt(double value)
{
double root = std::sqrt(value);
return root;
}
double Math::cbrt(double value)
{
double root = std::cbrt(value)
return root;
}
Test.CPP
#include <iostream>
#include "API.h"
#pragma comment(lib, "test.lib") //for test.dll
using namespace std;
int main()
{
cout << Math::cbrt(125); //works fine
cout << Math::Pi; // Error 1 error LNK2001:
getchar();
}
Error 1 error LNK2001: unresolved external symbol "public: static double Math::Pi" (?Pi@Math@@2NA)
Aucun commentaire:
Enregistrer un commentaire