Click here to Skip to main content
15,879,844 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I'm unable to access some const objects from a DLL despite the fact that they are exported and other items from the DLL, functions and classes are importing correctly.

Is their some rule against this or am I just being thick again and not spotting the obvious mistake?

//DLL header
extern __QOR_INTERFACE( __ARCHQOR ) const CGPReg eax;

//DLL cpp
__QOR_INTERFACE( __ARCHQOR ) const CGPReg eax( nsCodeQOR::_Initialize(), REG_EAX );

In the debugger I can hit the line above proving that eax gets initialised on load of the DLL.

Depends shows the export


at ordinal 1003 but building the exe which imports the symbol gives the error:

TestArchQOR.obj : error LNK2001: unresolved external symbol "class nsArch::nsx86::CGPReg const nsArch::nsx86::eax" (?eax@nsx86@nsArch@@3VCGPReg@12@B)

The nsArch::nsx86::CGPReg type is also exported and given that the export and the claimed missing import symbols match I am properly
nv3 13-Jun-13 16:29pm    
Sorry for the probably silly question, but have you specified the lib file in the linker inputs of your TestArchQOR project? Just asking to make sure you did. -- Ah, you said, other items of the DLL were imported correctly. So disregard my question.
Matthew Faithfull 13-Jun-13 16:36pm    
Good point but the answer is yes.
There are plenty of imports working for example the dword_ptr function was the last thing I fixed, a header inline that was using a function I'd forgotten to import/export.
__QOR_INTERFACE( __ARCHQOR ) CMem _MemPtrBuild( const CGPReg& base, Cmp_int_ptr disp, Cmp_unsigned__int32 ptrSize ) __QCMP_THROW;

Given that this fix worked I know that build is not an issue, everything is in the right place and any changes I make will affect the build outcome.
nv3 13-Jun-13 16:39pm    
I have never tried to export a const object. What if you remove the const?
Matthew Faithfull 13-Jun-13 16:44pm    
I don't know. This is code I'm recycling so not mine originally. I don't know why const would be important in this case. I'll try removing it and see what happens...

...The good news is nothing further breaks but the bad news is that the linker error is still the same. constness is not the determining factor in this case.
zlogdan 13-Jun-13 16:59pm    
Although the DLL mechanism permits that we export C++ classes, I personally prefer to export ANSI C functions, although most of the DLL internals I write in C++. Not sure if this will fix your compilation problems though.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900