user1330092
user1330092

Reputation:

C++ DLL Export Error Linkage LNK2019

facing some issues here:

Waz is in a DLL named Test

Waz.h

// Import/Export Pattern
#ifdef TEST_EXPORTS
#define DllExport __declspec(dllexport) 
#else 
#define DllExport __declspec(dllimport) 
#endif

#pragma once
#ifndef __Test__Waz__
#define __Test__Waz__

#include "WazImpl.h"

class DllExport Waz
{
/* Friends */
friend class WazImpl;
friend Waz operator*(const Waz &,const Waz &);

private:

WazImpl *p;
...
public:
...
};

#endif /* defined(__Test__Waz__) */

Waz operator*(const Waz &,const Waz &);

-------

Waz.cpp
(all def of the operator in public and ...)
Waz operator*(const Waz & w1, const Waz & w2)
{
Waz ww;
*ww.p=*w1.p * *w2.p;
return ww;
}


Then in the solution I have a console application and in my main

int main()
{
Waz a;
a(1,1) =3 ; // this line works fine operator() is defined in the public of the Waz class
Waz b;
Waz c = a*b; // ERROR 

ERROR:
error LNK2019 : unresolved external symbol "class Waz __cdecl operator*(class Waz const &, class Waz const &)" (??D@YA?AVWaz@@ABV0@0@Z) referenced in the function _main
error LNK1120 : 1 unresolved external symbol

Based on the fact that a(1,1) works it means operators of the class are correctly exported and the problem only comes from the friend operator * ! Any idea? Don't know what to do anymore to solve this.. Thanks in advance!!

Upvotes: 0

Views: 656

Answers (1)

manuell
manuell

Reputation: 7620

The operator is declared outside the class, just export it, with:

DllExport Waz operator*(const Waz &,const Waz &);

Upvotes: 1

Related Questions