Search code examples
c++cmanifestexe

Ho can I get rid of *.exe.manifest files form the MSVC compiled exe files?


I beg my apologies beforehand before asking some silly questions,
but I searched the web at my capacity but not found any answer that works in my case.
My question is:
How can I get rid of the embarrassing *.exe.manifest associated with the *.exe,
when codes compiled with MS Visual Studio 2008 from a bakefile generated makefile?

First I created a bakefile as follows:

<?xml version="1.0" ?>
<!--
===========================================
Plain EXE
===========================================
-->
<makefile>


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

<!-- HERE OUR PROJECT GOES -->
<exe id="MyApplication">
  <app-type> console </app-type>
  <!-- Compiler Specific -->
  <cflags>/TC /W4 /Za </cflags> <!-- Compile code as C. /TP , as C++
  /Tc <source file> means this file is C only, /Tp means this file is C++ only.
  /O1 minimize space, /O2 maximize speed, /Os favor code space, /Ot favor code speed.
  /Wall enable all warnings (gives warning on own headers like stdio.h).
  /Wp64 enable 64 bit porting warnings (will be deprecated in future). 
  /Za disable extensions, can be used with plain console apps but not with gui apps. -->

    <!-- <define>SOMEMACRO</define> -->
    <!-- <define>_OPENGLUT_STATIC</define> --> <!-- use underscore '_' before macro -->
    <!-- <include>../include/foo</include> -->
    <!-- <include>C:\xtralibs\appu</include> -->
    <!-- <include>C:\xtralibs\OpenGLUT-0.6.3vc</include> -->
    <!-- <headers>utils.h additionalheader.h</headers> -->

       <sys-lib> user32.lib kernel32.lib shell32.lib gdi32.lib comctl32.lib ole32.lib
         winmm </sys-lib> <!-- OpenGLUT_static.lib OpenGLUT.lib glu32.lib opengl32.lib -->
    <!-- <sys-lib>png</sys-lib> -->
    <!-- <sys-lib>OpenGLUT</sys-lib> -->
    <!-- <sys-lib>z</sys-lib> -->
    <!-- <lib-path>/usr/lib/mysql</lib-path> -->
    <!-- <lib-path>C:\xtralibs\OpenGLUT-0.6.3vc</lib-path> -->
                     <!-- note that hardcoding library paths like this is a bad
       idea, it's done here only for the sake of simplicity;
       in real bakefile, an <option> would be used -->
       <!--<library>mylib</library> -->
       <ldflags> /ENTRY:"mainCRTStartup"</ldflags> <!-- required for gui apps only,
       >can be used with console apps also -->

  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

  <!-- ~~~~~~~~ Compiler Specific definition Ends ~~~~~~~~~~ -->

    <!-- COMMON -->
    <!-- <win32-res> resource.rc </win32-res> -->
    <sources> test.c </sources>

</exe>
<!-- HERE OUR PROJECT ENDS -->

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</makefile>

Then I created a batch file as:

bakefile -f msvc -o Makefile.mak testing.bkl

call "%programfiles%\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
nmake -f Makefile.mak
cmd

After that a Makefile was created as:

# =========================================================================
#     This makefile was generated by
#     Bakefile 0.2.9 (http://www.bakefile.org)
#     Do not modify, all changes will be overwritten!
# =========================================================================



# -------------------------------------------------------------------------
# These are configurable options:
# -------------------------------------------------------------------------

# C compiler 
CC = cl

# Standard flags for CC 
CFLAGS = 

# Standard preprocessor flags (common for CC and CXX) 
CPPFLAGS = 

# Standard linker flags 
LDFLAGS = 



# -------------------------------------------------------------------------
# Do not modify the rest of this file!
# -------------------------------------------------------------------------

### Variables: ###

MYAPPLICATION_CFLAGS = /MD /DWIN32 /D_CONSOLE /TC /W4 /Za $(CPPFLAGS) $(CFLAGS)
MYAPPLICATION_OBJECTS =  \
  MyApplication_test.obj

### Conditionally set variables: ###



### Targets: ###

all: MyApplication.exe

clean: 
  -if exist .\*.obj del .\*.obj
    -if exist .\*.res del .\*.res
  -if exist .\*.pch del .\*.pch
  -if exist MyApplication.exe del MyApplication.exe
  -if exist MyApplication.ilk del MyApplication.ilk
  -if exist MyApplication.pdb del MyApplication.pdb

  MyApplication.exe: $(MYAPPLICATION_OBJECTS)
   link /NOLOGO /OUT:$@  /SUBSYSTEM:CONSOLE /ENTRY:"mainCRTStartup" $(LDFLAGS) @<<
  $(MYAPPLICATION_OBJECTS)   user32.lib kernel32.lib shell32.lib gdi32.lib comctl32.lib ole32.lib
  winmm.lib
 <<

 MyApplication_test.obj: .\test.c
  $(CC) /c /nologo /TC /Fo$@ $(MYAPPLICATION_CFLAGS) .\test.c

Finally my code compiled with Visual Studio 2008.
Up-to this everything was fine.
Now the main problem comes.
Visual Studio creates a manifest file which is actually a plain xml file.
When I delete the manifest, my exe does not run.

  • Can I manage to create the bakefile in such a way so that the compiled exe would never require the manifest?

    I mean some compiler/linker flags I would like to add to solve this, but I don't know this flag.

I'm eagerly waiting for your help.


Solution

  • I found the way to solve this. Bakefile already has a xml-tag called

    <postlink-command></postlink-command>
    

    where we can run mt.exe to embed the manifest and finally delete the manifest.

    The C code is:

    /* main.c */
    #include <errno.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void) {
     printf("Hello world!\n");
     system ("PAUSE");
     return 0;
    }
    

    The bakefile is (plain_exe.bkl):

    <?xml version="1.0" ?>
    <!--
    ===========================================
    A SIMPLE EXE
    ===========================================
    -->
    <makefile>
       <exe id="hello">
           <sources> main.c </sources>
           <sys-lib> user32.lib kernel32.lib shell32 </sys-lib>
           <pic>on</pic>
           <postlink-command> mt.exe -manifest $(id).exe.manifest -outputresource:$(id).exe;1
           <postlink-command> del $(id).exe.manifest </postlink-command>
       </exe>
    </makefile>
    

    The batch is (genbake.bat):

    bakefile -f msvc plain_exe.bkl -o Makefile.mak
    call C:\PROGRA~1\MICROS~1.0\VC\vcvarsall.bat
    nmake -f Makefile.mak
    cmd
    

    Trigger the batch to build everything.