c++ - export static member for another dll -
i have dll exports functions second dll can use them. both dll's loaded main. have problem exporting data member inside dll.
i have template class looking (temp.hpp):
template<typename t> class __declspec(dllexport) base { public: static t buf; static void do_smt(t val); }; template<typename t> void base<t>::do_smt(t val) { base<t>::buf = val; }
then second class inheriting template class (dll.h). header shared between 2 dll's.
#include "temp.hpp" class __declspec(dllexport) child : public base <int> {};
and dll.cpp looks like:
#include "dll.h" base<int> inter; int base<int>::buf;
there more other function, tried reduce down basics.
this compiles , creates .lib , .dll. have project compiled .lib. main loading both dll's, second dll use do_smt
(which working if remove static int buf
). error buf unresolved.
error 1 error lnk2001: unresolved external symbol "public: static int base<struct int>::buf" (?buf@?$base@uint@@@@2ha) module.obj
i tried that
template <class t> int base<t>::buf; int base<int>::buf;
but got same error.
everything working without static buf.
how can make buf static buf exported in dll.cpp (dll.dll) other dll's use static do_smt method?
i'm using vs2012.
edit:
dumpbin /exports dll.dll returns:
file type: dll section contains following exports dll.dll 00000000 characteristics 520d5353 time date stamp fri aug 16 00:16:51 2013 0.00 version 1 ordinal base 5 number of functions 5 number of names ordinal hint rva name 1 0 000613e9 ??4?$base@uint@@@@qaeaav0@abv0@@z = @ilt+17380(??4?$base@uint@@@@qaeaav0@abv0@@z) 2 1 0005f2bf ??4child@@qaeaav0@abv0@@z = @ilt+8890(??4child@@qaeaav0@abv0@@z) 3 2 0014f594 ?buf@?$base@uint@@@@2ha = ?buf@?$base@uint@@@@2ha (public: static int base<int>::buf) 4 3 0005d90b ?getdlldllinit@@yajpaupluginheader@@@z = @ilt+2310(?getdlldllinit@@yajpaupluginheader@@@z) 5 4 0005f0bc dlldll = @ilt+8375(_dlldll) summary 4000 .data 4000 .idata 29000 .rdata 9000 .reloc 1000 .rsrc c6000 .text 5c000 .textbss 1000 .tls
seems buf inside dll.
edit 2:
the main not written me , don't have code. main not loading dll.dll. loading library loadlibrary checking information (by getdlldllinit (maybe bad named)) , unload again. dll.dll in root directory of exe. loaded automatically windows if necessary (if access functions). other dll's specific loaded .exe using loadlibrary.
my first try without classes or templates, gobal functions , worked. after, i've created template class putting functions in. reason is, dll.dll reused other type's, don't have rewrite (just change inheritance class __declspec(dllexport) child: public base <some_other_type> {};
, redefine statics...) rewrite again , again violate against dry principle.
edit 3:
after willj adviced me try without template, find out new. problem while method inside header , not inside cpp. if rewrite template
template<typename t> class __declspec(dllexport) base {...};
to
class __declspec(dllexport) baseint {...};
it still won't work, if seperate methods header , move them in cpp (in case it's more important move base::buf
cpp) work. think problem is, if base::buf member right compiled dll.dll, other project can't find definition during compile time defined in lib. don't know if bug in msvc or it's correct behaviour. though inheriting base specific type it.
since want use template , 1 (global) header i'm start thinking problem may unresolveable.
edit 4:
comands:
- compile
/fr"debug\" /gs /analyze- /w3 /zc:wchar_t /i"my include path's" /zi /gm- /od /fd"debug\vc110.pdb" /fp:precise /d "win32" /d "_windows" /d "_win32_windows=0x0501" /d "_debug" /d "_usrdll" /d "nominmax" /d "_crt_secure_no_warnings" /d "_windll" /errorreport:prompt /wx- /zc:forscope /rtc1 /gd /oy- /mdd /fa"debug\" /ehsc /nologo /fo"debug\" /fp"debug\test.pch"
- link
/out:"debug\test.dll" /manifest /pdb:"debug\test.pdb" /dynamicbase:no "dll.lib" "winmm.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /implib:"debug\test.lib" /debug /dll /machine:x86 /safeseh /incremental /pgd:"debug\test.pgd" /subsystem:windows /manifestuac:"level='asinvoker' uiaccess='false'" /manifestfile:"debug\test.dll.intermediate.manifest" /errorreport:prompt /nologo /libpath:"d:/prg/svn/branches/dll/debug" /libpath:"d:\prg\svn\trunk\libs\boost\1.53.0\lib\msvc-32bit" /tlbid:1
Comments
Post a Comment