我正在尝试构建一个需要在可能没有安装.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环境变量,但我对如何解决这些链接器错误感到有些困惑。
答案 0 :(得分:1)
我正在使用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 \包括\ 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“/一世 ”。” “temp.c”“temp.o”“C:\ Program Files(x86)\ Mono \ lib \ monosgen-2.0.lib”/ link / 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:tt2.exe
然后执行以下操作:
将monosgen-2.0.dll从C:\ Program Files(x86)\ Mono \ bin复制到mkbundled应用程序目录。
将所有.dll文件从C:\ Program Files(x86)\ Windows Kits \ 10 \ Redist \ ucrt \ DLLs \ x86复制到mkbundled应用程序目录。然后运行mkbundled的应用程序。
你会得到你想要的结果。
也:
并且,不要将捆绑的应用程序放到非ANSI路径中, 因为mkbundle不完全支持Windows上的非ANSI路径。 解决这个问题: 你可以编辑temp.c文件,
键入SetEnvironmentVariable(“UTF16”); 在方法体第一行:int main(int argc,char * argv [])
然后您的捆绑应用程序可以在任何路径上运行, 但仍有一些问题: 在你的c#应用程序中,mkbundle, 您无法使用AppDomain.CurrentDomain.BaseDirectory来获取应用程序存在的目录。 另一个问题,如果您的应用程序使用app.config,并在appsettings中定义一些变量。 捆绑应用程序后,它无法从.config文件中读取变量, reaseon与AppDomain.CurrentDomain.BaseDirectory问题相同。
在处理非ANSI路径时,似乎是appdomain创建中的mkbundled应用程序存在错误。
我正在解决这个问题,并阅读单声道源代码,但到目前为止还没有找到解决方案。
答案 1 :(得分:0)
最后,我找到了如何解决这个问题。
你必须像这样使用mkbundle:
mkbundle --deps mkbundleTest.exe -o test.exe --keeptemp
重点是--keeptemp param。
使用此参数,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.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
从此行删除两个参数:/ 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.lib”/ link / 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
然后您将获得捆绑的应用程序。
这种方式适合我。