Using a VS macro to generate a .DEF file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Using a VS macro to generate a .DEF file

Hybrid View

  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,262

    Using a VS macro to generate a .DEF file

    I'm trying to build libglib using MSVC. libglib doesn't use dllexport - so to create usable DLLs it needs to generate a .DEF file. It does this by using a .symbols file. Here's a cut-down example:-

    Code:
    /* This file lists all exported symbols. It is used to generate
     * the glib.def file used to control exports on Windows.
     */
    
    /* glib.symbols */
    g_mkdir_with_parents
    
    #ifdef G_OS_WIN32
    g_file_get_contents_utf8
    #endif
    The following commands would produce the following files called glib.def

    Code:
    cl /EP glib.symbols > glib.def
    
    produces this in glib.def:-
    
    g_mkdir_with_parents
    Code:
    whereas this:-
    cl /EP -DG_OS_WIN32 glib.symbols > glib.def
    
    produces this in glib.def:-
    
    g_mkdir_with_parents
    g_file_get_contents_utf8
    So this is a handy way of producing conditional .DEF files. Fortunately, this can all be built into a Visual Studio macro in my vsprops file - e.g.

    Code:
    	<UserMacro
    		Name="GlibGenerateGlibDef"
    		Value="echo &gt;&quot;$(SolutionDir)\glib.def&quot; &amp;&amp; cl /EP -DG_OS_WIN32 glib.symbols &gt;&gt;&quot;$(SolutionDir)\glib.def&quot;"
    	/>
    Problem:- Although I can run the macro as a pre-build step (and it does produce conditional entries in the generated .DEF file) it DOESN'T produce the word EXPORTS at the top of the file. So the linker then fails to recognise it as a valid .DEF file.

    How can I add that word EXPORTS to the top of the generated file? I tried just adding EXPORTS to the top of the symbols file but that didn't work. I also tried this variation on the macro:-

    Code:
    		Name="GlibGenerateGlibDef"
    		Value="echo EXPORTS &gt;&quot;$(SolutionDir)\glib.def&quot; &amp;&amp; cl /EP -DG_OS_WIN32 glib.symbols
    but that didn't work either I feel sure there must be a way to do this.
    "A problem well stated is a problem half solved. - Charles F. Kettering

  2. #2
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,262

    Re: Using a VS macro to generate a .DEF file

    I figured it out. The trick is to split it into two pre-build steps, where the original macro looks like this:-

    Code:
    	<UserMacro
    		Name="GlibGenerateGlibDef"
    		Value="cl /EP -DG_OS_WIN32 glib.symbols >> &gt;&gt;&quot;$(SolutionDir)\glib.def&quot;"
    	/>
    and the two steps are these:-

    Code:
    echo EXPORTS > $(SolutionDir)\glib.def
    $(GlibGenerateGlibDef)
    "A problem well stated is a problem half solved. - Charles F. Kettering

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center