Menu

#pragma data_seg("MY_SEG") in DevCpp?

Ron McHugh
2008-08-14
2012-09-26
  • Ron McHugh

    Ron McHugh - 2008-08-14

    I am building a dll with Dev-C++ 4.9.9.2 and my shared data segment is not being recognized.
    I have tried to use code MY_SEG READ WRITE SHARED[/code] in a .def file and pointed the linker at it and still not working.
    I look into the file created by dlltool and only my exports are listed.
    I have variables in my dll that MUST remain static for all instances used.
    If you have .def file sample for for this compiler, please post it here.
    Or if there is another way, i would like to also see it.
    I prefer to use .def files because if i add new services to the dll, older client apps can still import functions without having to be rebuilt.
    Ok, thanks for your time, and any response will be greatly appreciated.

     
    • BiT

      BiT - 2008-08-15

      //includes here

      //global vars here

      //pragma statement here

      pragma data_seg("MY_SEG")//begin shared data segment

      //what is shared here

      pragma data_seg() //end shared data segment

      pragma comment(linker, "/SECTION:MY_SEG,RWS")//tells linker to generate the shared data segment.

      //dll code here

       
      • cpns

        cpns - 2008-08-16

        Uh....

        As I said the required behaviour of a conforming compiler with respect to an unsupported #pragma is to ignore it. GCC will ignore that. http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Pragmas.html#Pragmas

         
    • cpns

      cpns - 2008-08-14

      and #pragma directive is by definition compiler specific, that is what #pragma is for. In general GCC doesn't not support many #pragma directives ( see http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Pragmas.html#Pragmas ). Moreover teh required behaviour of a conforming compiler with respect to an unsupported #pragma is to ignore it, so you may never know when it is not doing its job!

      In GCC to specify the segment location of a variable you must use the data attribute extension. For example:

      int MyData attribute ((section ("MY_SEG"))) = 0;

      See http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Variable-Attributes.html#Variable-Attributes for details.

      Clifford

       
    • Ron McHugh

      Ron McHugh - 2008-08-15

      So after using the attributes variable descriptor i will still need to point the linker at my .def file, right???

      In my .def file...
      SECTIONS
      MY_SEG READ WRITE SHARED
      EXPORTS
      DoSomething @1
      DoSomethingElse @2

      In the linker commands box...
      -def mydef.def

      Am i on the right track???

       
      • cpns

        cpns - 2008-08-15

        I have no idea. I simply gave you what I believe is the direct equivalent of Microsoft's #pragma data_seg directive, that's the extent of my knowledge on this. Sorry.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.