I try to declare a shared data segment in a DLL. I declare the area with:
#pragma data_seg(".shared")
int varx=0;
#pragma data_seg()
__declspec(allocate(".s开发者_开发百科hared"))
// I found this declspec suggestion in another forum
#pragma comment (linker,"/section:.shared,RWS")
Also I add
SECTIONS
.shared READ WRITE SHARED
into the def file. However I always get:
LINK : warning LNK4039: section '.shared' specified with /SECTION option does not exist
error. If I do only one (.def or pragma comment) get only one, if do both get two errors.
Anything I miss?
Ive only seen that declspec used in this way:
__declspec(allocate(".shared")) int varx=0;
I would try writting only this:
#pragma comment (linker,"/section:.shared,RWS")
__declspec(allocate(".shared")) int varx=0;
avoiding declaring an empty section or a multiply defined one
To make it clear:
data_seg changes default section name in obj file where initialized to non-zero variables will go. So if you set varx = 1 this variable appeared in .shared section and will be shared across processes. I your case it didn't appeared there because of varx = 0.
Use #pragma section instead and specify the section to use when declaring your variable: __declspec(allocate(".shared")) int varx = 0.
Don't use data_seg keyword for your pupose. This will allow you NOT to share any other variables that initialized to non-zero :)
精彩评论