H
HiddenHandX
Guest
// MathLibrary.h - Contains declaration of Function class
#pragma once
#ifdef MATHLIBRARY_EXPORTS
#define MATHLIBRARY_API __declspec(dllexport)
#else
#define MATHLIBRARY_API __declspec(dllimport)
#endif
#ifndef MathLib
#define MathLib
namespace MathLibrary
{
// This class is exported from the MathLibrary.dll
class Functions
{
public:
MATHLIBRARY_API Functions();
// Returns a + b
static MATHLIBRARY_API double Add(double a, double b);
// Returns a * b
static MATHLIBRARY_API double Multiply(double a, double b);
// Returns a + (a * b)
static MATHLIBRARY_API double AddMultiply(double a, double b);
MATHLIBRARY_API int wLib();
int woLib();
};
}
#endif
// MathLibrary.cpp : Defines the exported functions for the DLL application.
// Compile by using: cl /EHsc /DMATHLIBRARY_EXPORTS /LD MathLibrary.cpp
#include "stdafx.h"
#include "MathLibrary.h"
#ifndef MathLib
#define MathLib
namespace MathLibrary
{
class Functions {
public Functions() {}
static double Add(double a, double b)
{
return a + b;
}
static double Multiply(double a, double b)
{
return a * b;
}
static double AddMultiply(double a, double b)
{
return a + (a * b);
}
int wLib() {
return 3;
}
int woLib() {
return 2;
}
};
}
#endif
Unable to instantiate class.
// Application.cpp : Defines the entry point for the console application.
// Compile by using: cl /EHsc /link MathLibrary.lib MathClient.cpp
#include "stdafx.h"
#include <iostream>
#include "MathLibrary.h"
using namespace std;
int main()
{
double a = 7.4;
int b = 99;
cout << "a + b = " <<
MathLibrary::Functions::Add(a, b) << endl;
cout << "a * b = " <<
MathLibrary::Functions::Multiply(a, b) << endl;
cout << "a + (a * b) = " <<
MathLibrary::Functions::AddMultiply(a, b) << endl;
MathLibrary::Functions *ptr = new MathLibrary::Functions();
//cout << "wLib: " << ptr->wLib() << endl;
//cout << "woLib: " << ptr->woLib() << endl;
return 0;
}
Returns the error
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall MathLibrary::Functions::Functions(void)" (__imp_??0Functions@MathLibrary@@QAE@XZ) referenced in function _main Application C:\...\Application.obj 1
Error LNK1120 1 unresolved externals Application C:\...\Debug\Application.exe 1
Why? How to fix it?
Continue reading...
#pragma once
#ifdef MATHLIBRARY_EXPORTS
#define MATHLIBRARY_API __declspec(dllexport)
#else
#define MATHLIBRARY_API __declspec(dllimport)
#endif
#ifndef MathLib
#define MathLib
namespace MathLibrary
{
// This class is exported from the MathLibrary.dll
class Functions
{
public:
MATHLIBRARY_API Functions();
// Returns a + b
static MATHLIBRARY_API double Add(double a, double b);
// Returns a * b
static MATHLIBRARY_API double Multiply(double a, double b);
// Returns a + (a * b)
static MATHLIBRARY_API double AddMultiply(double a, double b);
MATHLIBRARY_API int wLib();
int woLib();
};
}
#endif
// MathLibrary.cpp : Defines the exported functions for the DLL application.
// Compile by using: cl /EHsc /DMATHLIBRARY_EXPORTS /LD MathLibrary.cpp
#include "stdafx.h"
#include "MathLibrary.h"
#ifndef MathLib
#define MathLib
namespace MathLibrary
{
class Functions {
public Functions() {}
static double Add(double a, double b)
{
return a + b;
}
static double Multiply(double a, double b)
{
return a * b;
}
static double AddMultiply(double a, double b)
{
return a + (a * b);
}
int wLib() {
return 3;
}
int woLib() {
return 2;
}
};
}
#endif
Unable to instantiate class.
// Application.cpp : Defines the entry point for the console application.
// Compile by using: cl /EHsc /link MathLibrary.lib MathClient.cpp
#include "stdafx.h"
#include <iostream>
#include "MathLibrary.h"
using namespace std;
int main()
{
double a = 7.4;
int b = 99;
cout << "a + b = " <<
MathLibrary::Functions::Add(a, b) << endl;
cout << "a * b = " <<
MathLibrary::Functions::Multiply(a, b) << endl;
cout << "a + (a * b) = " <<
MathLibrary::Functions::AddMultiply(a, b) << endl;
MathLibrary::Functions *ptr = new MathLibrary::Functions();
//cout << "wLib: " << ptr->wLib() << endl;
//cout << "woLib: " << ptr->woLib() << endl;
return 0;
}
Returns the error
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall MathLibrary::Functions::Functions(void)" (__imp_??0Functions@MathLibrary@@QAE@XZ) referenced in function _main Application C:\...\Application.obj 1
Error LNK1120 1 unresolved externals Application C:\...\Debug\Application.exe 1
Why? How to fix it?
Continue reading...