我怎么能摆脱*.exe.从MSVC编译的exe文件中获取manifest文件

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

本文关键字:文件 exe manifest 获取 编译 怎么能 MSVC      更新时间:2023-10-16

在问一些愚蠢的问题之前我先道歉,
但是我在网上搜索了我的能力,但没有找到任何适合我的答案。
我的问题是:
我怎样才能摆脱尴尬的*.exe。manifest相关联*.exe
当代码编译与MS Visual Studio 2008从一个bakefile生成makefile?


首先我创建了一个bakefile,如下所示:
<?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:xtralibsappu</include> -->
    <!-- <include>C:xtralibsOpenGLUT-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:xtralibsOpenGLUT-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>
然后我创建了一个批处理文件:

bakefile - fmsvc -o Makefile。mak testing.bkl

call "%programfiles%Microsoft Visual Studio 9.0VC vcvarsmall .bat"
nmake -f makefile . makk
cmd

之后一个Makefile被创建为:

# =========================================================================
#     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

最后用Visual Studio 2008编译了我的代码。在此之前,一切都很好。
现在主要问题来了。
Visual Studio创建一个清单文件,它实际上是一个纯xml文件。
当我删除清单时,我的exe不运行

  • 我能设法以这样一种方式创建bakefile,以便编译的exe永远不需要清单?

    我的意思是我想添加一些编译器/链接器标志来解决这个问题,但我不知道这个标志。


我找到了解决这个问题的方法。Bakefile已经有了一个名为

的xml标签
<postlink-command></postlink-command>

我们可以运行mt.exe来嵌入清单,最后删除清单。

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

bakefile是(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>

批处理是(genbaker .bat):

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