如何在Ubuntu16.04上编译vs2013工程为exe文件

      “在现在这种时间就是金钱的时代,程序需要自动化,程序需要自动化,程序需要自动化。”

      “自动化就是程序员的生产力。不要像码农一样,一辈子把自己的双手双脚绑在自己的一亩三分地上。”

                                                                                                                                --------  过客 曰

         

很久很久(大于等于8年)以前听说过wine这个软件,当时是在bgi想要在RedHat大型机上运行一个Windows下的生物信息分析软件。悲剧的是这个wine需要root权限,当时作为一只小菜鸟,运维部门果断拒绝了这个请求。时值今日,在工作中已经完全可以拥有单独的Linux机器,root权限神马的已经不再是问题。想装神马软件就装神马软件。

        前段时间遇到了一个需求,同一个软件需要同时发布Ubuntu、Arm64、Win32这3个版本。本质上就是用同一套代码,在3个不同的平台上编译出3个可执行文件。这第一个Ubuntu版本很简单,直接在linux docker上自动化编译+打包+测试。第2个arm64版本,虽然很少见,但是还是找到了可以在Linux-x64上运行的docker版本(https://hub.docker.com/r/multiarch/ubuntu-core/),只是需要花些时间折腾。最难的是第3个win32版本,以前是没办法,只能每次在Windows上用visual studio手动编译,然后再手动打包。软件小的话,还可以忍受一下,关键是我要编译九(注:这是一个虚数)个exe文件,换我纯是受不了。于是就想到wine这个软件了,网上搜了一下别人的安装方法,基本上都是在带有图形界面的Ubuntu上安装的。我现在的情况是,只能在Ubuntu Server上做开发。没办法,只能自己编译一个不带界面的wine版本。

一、在Ubuntu16.04 Server上,编译和安装wine

1. 先下载wine源代码 https://sourceforge.net/projects/wine/files/Source/wine-5.10.tar.xz/download

2. 因为编译的时候需要很多依赖包,我采用了一个比较取巧的办法,就是先在Ubuntu 16.04 Server上,用sudo apt-get install wine64先安装一遍已经编译好了的deb包,在安装的过程中,会自动安装相关的依赖包,等安装完后,因为没有图形界面,命令行运行wine64会各种报错,所以然后用sudo dpkg -P wine64卸载掉,卸载时不会卸载相关的依赖库。

3. 解压 xz -d wine-5.10.tar.xz,  tar xf wine-5.10.tar

4. cd wine-5.10

5. ./configure --prefix=/root/Packages/wine-5.10/build_x64 -enable-win64 --without-x

   如果需要win32版本,则用 ./configure --prefix=/root/Packages/wine-5.10/build_Win32 --without-x

  其中的--without-x表示编译的版本不支持X图形系统

6. make

7. make install

编译安装后,所有文件都会安装到 /root/Packages/wine-5.10/build_x64/ 目录下,其中 build_x64/bin/wine64 就是64位的wine在linux上的可执行文件,下面就先运行一下看看:

在命令行输入 build_x64/bin/wine64 cmd /c echo "Hello Wine64!"

root@pc:~/wine-5.10# build_x64/bin/wine64 cmd /c echo "Hello Wine64!"
wine: created the configuration directory '/root/.wine'
0048:err:ole:StdMarshalImpl_MarshalInterface Failed to create ifstub, hres=0x80004002
0048:err:ole:CoMarshalInterface Failed to marshal the interface {6d5140c1-7436-11ce-8034-00aa006009fa}, 80004002
0048:err:ole:get_local_server_stream Failed: 80004002
002c:err:winediag:nodrv_CreateWindow Application tried to create a window, but no driver could be loaded.
002c:err:winediag:nodrv_CreateWindow The graphics driver is missing. Check your build!
0050:err:winediag:nodrv_CreateWindow Application tried to create a window, but no driver could be loaded.
0050:err:winediag:nodrv_CreateWindow The graphics driver is missing. Check your build!
0050:err:ole:apartment_createwindowifneeded CreateWindow failed with error 0
0050:err:ole:apartment_createwindowifneeded CreateWindow failed with error 0
0050:err:ole:apartment_createwindowifneeded CreateWindow failed with error 14007
0050:err:ole:StdMarshalImpl_MarshalInterface Failed to create ifstub, hres=0x800736b7
0050:err:ole:CoMarshalInterface Failed to marshal the interface {6d5140c1-7436-11ce-8034-00aa006009fa}, 800736b7
0050:err:ole:get_local_server_stream Failed: 800736b7
0040:err:winediag:nodrv_CreateWindow Application tried to create a window, but no driver could be loaded.
0040:err:winediag:nodrv_CreateWindow The graphics driver is missing. Check your build!
0058:err:winediag:nodrv_CreateWindow Application tried to create a window, but no driver could be loaded.
0058:err:winediag:nodrv_CreateWindow The graphics driver is missing. Check your build!
0060:err:winediag:nodrv_CreateWindow Application tried to create a window, but no driver could be loaded.
0060:err:winediag:nodrv_CreateWindow The graphics driver is missing. Check your build!
Could not find Wine Gecko. HTML rendering will be disabled.
0040:err:vulkan:wine_vk_init Failed to load Wine graphics driver supporting Vulkan.
00a8:err:ntoskrnl:ZwLoadDriver failed to create driver L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\wineusb": c0000142
002c:err:setupapi:SetupDiInstallDevice Failed to start service L"wineusb" for device L"ROOT\\WINE\\WINEUSB", error 1114.
wine: configuration in L"/root/.wine" has been updated.
Hello Wine64!

从上面的输出来看,wine会先判断home目录下面是否存在.wine文件夹,如果不存在,则会自动创建,然后执行 echo "Hello Wine64!" 命令。可以重点看一下 ~/.wine/ 下面的目录,

/root/.wine/
├── dosdevices
│   ├── c: -> ../drive_c
│   ├── com1 -> /dev/ttyS0
│   ├── com10 -> /dev/ttyS9
│   ├── com17 -> /dev/ttyS16
│   ├── com8 -> /dev/ttyS7
│   ├── com9 -> /dev/ttyS8
│   └── z: -> /                #可以看到"z:/"盘映射为linux根目录"/"
├── drive_c
│   ├── ProgramData
│   │   └── Microsoft
│   │       └── Windows
│   │           ├── Start Menu
│   │           │   └── Programs
│   │           │       ├── Administrative Tools
│   │           │       └── StartUp
│   │           └── Templates
│   ├── Program Files
│   │   ├── Common Files
│   │   │   ├── Microsoft Shared
│   │   │   │   └── TextConv
│   │   │   └── System
│   │   │       ├── ADO
│   │   │       │   └── msado15.dll
│   │   │       └── OLE DB
│   │   │           ├── msdaps.dll
│   │   │           └── oledb32.dll
│   │   ├── Internet Explorer
│   │   │   └── iexplore.exe
│   │   ├── Windows Media Player
│   │   │   └── wmplayer.exe
│   │   └── Windows NT
│   │       └── Accessories
│   │           └── wordpad.exe
│   ├── Program Files (x86)
│   │   └── Common Files
│   ├── users
│   │   ├── Public
│   │   │   ├── Desktop
│   │   │   ├── Documents
│   │   │   ├── Favorites
│   │   │   ├── Music
│   │   │   ├── Pictures
│   │   │   └── Videos
│   │   └── root
│   │       ├── AppData
│   │       │   └── LocalLow
│   │       ├── Application Data
│   │       │   └── Microsoft
│   │       │       └── Windows
│   │       │           └── Themes
│   │       ├── Contacts
│   │       ├── Cookies
│   │       ├── Desktop
│   │       ├── Downloads -> /root/.wine/dosdevices/c:/users/root/My Documents
│   │       ├── Favorites
│   │       ├── Links
│   │       ├── Local Settings
│   │       │   ├── Application Data
│   │       │   │   └── Microsoft
│   │       │   ├── History
│   │       │   └── Temporary Internet Files
│   │       ├── My Documents -> /root
│   │       ├── My Music -> /root/.wine/dosdevices/c:/users/root/My Documents
│   │       ├── My Pictures -> /root/.wine/dosdevices/c:/users/root/My Documents
│   │       ├── My Videos -> /root/.wine/dosdevices/c:/users/root/My Documents
│   │       ├── NetHood
│   │       ├── PrintHood
│   │       ├── Recent
│   │       ├── Saved Games
│   │       ├── Searches
│   │       ├── SendTo
│   │       ├── Start Menu
│   │       │   └── Programs
│   │       │       ├── Administrative Tools
│   │       │       └── StartUp
│   │       ├── Temp
│   │       └── Templates -> /root/.wine/dosdevices/c:/users/root/My Documents
│   └── windows
│       ├── explorer.exe
│       ├── Fonts
│       ├── globalization
│       │   └── sorting
│       │       └── sortdefault.nls
│       ├── help
│       ├── hh.exe
│       ├── inf
│       │   ├── oem0.inf
│       │   ├── winebus.inf
......

上面完成后,基本上就可以进行下面的步骤了,不过,有时候home目录的磁盘不是很大,就需要把wine相关的文件放到其他路径下,可以按照下面的做法:

1. 先把/root/.wine目录拷贝到/opt/wine64, 即 cp -r /root/.wine /opt/wine64

2. WINEPREFIX=/opt/wine64 build_x64/bin/wine64 cmd /c echo "Hello Wine64!"

  这样wine会按照环境变量WINEPREFIX设置的路径去查找文件

现在正式进入下一个环节:

二、在wine中,编译vs2013工程

1. 首先你得在win7上已经安装好了vs2013软件(磨刀不误砍菜功嘛,慢慢磨咯)

2. 在win7上,将 C:\Program Files (x86)\Windows Kits\8.1 目录下面的 bin、include、Lib 这3个文件夹,对应拷贝到 /opt/wine64/drive_c/Program Files (x86)/Windows Kits/8.1/ 目录下面

3. 在win7上,将 C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC 目录下面的 bin、include 、lib 、vcvarsall.bat 对应拷贝到 /opt/wine64/drive_c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/ 目录下面

4. 写一个main_test.cpp测试程序,如下:

// main_test.cpp

#include <stdio.h>


int main(int argc, char *argv[])
{
    printf("Hello World!\n");
    return 0;
}

5. 写一个生成exe的 Makefile.vs2013,如下:

# filename: Makefile.vs2013
# 386520874@qq.com && 2020.09.05

PLATFORM = x64
DEBUG = 0

#-----------------------------------------
PROJECT_VERSION = v1.0.0.0
VS_VERSION = vs2013
PROJECT_NAME = main_test
PROJECT_DIR = $(MAKEDIR)
PREFIX_DIR = $(PROJECT_DIR)\bin
SUFFIX =

EXE = $(PROJECT_NAME).exe
LIB_NAME = $(PROJECT_NAME).lib

#-----------------------------------------
!IF "$(PLATFORM)" == "Win32"
CC = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe"
LD = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe"
RC = "C:\Program Files (x86)\Windows Kits\8.1\bin\x86\rc.exe"
!ELSEIF "$(PLATFORM)" == "x64"
CC = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\cl.exe"
LD = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\link.exe"
RC = "C:\Program Files (x86)\Windows Kits\8.1\bin\x64\rc.exe"
!ENDIF

#-----------------------------------------
INCLUDE = \
/I"C:\Program Files (x86)\Windows Kits\8.1\Include\um" \
/I"C:\Program Files (x86)\Windows Kits\8.1\Include\shared" \
/I"c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" \
/I$(PROJECT_DIR) \
/I$(PROJECT_DIR)\main_test

#-----------------------------------------
LIB_PATH_Win32 = \
/LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib" \
/LIBPATH:"C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86"

LIB_PATH_x64 = \
/LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\amd64" \
/LIBPATH:"C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64"

#-----------------------------------------
CXXFLAGS_Win32 = /c /TP /GS /analyze- /W3 /Zc:wchar_t /Zi /fp:precise /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /EHsc /nologo
LDFLAGS_Win32 = /NXCOMPAT /DYNAMICBASE /DEBUG /MACHINE:X86 /SUBSYSTEM:CONSOLE /ERRORREPORT:PROMPT /NOLOGO /TLBID:1 \
$(LIB_PATH_Win32) \
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

CXXFLAGS_x64 = /c /TP /GS /W3 /Zc:wchar_t /Zi /fp:precise /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /EHsc /nologo
LDFLAGS_x64 = /NXCOMPAT /DYNAMICBASE /DEBUG /MACHINE:X64 /INCREMENTAL /SUBSYSTEM:CONSOLE /ERRORREPORT:PROMPT /NOLOGO  /TLBID:1 \
$(LIB_PATH_x64) \
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

#-----------------------------------------
!IF "$(PLATFORM)" == "Win32"

!       IF $(DEBUG) == 1
CXXFLAGS = $(CXXFLAGS_Win32) /Gm /MDd /Od /RTC1 /D "_DEBUG"
LDFLAGS = $(LDFLAGS_Win32) /MANIFEST:NO /INCREMENTAL
OUTPUT_DIR = $(PROJECT_DIR)\build\$(VS_VERSION)\$(PLATFORM)\Debug
TEMP_DIR = $(PROJECT_DIR)\temp\$(VS_VERSION)\$(PLATFORM)\Debug
SUFFIX = Win32-d
VISUAL_STUDIO_INFO = _vs2013_Win32_Debug
!       ELSE
CXXFLAGS = $(CXXFLAGS_Win32) /Gm- /MD /Oi /GL /Gy /O2 /D "NDEBUG"
LDFLAGS = $(LDFLAGS_Win32) /MANIFEST /INCREMENTAL:NO /LTCG /OPT:NOREF /SAFESEH /OPT:ICF  /MANIFESTUAC:"level='asInvoker' uiAccess='false'"
OUTPUT_DIR = $(PROJECT_DIR)\build\$(VS_VERSION)\$(PLATFORM)\Release
TEMP_DIR = $(PROJECT_DIR)\temp\$(VS_VERSION)\$(PLATFORM)\Release
SUFFIX = Win32
VISUAL_STUDIO_INFO = _vs2013_Win32_Release
!       ENDIF

!ELSEIF "$(PLATFORM)" == "x64"

!       IF $(DEBUG) == 1
CXXFLAGS = $(CXXFLAGS_x64) /Gm /MDd /Od /RTC1 /D "_DEBUG"
LDFLAGS = $(LDFLAGS_x64) /MANIFEST:NO /INCREMENTAL
OUTPUT_DIR = $(PROJECT_DIR)\build\$(VS_VERSION)\$(PLATFORM)\Debug
TEMP_DIR = $(PROJECT_DIR)\temp\$(VS_VERSION)\$(PLATFORM)\Debug
SUFFIX = x64-d
VISUAL_STUDIO_INFO = _vs2013_x64_Debug
!       ELSE
CXXFLAGS = $(CXXFLAGS_x64) /Gm- /MD /O2 /Oi /GL /Gy /D "NDEBUG"
LDFLAGS = $(LDFLAGS_x64) /MANIFEST /INCREMENTAL:NO /LTCG /OPT:NOREF /OPT:ICF  /MANIFESTUAC:"level='asInvoker' uiAccess='false'"
OUTPUT_DIR = $(PROJECT_DIR)\build\$(VS_VERSION)\$(PLATFORM)\Release
TEMP_DIR = $(PROJECT_DIR)\temp\$(VS_VERSION)\$(PLATFORM)\Release
SUFFIX = x64
VISUAL_STUDIO_INFO = _vs2013_x64_Release
!       ENDIF

!ENDIF

#-----------------------------------------
SRCS_C =

SRCS = \
.\main_test.cpp

OBJS_C = $(SRCS_C:.c=.obj)
OBJS = $(SRCS:.cpp=.obj)

RC_FILE = $(MAKEDIR)\main_test.rc
RES = $(TEMP_DIR)\main_test.res

#-----------------------------------------
ALL: clean CREATE_DIR $(EXE) install

CREATE_DIR:
        if not exist $(TEMP_DIR) mkdir $(TEMP_DIR)
        if not exist $(OUTPUT_DIR) mkdir $(OUTPUT_DIR)
        if not exist $(PREFIX_DIR) mkdir $(PREFIX_DIR)

$(EXE): $(OBJS) $(OBJS_C)
        cd /d $(TEMP_DIR) && $(LD) $** $(LDFLAGS) /OUT:"$(OUTPUT_DIR)\$@" /IMPLIB:"$(OUTPUT_DIR)\$(PROJECT_NAME).lib" /PDB:"$(OUTPUT_DIR)\$(PROJECT_NAME).pdb"

.c.obj:
        if not exist $(TEMP_DIR)\%|pF mkdir $(TEMP_DIR)\%|pF
        $(CC) $(CXXFLAGS) $(INCLUDE) /Fd"$(TEMP_DIR)\vc120.pdb" /Fa"$(TEMP_DIR)\\"%|pF /Fo"$(TEMP_DIR)\\"%|pF /Fp"$(TEMP_DIR)\$(PROJECT_NAME).pch" $<

.cpp.obj:
        if not exist $(TEMP_DIR)\%|pF mkdir $(TEMP_DIR)\%|pF
        $(CC) $(CXXFLAGS) $(INCLUDE) /Fd"$(TEMP_DIR)\vc120.pdb" /Fa"$(TEMP_DIR)\\"%|pF /Fo"$(TEMP_DIR)\\"%|pF /Fp"$(TEMP_DIR)\$(PROJECT_NAME).pch" $<

$(RES): $(RC_FILE)
        $(RC) /d "VS_INFO=$(VISUAL_STUDIO_INFO)" /l"0x0409" /nologo $(INCLUDE) /fo"$(RES)" $(RC_FILE)

install:
        if exist "$(OUTPUT_DIR)\$(EXE)" copy "$(OUTPUT_DIR)\$(EXE)" "$(PREFIX_DIR)\$(PROJECT_NAME).exe"

clean:
        if exist "$(OUTPUT_DIR)" del /q "$(OUTPUT_DIR)\*"
        if exist "$(TEMP_DIR)" del /q "$(TEMP_DIR)\*"

uninstall:
        if exist "$(PREFIX_DIR)" del /q "$(PREFIX_DIR)\*"

6. 编译成exe文件,运行命令:

 WINEPREFIX=/opt/wine64  /root/Packages/wine-5.10/build_x64/bin/wine64 "C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/nmake.exe" -f Makefile.vs2013 DEBUG=0 PLATFORM=x64

root@pc:~/test# WINEPREFIX=/opt/wine64 /root/Packages/wine-5.10/build_x64/wine64 "C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/nmake.exe" -f Makefile.vs2013 DEBUG=0 PLATFORM=x64
0078:err:ntoskrnl:ZwLoadDriver failed to create driver L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\wineusb": c0000142
003c:fixme:service:scmdatabase_autostart_services Auto-start service L"wineusb" failed to start: 1114

0024:fixme:nls:RtlSetThreadPreferredUILanguages 256, (nil), (nil)
0024:fixme:nls:RtlGetThreadPreferredUILanguages 00000034, 0x21de88, (nil) 0x21de74
0024:fixme:nls:get_dummy_preferred_ui_language (0x34 0x21de88 (nil) 0x21de74) returning a dummy value (current locale)
0024:fixme:nls:RtlGetThreadPreferredUILanguages 00000034, 0x21de88, 0x101c80 0x21de74
0024:fixme:nls:get_dummy_preferred_ui_language (0x34 0x21de88 0x101c80 0x21de74) returning a dummy value (current locale)
Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

        if exist "Z:\root\test\build\vs2013\x64\Release" del /q "Z:\root\test\build\vs2013\x64\Release\*"
        if exist "Z:\root\test\temp\vs2013\x64\Release" del /q "Z:\root\test\temp\vs2013\x64\Release\*"
        if not exist Z:\root\test\temp\vs2013\x64\Release mkdir Z:\root\test\temp\vs2013\x64\Release
        if not exist Z:\root\test\build\vs2013\x64\Release mkdir Z:\root\test\build\vs2013\x64\Release
        if not exist Z:\root\test\bin mkdir Z:\root\test\bin
        if not exist Z:\root\test\temp\vs2013\x64\Release\.\ mkdir Z:\root\test\temp\vs2013\x64\Release\.\
        "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\cl.exe" /c /TP /GS /W3 /Zc:wchar_t /Zi /fp:precise /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /EHsc /nologo /Gm- /MD /O2 /Oi /GL /Gy /D "NDEBUG" /I"C:\Program Files (x86)\Windows Kits\8.1\Include\um"  /I"C:\Program Files (x86)\Windows Kits\8.1\Include\shared"  /I"c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include"  /IZ:\root\test  /IZ:\root\test\main_test /Fd"Z:\root\test\temp\vs2013\x64\Release\vc120.pdb" /Fa"Z:\root\test\temp\vs2013\x64\Release\\".\ /Fo"Z:\root\test\temp\vs2013\x64\Release\\".\ /Fp"Z:\root\test\temp\vs2013\x64\Release\main_test.pch" .\main_test.cpp
00e0:fixme:nls:RtlSetThreadPreferredUILanguages 256, (nil), (nil)
00e0:fixme:nls:RtlGetThreadPreferredUILanguages 00000034, 0x51d580, (nil) 0x51d564
00e0:fixme:nls:get_dummy_preferred_ui_language (0x34 0x51d580 (nil) 0x51d564) returning a dummy value (current locale)
00e0:fixme:nls:RtlGetThreadPreferredUILanguages 00000034, 0x51d580, 0xa37a30 0x51d564
00e0:fixme:nls:get_dummy_preferred_ui_language (0x34 0x51d580 0xa37a30 0x51d564) returning a dummy value (current locale)
main_test.cpp
00e0:fixme:msvcrt:__clean_type_info_names_internal (0x1079aa8) stub
00e0:fixme:msvcrt:__clean_type_info_names_internal (0x16f6ab8) stub
00e0:fixme:msvcrt:__clean_type_info_names_internal (0x11927b8) stub
00e0:fixme:msvcrt:__clean_type_info_names_internal (0x18003d778) stub
        cd /d Z:\root\test\temp\vs2013\x64\Release && "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\link.exe" .\main_test.obj /NXCOMPAT /DYNAMICBASE /DEBUG /MACHINE:X64 /INCREMENTAL /SUBSYSTEM:CONSOLE /ERRORREPORT:PROMPT /NOLOGO  /TLBID:1  /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\amd64"  /LIBPATH:"C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64"  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /INCREMENTAL:NO /LTCG /OPT:NOREF /OPT:ICF  /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /OUT:"Z:\root\test\build\vs2013\x64\Release\main_test.exe" /IMPLIB:"Z:\root\test\build\vs2013\x64\Release\main_test.lib" /PDB:"Z:\root\test\build\vs2013\x64\Release\main_test.pdb"
00f0:fixme:nls:RtlSetThreadPreferredUILanguages 256, (nil), (nil)
00f0:fixme:nls:RtlGetThreadPreferredUILanguages 00000034, 0x21d520, (nil) 0x21d504
00f0:fixme:nls:get_dummy_preferred_ui_language (0x34 0x21d520 (nil) 0x21d504) returning a dummy value (current locale)
00f0:fixme:nls:RtlGetThreadPreferredUILanguages 00000034, 0x21d520, 0x11df50 0x21d504
00f0:fixme:nls:get_dummy_preferred_ui_language (0x34 0x21d520 0x11df50 0x21d504) returning a dummy value (current locale)
Generating code
00f0:fixme:ole:NdrCorrelationInitialize (000000000021C430, 000000000021B8F0, 2048, 0x0): semi-stub
00f0:fixme:ole:NdrCorrelationFree (000000000021C430): stub
0104:fixme:ole:NdrCorrelationInitialize (0000000000CCEE70, 0000000000CCF000, 2048, 0x0): semi-stub
0104:fixme:ole:NdrCorrelationFree (0000000000CCEE70): stub
Finished generating code
00f0:fixme:msvcrt:__clean_type_info_names_internal (0x2fca5f8) stub
00f0:fixme:msvcrt:__clean_type_info_names_internal (0x2406ab8) stub
00f0:fixme:msvcrt:__clean_type_info_names_internal (0x267d778) stub
00f0:fixme:msvcrt:__clean_type_info_names_internal (0x18006d7b8) stub
        if exist "Z:\root\test\build\vs2013\x64\Release\main_test.exe" copy "Z:\root\test\build\vs2013\x64\Release\main_test.exe" "Z:\root\test\bin\main_test.exe"

7. 会生成 build/vs2013/x64/Release/main_test.exe 文件,然后测试一下这个exe文件是否有效,

root@pc:~//test# WINEPREFIX=/opt/wine64 /root/Packages/wine-5.10/build_x64/wine64 build/vs2013/x64/Release/main_test.exe
Hello World!

8. 最后可以拷贝到windows上,运行一下:

嗯,到此处,基本上大功告成了,接下来进入到下一个环节

三、将exe文件打包

1. 自己写一个 Inno Setup 的打包脚本,比如 package_for_main_test.iss,写好后一定要保存成 UTF-8 Unicode (with BOM) text 格式,重点是这个"with BOM",当时我就是在这里被坑惨了,最后回过神来发现,用vim和用windows记事本保存的UTF-8文件,一个是不带"with BOM",一个是带"with BOM"的,真是嘿无语哈。

2. 先在win7上安装好Inno Setup 6

3. 将win7上的 C:\Program Files (x86)\Inno Setup 6 整个目录拷贝到Ubuntu的 /opt/wine64/drive_c/Program Files (x86)/Inno Setup 6/ 下面

4. 在Ubuntu上运行打包命令:

WINEPREFIX=/opt/wine64 /root/Packages/wine-5.10/build_x64/wine64 "C:/Program Files (x86)/Inno Setup 6/ISCC.exe" /Oz:\opt  package_for_main_test.iss

四、docker自动化编译和打包

前面三板斧下来,就完成得差不多了,剩下的就是把上面的劳动成果,搬到docker里面去,制作成一个docker镜像,然后让gitlab CI自动化跑流程。

打完,收工!

                                                                                                                 ------------过客 & 2020.09.05 & 香港九龙

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值