Visual Studio 17.4.x和17.5.x无法编译Android动态共享库项目(C++)

ifsvaxew  于 2023-04-07  发布在  Android
关注(0)|答案(1)|浏览(86)

我试图在Visual Studio 17.3.4中编译良好的解决方案中编译项目,但在Visual Studio 17.4.x和17.5.x中编译失败。我使用的是Windows 11。解决方案如下:
https://github.com/hyvanmielenpelit/GnollHack
构建说明在这里:
https://github.com/hyvanmielenpelit/GnollHack/wiki/Build-Instructions-for-Android-Version-on-Windows
该解决方案具有动态共享库(Android)项目C++中名为gnollhackdroid,编译成.so库,尝试重建项目时,首先编译失败,因为没有安装NDK(即使它应该是)。手动安装Android NDK后(任何版本)并在跨平台C++选项中设置正确的路径,项目无法编译,并显示以下错误消息(此处使用ndk-r16 b):

6>C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r16b\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\ld: cannot find crtbegin_so.o: No such file or directory
6>C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r16b\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\ld: cannot find -lm
6>C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r16b\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\ld: cannot find -lc
6>C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r16b\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\ld: cannot find -llog
6>C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r16b\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\ld: cannot find -landroid
6>C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r16b\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\ld: cannot find -ldl
6>C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r16b\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\ld: cannot find -lc
6>C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r16b\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\ld: cannot find -ldl
6>C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r16b\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\ld: cannot find crtend_so.o: No such file or directory
6>clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Application Type\Android\3.0\Android.Common.targets(125,5): error MSB6006: "clang.exe" exited with code 1.
6>Done building project "gnollhackdroid.vcxproj" -- FAILED.

如果查看报告的目标文件,则有问题的MSBuild命令为:

<ClangLink BuildingInIDE = "$(BuildingInsideVisualStudio)"
           GNUMode="$(GNUMode)"
           ClangVersion="$(ClangVersion)"
           MSVCErrorReport="$(MSVCErrorReport)"

           Sources="@(Link)"
           AdditionalLibraryDirectories="%(Link.AdditionalLibraryDirectories)"
           AdditionalOptions="%(Link.AdditionalOptions)"
           AdditionalDependencies="%(Link.AdditionalDependencies)"
           FunctionBinding="%(Link.FunctionBinding)"
           ForceSymbolReferences="%(Link.ForceSymbolReferences)"
           GenerateMapFile="%(Link.GenerateMapFile)"
           GccToolChain="$(GccToolchainPrebuiltPath)"
           IncrementalLink="%(Link.IncrementalLink)"
           IgnoreSpecificDefaultLibraries="%(Link.IgnoreSpecificDefaultLibraries)"
           LibraryDependencies="%(Link.LibraryDependencies)"
           LinkDLL="%(Link.LinkDLL)"
           NoExecStackRequired="%(Link.NoExecStackRequired)"
           DebuggerSymbolInformation="%(Link.DebuggerSymbolInformation)"
           OptimizeForMemory="%(Link.OptimizeForMemory)"
           OutputFile="$(LinkOutputFile)"
           Relocation="%(Link.Relocation)"
           SharedLibrarySearchPath="%(Link.SharedLibrarySearchPath)"
           ShowProgress="%(Link.ShowProgress)"
           Soname="%(Link.Soname)"
           Sysroot="$(SysrootLink)"
           TargetArch="$(ClangTarget)"
           UnresolvedSymbolReferences="%(Link.UnresolvedSymbolReferences)"
           Version="%(Link.Version)"
           VerboseOutput="%(Link.VerboseOutput)"
           WholeArchiveBegin="%(Link.WholeArchiveBegin)"
           WholeArchiveEnd="%(Link.WholeArchiveEnd)"

           MinimalRebuildFromTracking="%(Link.MinimalRebuildFromTracking)"
           TrackFileAccess="$(TrackFileAccess)"
           TrackedOutputFilesToIgnore ="@(LinkTrackedOutputFilesToIgnore)"
           TrackerLogDirectory="$(TLogLocation)"
           TLogReadFiles="@(LinkTLogReadFiles)"
           TLogWriteFiles="@(LinkTLogWriteFiles)"
           ToolExe="$(ClangToolExe)"
           ToolPath="$(ClangToolPath)"
           ToolArchitecture="$(LinkToolArchitecture)"
           TrackerFrameworkPath="$(LinkTrackerFrameworkPath)"
           TrackerSdkPath="$(LinkTrackerSdkPath)"
           EnableExecuteTool="$(ClangEnableExecuteTool)"
>
  <Output TaskParameter="SkippedExecution" PropertyName="LinkSkippedExecution" />
</ClangLink>

显然ClangLink由于某种原因失败了。我能做些什么来使它编译吗?编译问题始于Visual Studio 17.4.0,并在Visual Studio 17.5.1中继续存在。
谢谢你的帮助!

vyswwuz2

vyswwuz21#

这个问题似乎在Visual Studio 17.5.3中得到了解决。

相关问题