templates are supposed to be all in the header. Doing otherwise .. yea, you can often get it working (esp small programs), but it can also cause weird errors.
Does it work if you move it to the H file? That should, in < 5 min, tell you whether that is the issue or not...
@jonnin:
I cannot easily put my code into the header as this is the header I'm publishing with my lib.
I'm using PIMPL to keep my header completely clean.
> Yes it compiles when I put everything in my header but unfortunately this is not the solution I'm looking for.
@MikeyBoy:
I will prepare something and post it asap.
> Maybe it's worth mentioning, that the lib it self is compiling without any problem.
> It's the the app, that uses this lib which gets the LNK-Error (main.cpp)
Can't reproduce your problem. The following worked fine from the Windows command line with both g++ main.cpp netlibc.cpp
and cl /EHsc main.cpp netlibc.cpp
main.cpp
1 2 3 4 5 6 7 8 9
#include "netlibc.h" // <=== I presume you included this?
int main(int argc, char *argv[])
{
NetLibC lib;
NDataObjectTx<int> *dob;
lib.addDataObject(&dob);
}
That's kind of the point of templates. They are not exported they are compiled into your program.
When a function template is instantiated, it produces a function, which can be exported:
D:\explicit_inst_decl>dumpbin netlibc.dll /EXPORTS /NOLOGO
Dump of file netlibc.dll
File Type: DLL
Section contains the following exports for netlibc.dll
00000000 characteristics
FFFFFFFF time date stamp
0.00 version
1 ordinal base
3 number of functions
3 number of names
ordinal hint RVA name
1 0 000019C0 ??$addDataObject@H@NetLibC@@QEAA_NPEAPEAV?$NDataObjectTx@H@@@Z
2 1 000025E0 ??4NetLibC@@QEAAAEAV0@$$QEAV0@@Z
3 2 000025E0 ??4NetLibC@@QEAAAEAV0@AEBV0@@Z
Summary
3000 .data
3000 .pdata
12000 .rdata
1000 .reloc
22000 .text
1000 _RDATA
D:\explicit_inst_decl>