tags:

views:

243

answers:

2

I use __declspec(dllexport) with several methods in a library. But one of the symbols do not get exported properly. The value in question is called "restart". I've given the output from dumpbin.exe, below:

1    0 0002DB27 ev_err = @ILT+2850(_ev_err)
          2    1 0002DADC m_foutput = @ILT+2775(_m_foutput)
          3    2 0002D361 m_free = @ILT+860(_m_free)
          4    3 0002D505 m_free_vars = @ILT+1280(_m_free_vars)
          5    4 0002D055 m_get = @ILT+80(_m_get)
          6    5 0002D95B m_ident = @ILT+2390(_m_ident)
          7    6 0002D80C m_inverse = @ILT+2055(_m_inverse)
          8    7 0002D0F5 m_mlt = @ILT+240(_m_mlt)
          9    8 0002D339 m_ones = @ILT+820(_m_ones)
         10    9 0002D43D m_rand = @ILT+1080(_m_rand)
         11    A 0002DC3F m_resize = @ILT+3130(_m_resize)
         12    B 0002D465 m_zero = @ILT+1120(_m_zero)
         13    C 0002D3A7 px_foutput = @ILT+930(_px_foutput)
         14    D 0002DA2D px_free = @ILT+2600(_px_free)
         15    E 00092DE0 restart = _restart
         16    F 0002DB45 set_err_flag = @ILT+2880(_set_err_flag)
         17   10 0002D550 v_foutput = @ILT+1355(_v_foutput)
         18   11 0002D839 v_free = @ILT+2100(_v_free)

This seems to indicate that restart did not get exported properly but I can't figure out why.

I use the following line to export the variable:

extern  __declspec(dllexport) jmp_buf   restart;

What is the reason for this anomaly and how can I resolve it?

A: 

You must have the dllexport attribute on the definition and the declaration. The definition is the source file where you have "restart" defined without the "extern" keyword.

janm
This gives the error "error C2370: 'restart' : redefinition; different storage class".
Gayan
Sorry, the definition and the declaration must match. Wording improved.
janm
Fixes the error in the previous comment but the symbol is still not being exported. I get linking errors for "restart" when I try to use it.
Gayan
How do you try to use it? Do you declare with __declspec(dllimport)?The advice from nobugz to just do it differently is also good.
janm
+2  A: 

It is because your "restart" identifier is data, not code. It probably should have been named "restart_state". Exporting data from a DLL is a supported scenario but a good way to blow your foot off. The client code has to have strict binary compatibility with the DLL code. That's a very questionable proposition for setjmp(), the saved state is highly implementation dependent.

You are much better off exporting functions that make the setjmp() and longjmp() calls and keep the jmp_buf private.

Hans Passant
Actually I do not make direct use of this symbol. I only tried to export it because one of the binaries (another dll) which links to this, gave an undefined symbol error at compile time. I think it's being used indirectly via another method. There's a definition for "catch"(!!) which raises this error if used in my source. I can't figure out the exact mechanics but I was able to get my code to compile by removing all uses of this method.
Gayan