How to prevent linker from "not creating" only a single unreferenced variable?

  • Thread starter Thread starter George912
  • Start date Start date
G

George912

Guest
I need it to allocate memory for a newly created section, but this doesn't work unless the memory is referenced in any way:


#pragma section(".sec", read, write)

__declspec(allocate(".sec")) Byte newSectionAllocatedMemory[0x500];

/*
The section doesn't get created unless the newSectionAllocatedMemory is referenced like this:

newSectionAllocatedMemory[0] = 0;

It's not clean solution, though.
*/


I've also seen "/OPT:NOREF" linker option, however I'm not sure whether it's going to work for only one variable if used like this:


#pragma section(".sec", read, write)

#pragma comment(linker, "/OPT:NOREF")

__declspec(allocate(".sec")) Byte newSectionAllocatedMemory[0x500];

#pragma comment(linker, "/OPT:REF")


I think it won't work and either "/OPT:REF" will remain or "/OPT:NOREF" will work, but for all the variables/functions (I'd like it to include only the newSectionAllocatedMemory variable).

Also it doesn't even work at all for me and each of these directives causes the following linker warnings:



main.obj : warning LNK4229: invalid directive „/OPT:NOREF” encountered; ignored

main.obj : warning LNK4229: invalid directive „/OPT:REF” encountered; ignored




Have you any idea how to achieve that (if it's even possible)?

Continue reading...
 
Back
Top