1

I have been googling for days now, and I cant seem to wrap my head around this problem.

I have a header, which exports some functions to a library. This file is called test_extern.h, and the function looks like this:

__declspec(dllexport) int aFunction(int a, int b);

I have two other files, one .h and .cpp which calculates some things with the help of the exported file. I have stripped down the versions to show what I want to do.

A.h file:

// Include CBaseDILI_J1939 header file.
class A : public CBaseDILI_J1939
{
public:
  int bFunction(int a, int b);
}

A.cpp file:

#include "test_extern.h"
#include "A.h"

int A::bFunction(int a, int b) {
  return aFunction(a, b);  // REturn the value of the exported function!
}

Now when I run this, I get "error LNK2019: unresolved external symbol _imp_aFunction".

I have read and read all there is about exporting dll's, is there anyone who knows what I might be doing wrong?

Charles
  • 50,943
  • 13
  • 104
  • 142
Pphoenix
  • 1,423
  • 1
  • 15
  • 37
  • What library file(s) are you specifying when you run the linker? – Jerry Coffin Aug 07 '13 at 14:31
  • I dont add anything extra to the linker. Do I have to do that? I just supposed that the linker would find it – Pphoenix Aug 07 '13 at 14:39
  • So, is A in a different project to aFunction? In that case the declaration from the header isn't enough. Do you have a lib from the dll or not? – doctorlove Aug 07 '13 at 14:46
  • @Karadur solved it! I had forgotten to import the functions before I used them. Easy fix, but oh so hard to find when you've been staring at the code for hours ;) – Pphoenix Aug 07 '13 at 14:51
  • @JerryCoffin You were right. I had too specify the .lib file when I rebuilded the solution, or the linker wouldn't find my functions. – Pphoenix Aug 08 '13 at 07:56

2 Answers2

2

You have to declare the dll function in the calling module as dllspec(dllimport).

Karadur
  • 1,226
  • 9
  • 16
2

@Karadur is right.

Check the example on this link: http://msdn.microsoft.com/en-us/library/799kze2z.aspx. The answer is on the bottom of this page.

In A.cpp add this on top.

__declspec(dllimport) int aFunction(int a, int b);

ipinak
  • 5,739
  • 3
  • 23
  • 41
  • Do not forget to check msdn, you will find a lot of helpful posts for windows development. Despite the fact I don't like MS and that I don't develop a lot on their platforms. Their support is by far one of the best... – ipinak Aug 07 '13 at 14:51