Linking a static library to a dynamic library

Hi,

I'm working on a pet project which dynamically loads several dlls. One of the dll in turn has to be linked to a static libarary but i am getting the following unresolved external symbol errors and i can't figure out why.

error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Poco::DateTime::~DateTime(void)" (__imp_??1DateTime@Poco@@QAE@XZ) referenced in function "public: bool __thiscall AISMTPConnection::Process(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?Process@AISMTPConnection@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)

Any help is appreciated.
To rephrase, the linker can't find:
Poco::DateTime::~DateTime()

which was called from function:
bool AISMTPConnection::Process(const std::string&);

It's more a dependency problem. The library that contains class AISMTPConnection should depend on (link to) the library that contains Poco::DateTime.
Exactly,

The linker finds the static library, but cannot import the the symbols exported from it and into the dynamic library.

Poco::DateTime::~DateTime() this is in PocoFoundation.lib

which I want for the dll to see.

I'm gonna set up a small experiment to find out if this is at all possible.
Last edited on
error LNK2019: unresolved external symbol __imp__staticLibFunc referenced in function _dynamicLibFunc

Its the same result.

staticLib.lib is composed of:
staticLib.h
1
2
3
4
5
6
7
8
9
10
#ifdef STDLLIMPORT
#define STDECLDIR __declspec(dllimport)
#else
#define STDECLDIR __declspec(dllexport)
#endif

extern "C"
{
	STDECLDIR char* staticLibFunc();
}


staticLib.cpp
1
2
3
4
5
6
#include "staticLib.h"

STDECLDIR char* staticLibFunc()
{
	return "static lib Func";
}



dynamicLib.dll is composed of:
dynamicLib.h
1
2
3
4
5
6
7
8
9
10
#ifdef DYDLLIMPORT
#define DYDECLDIR __declspec(dllimport)
#else
#define DYDECLDIR __declspec(dllexport)
#endif

extern "C"
{
	DYDECLDIR char* dynamicLibFunc();
}


dynamicLib.cpp
1
2
3
4
5
6
7
8
9
10
11
#include "dynamicLib.h"
#define STDLLIMPORT
#include "staticLib.h"

extern "C"
{
	DYDECLDIR char* dynamicLibFunc()
	{
		return staticLibFunc();
	}
}
Last edited on
Got it. You cannot import anything into a library, you can only export.

In the file
dynamicLib.cpp
theres a slight change.
1
2
3
4
5
6
7
8
9
10
11
#include "dynamicLib.h"
//#define STDLLIMPORT //this is not required when you are importing into a library.
#include "staticLib.h"

extern "C"
{
	DYDECLDIR char* dynamicLibFunc()
	{
		return staticLibFunc();
	}
}
In Windows, a DLL can use stuff defined in another DLL, in which case, it does import it. The user of the DLL doesn't need to know about the library's dependcies.

Unix is different, libraries can be built without resolving the external references. When the hosting application is linked, it must state all dependent libraries.
I was building this on windows platform using C++ Express Edition 2008.
Topic archived. No new replies allowed.