gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 17:36:15 28 4
gpt4 key购买 nike

我正在尝试构建一个需要在可能未安装 .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 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

然后执行以下操作:

  1. 将 monosgen-2.0.dll 从 C:\Program Files (x86)\Mono\bin 复制到您的 mkbundled 应用程序目录。

  2. 将 C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x86 中的所有 .dll 文件复制到您的 mkbundled 应用程序目录。然后运行你的应用程序 which mkbundled 。

你会得到你想要的结果。

还有:

并且,不要将您的捆绑应用程序放到非 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 问题相同。

似乎是 mkbundled 应用程序在创建 appdomain 时在处理非 ANSI 路径时有错误。

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

关于c# - 在 Windows 上,mkbundle 因链接器错误而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39905982/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com