在Windows上,mkbundle因链接器错误而失败

本文关键字:错误 失败 链接 Windows mkbundle | 更新日期: 2023-09-27 18:11:50

我正在尝试构建一个控制台实用程序,需要在可能没有安装。net的环境中运行。Mono的mkbundle似乎是这个问题的一个很好的解决方案,但是当通过cygwin在Windows 10上运行mkbundle (Mono 4.6.1.3)时,这是我收到的输出:

$ mkbundle --deps mkbundleTest.exe -o test.exe
OS is: Windows
Sources: 1 Auto-dependencies: True
   embedding: C:'Users'Jason'Documents'mkbundleTest'mkbundleTest'bin'Debug'mkbundleTest.exe
 config from: C:'Users'Jason'Documents'mkbundleTest'mkbundleTest'bin'Debug'mkbundleTest.exe.config
   embedding: C:'Program Files'Mono'lib'mono'4.5'mscorlib.dll
AS = as (default)
as -o temp.o temp.s
Compiling:
CC = cl.exe (default)
WINSDK = C:'Program Files (x86)'Windows Kits'8.1 (default)
VSINCLUDE = C:'Program Files (x86)'Microsoft Visual Studio 14.0'VC (default)
MONOPREFIX = C:'Program Files (x86)'Mono (default)
WARNING: Dynamically linking the Mono runtime on Windows is not a tested option.
cl.exe /MT /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 14.0'VC'include" /I "C:'Program Files (x86)'Mono'include'mono-2.0" /I "." "temp.c" "temp.o" "C:'Program Files (x86)'Mono'lib'monosgen-2.0.lib" /link /NODEFAULTLIB /SUBSYSTEM:windows /ENTRY:mainCRTStartup kernel32.lib version.lib Ws2_32.lib Mswsock.lib Psapi.lib shell32.lib OleAut32.lib ole32.lib winmm.lib user32.lib libvcruntime.lib advapi32.lib OLDNAMES.lib libucrt.lib /out:test.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.
cl : Command line warning D9024 : unrecognized source file type 'temp.o', object file assumed
temp.c
Microsoft (R) Incremental Linker Version 14.00.24215.1
Copyright (C) Microsoft Corporation.  All rights reserved.
/out:temp.exe
/NODEFAULTLIB
/SUBSYSTEM:windows
/ENTRY:mainCRTStartup
kernel32.lib
version.lib
Ws2_32.lib
Mswsock.lib
Psapi.lib
shell32.lib
OleAut32.lib
ole32.lib
winmm.lib
user32.lib
libvcruntime.lib
advapi32.lib
OLDNAMES.lib
libucrt.lib
/out:test.exe
temp.obj
temp.o
"C:'Program Files (x86)'Mono'lib'monosgen-2.0.lib"
LINK : error LNK2001: unresolved external symbol _mainCRTStartup
libvcruntime.lib(wcschr.obj) : error LNK2001: unresolved external symbol ___isa_available
libvcruntime.lib(memcpy.obj) : error LNK2001: unresolved external symbol ___isa_available
libvcruntime.lib(strchr.obj) : error LNK2001: unresolved external symbol ___isa_available
libucrt.lib(strnlen.obj) : error LNK2001: unresolved external symbol ___isa_available
libvcruntime.lib(memset.obj) : error LNK2001: unresolved external symbol ___isa_available
libvcruntime.lib(memcpy.obj) : error LNK2019: unresolved external symbol ___isa_enabled referenced in function _memcpy
libvcruntime.lib(memset.obj) : error LNK2001: unresolved external symbol ___isa_enabled
libvcruntime.lib(memcpy.obj) : error LNK2019: unresolved external symbol ___favor referenced in function _memcpy
libvcruntime.lib(memset.obj) : error LNK2001: unresolved external symbol ___favor
libucrt.lib(signal.obj) : error LNK2001: unresolved external symbol __SEH_epilog4
libucrt.lib(onexit.obj) : error LNK2001: unresolved external symbol __SEH_epilog4
libucrt.lib(winapi_thunks.obj) : error LNK2001: unresolved external symbol __SEH_epilog4
libucrt.lib(mbctype.obj) : error LNK2001: unresolved external symbol __SEH_epilog4
libucrt.lib(locale_refcounting.obj) : error LNK2001: unresolved external symbol __SEH_epilog4
libucrt.lib(exit.obj) : error LNK2001: unresolved external symbol __SEH_epilog4
libucrt.lib(getenv.obj) : error LNK2001: unresolved external symbol __SEH_epilog4
libucrt.lib(new_handler.obj) : error LNK2001: unresolved external symbol __SEH_epilog4
libucrt.lib(per_thread_data.obj) : error LNK2001: unresolved external symbol __SEH_epilog4
libucrt.lib(wsetlocale.obj) : error LNK2001: unresolved external symbol __SEH_epilog4
libucrt.lib(signal.obj) : error LNK2001: unresolved external symbol __SEH_prolog4
libucrt.lib(onexit.obj) : error LNK2001: unresolved external symbol __SEH_prolog4
libucrt.lib(winapi_thunks.obj) : error LNK2001: unresolved external symbol __SEH_prolog4
libucrt.lib(mbctype.obj) : error LNK2001: unresolved external symbol __SEH_prolog4
libucrt.lib(locale_refcounting.obj) : error LNK2001: unresolved external symbol __SEH_prolog4
libucrt.lib(exit.obj) : error LNK2001: unresolved external symbol __SEH_prolog4
libucrt.lib(getenv.obj) : error LNK2001: unresolved external symbol __SEH_prolog4
libucrt.lib(new_handler.obj) : error LNK2001: unresolved external symbol __SEH_prolog4
libucrt.lib(per_thread_data.obj) : error LNK2001: unresolved external symbol __SEH_prolog4
libucrt.lib(wsetlocale.obj) : error LNK2001: unresolved external symbol __SEH_prolog4
libucrt.lib(invalid_parameter.obj) : error LNK2019: unresolved external symbol __crt_debugger_hook referenced in function ___acrt_call_reportfault
libvcruntime.lib(_exsup4_.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libvcruntime.lib(_exsup_.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(isctype.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(initterm.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(onexit.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libvcruntime.lib(_chandler4_.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(getqloc_downlevel.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(lcmapstringa.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(exit.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(getlocaleinfoa.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(exception_filter.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(initctype.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(getstringtypea.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(get_qualified_locale.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(comparestringa.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(winapi_thunks.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(free_base.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(mbctype.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(invalid_parameter.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(environment_initialization.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(new_handler.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(wsetlocale.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
libucrt.lib(onexit.obj) : error LNK2001: unresolved external symbol ___security_cookie
libvcruntime.lib(_chandler4_.obj) : error LNK2001: unresolved external symbol ___security_cookie
libvcruntime.lib(_exsup4_.obj) : error LNK2001: unresolved external symbol ___security_cookie
libvcruntime.lib(_exsup_.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(getlocaleinfoa.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(isctype.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(initterm.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(onexit.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(lcmapstringa.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(exit.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(exit.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(signal.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(initctype.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(getstringtypea.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(get_qualified_locale.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(getqloc_downlevel.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(winapi_thunks.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(free_base.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(mbctype.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(exception_filter.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(new_handler.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(wsetlocale.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(comparestringa.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(winapi_thunks.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(invalid_parameter.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(invalid_parameter.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(environment_initialization.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(new_handler.obj) : error LNK2001: unresolved external symbol ___security_cookie
libucrt.lib(wsetlocale.obj) : error LNK2019: unresolved external symbol ___report_rangecheckfailure referenced in function __wsetlocale_nolock
libucrt.lib(comparestringa.obj) : error LNK2019: unresolved external symbol __alloca_probe_16 referenced in function "int __cdecl InternalCompareStringA(struct __crt_locale_pointers *,wchar_t const *,unsigned long,char const *,int,char const *,int,int)" (?InternalCompareStringA@@YAHPAU__crt_locale_pointers@@PB_WKPBDH2HH@Z)
libucrt.lib(getstringtypea.obj) : error LNK2001: unresolved external symbol __alloca_probe_16
libucrt.lib(lcmapstringa.obj) : error LNK2001: unresolved external symbol __alloca_probe_16
libucrt.lib(getlocaleinfoa.obj) : error LNK2001: unresolved external symbol __alloca_probe_16
libucrt.lib(exit.obj) : error LNK2019: unresolved external symbol __SEH_epilog4_GS referenced in function "public: __thiscall <lambda_6e4b09c48022b2350581041d5f6b0c4c>::operator()(void)const " (??R<lambda_6e4b09c48022b2350581041d5f6b0c4c>@@QBE@XZ)
libucrt.lib(signal.obj) : error LNK2001: unresolved external symbol __SEH_epilog4_GS
libucrt.lib(terminate.obj) : error LNK2001: unresolved external symbol __SEH_epilog4_GS
libucrt.lib(exit.obj) : error LNK2019: unresolved external symbol __SEH_prolog4_GS referenced in function "public: __thiscall <lambda_6e4b09c48022b2350581041d5f6b0c4c>::operator()(void)const " (??R<lambda_6e4b09c48022b2350581041d5f6b0c4c>@@QBE@XZ)
libucrt.lib(signal.obj) : error LNK2001: unresolved external symbol __SEH_prolog4_GS
libucrt.lib(terminate.obj) : error LNK2001: unresolved external symbol __SEH_prolog4_GS
libucrt.lib(exit.obj) : error LNK2001: unresolved external symbol ___xp_a
libucrt.lib(exit.obj) : error LNK2001: unresolved external symbol ___xp_z
libucrt.lib(exit.obj) : error LNK2001: unresolved external symbol ___xt_a
libucrt.lib(exit.obj) : error LNK2001: unresolved external symbol ___xt_z
libucrt.lib(xtoa.obj) : error LNK2019: unresolved external symbol __aulldvrm referenced in function "int __cdecl common_xtox<unsigned __int64,char>(unsigned __int64,char * const,unsigned int,unsigned int,bool)" (??$common_xtox@_KD@@YAH_KQADII_N@Z)
libucrt.lib(atox.obj) : error LNK2001: unresolved external symbol __aulldvrm
libucrt.lib(atox.obj) : error LNK2019: unresolved external symbol __allmul referenced in function "unsigned __int64 __cdecl __crt_strtox::parse_integer<unsigned __int64,class __crt_strtox::c_string_character_source<char> >(struct __crt_locale_pointers * const,class __crt_strtox::c_string_character_source<char>,int,bool)" (??$parse_integer@_KV?$c_string_character_source@D@__crt_strtox@@@__crt_strtox@@YA_KQAU__crt_locale_pointers@@V?$c_string_character_source@D@0@H_N@Z)
libvcruntime.lib(_chandler4_.obj) : error LNK2019: unresolved external symbol __IsNonwritableInCurrentImage referenced in function __except_handler4
libvcruntime.lib(_chandler4_.obj) : error LNK2019: unresolved external symbol @_guard_check_icall@4 referenced in function __except_handler4
LINK : error LNK2001: unresolved external symbol __load_config_used
test.exe : fatal error LNK1120: 22 unresolved externals
ERROR: [Fail] 2

要做到这一点,我已经安装了最新的windows SDK并设置了INCLUDE和LIB环境变量,但我有点卡在如何解决这些链接器错误。

在Windows上,mkbundle因链接器错误而失败

我使用的是Windows 10和windows10sdk,编译命令是这样的:

cl.exe/MT/I "C:'Program Files (x86)'Windows Kits'10'Include'10.0.14393.0'um"/I "C:'Program Files (x86)'Windows Kits'10'Include'10.0.14393.0'shared"/I "C:'Program Files (x86)'Microsoft Visual Studio 14.0'VC' Include "/I "C:'Program Files (x86)'Mono' Include' Mono -2.0"/I "。"temp.c" "temp.o" "C:'Program Files (x86)'Mono'lib'monosgen-2.0 "mainCRTStartup kernel32. lib/link/ENTRY:自由的版本。自由Ws2_32。自由Mswsock。自由Psapi。自由shell32。自由OleAut32。自由ole32。自由winmm。自由user32。自由libvcruntime。自由advapi32。自由OLDNAMES。自由libucrt。lib/: tt2.exe

,然后执行以下操作:

  1. 从C:'Program Files (x86)'Mono'bin拷贝monosgen-2.0.dll到你的mkbundle应用目录。

  2. 将所有.dll文件从C:'Program Files (x86)'Windows Kits'10'Redist'ucrt' dll 'x86复制到您的mkbundle应用程序目录。然后运行mk捆绑的应用程序。

你会得到你想要的结果。

:

,不要将绑定的应用程序放在非ansi路径下,因为mkbundle不完全支持windows上的非ansi路径。要解决这个问题:您可以编辑temp.c文件

输入SetEnvironmentVariable("UTF16");在方法体第一行:int main(int argc,char* argv[])

则绑定的应用程序可以在任何路径下运行,但仍然存在一些问题:在你的c#应用程序中,它是mkbundle,你不能使用AppDomain.CurrentDomain.BaseDirectory来获取应用程序的存在目录。另一个问题是,如果您的应用程序使用app.config,并在appsettings中定义一些变量。绑定应用程序后,它无法从.config文件中读取变量,原因与AppDomain.CurrentDomain.BaseDirectory问题相同。

在创建appdomain时似乎是mkbundle应用程序,在处理非ansi路径时存在错误。

我解决了这个问题,并阅读了mono源代码,但到目前为止还没有找到解决方案。

在我的上一篇文章之后。我试了很多方法。

最后,我找到了解决这个问题的方法。

你必须这样使用mkbundle:

mkbundle——deps mkbundleTest.exe -o test.exe——keeptemp

关键是——keeptemp参数。

使用这个参数,mkbundle将把temp.c文件保存到当前目录。

然后复制这一行:

cl.exe/MT/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 14.0'VC' Include "/I "C:'Program Files (x86)'Mono' Include' Mono -2.0"/I "。"temp.c" "temp.o" "C:'Program Files (x86)'Mono'lib'monosgen-2.0 "/link/NODEFAULTLIB/SUBSYSTEM:windows/ENTRY:mainCRTStartup kernel32。自由的版本。自由Ws2_32。自由Mswsock。自由Psapi。自由shell32。自由OleAut32。自由ole32。自由winmm。自由user32。自由libvcruntime。自由advapi32。自由OLDNAMES。自由libucrt。lib/: test.exe

从这行删除两个参数:/NODEFAULTLIB/SUBSYSTEM:windows,

最后的命令行如下:

cl.exe/MT/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 14.0'VC' Include "/I "C:'Program Files (x86)'Mono' Include' Mono -2.0"/I "。"temp.c" "temp.o" "C:'Program Files (x86)'Mono'lib'monosgen-2.0 "mainCRTStartup kernel32. lib/link/ENTRY:自由的版本。自由Ws2_32。自由Mswsock。自由Psapi。自由shell32。自由OleAut32。自由ole32。自由winmm。自由user32。自由libvcruntime。自由advapi32。自由OLDNAMES。自由libucrt。lib/: test.exe

那么你将得到你的捆绑应用程序。