Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong lib/include path was used in x86 or AnyCPU #29

Closed
Executor-Cheng opened this issue Aug 29, 2020 · 3 comments · Fixed by #32
Closed

Wrong lib/include path was used in x86 or AnyCPU #29

Executor-Cheng opened this issue Aug 29, 2020 · 3 comments · Fixed by #32

Comments

@Executor-Cheng
Copy link
Contributor

Executor-Cheng commented Aug 29, 2020

DNNE: v1.0.7
The following command generated by building solution in VS will cause LNK2019:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\bin\Hostx64\x86\cl.exe" /Od /LDd /TC /MT /GS /Zi /D DNNE_ASSEMBLY_NAME=CoreExportTest /D DNNE_COMPILE_AS_SOURCE /I "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\include" /I "C:\Users\user\.nuget\packages\dnne\1.0.7\tools\platform" /I "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Host.win-x64\5.0.0-preview.8.20407.11\runtimes\win-x64\native" /I "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared" /I "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um" /I "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt" "F:\Projects\CoreExportTest\CoreExportTest\obj\x86\Debug\net5.0\dnne\CoreExportTest.g.c" "C:\Users\user\.nuget\packages\dnne\1.0.7\tools\platform\platform.c"  /link /DLL /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\lib\x86" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\um\x86" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\ucrt\x86" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Host.win-x64\5.0.0-preview.8.20407.11\runtimes\win-x64\native\libnethost.lib" Advapi32.lib /IGNORE:4099 /IMPLIB:"F:\Projects\CoreExportTest\CoreExportTest\obj\x86\Debug\net5.0\dnne\bin\CoreExportTestNE.lib" /OUT:"F:\Projects\CoreExportTest\CoreExportTest\obj\x86\Debug\net5.0\dnne\bin\CoreExportTestNE.dll"
@AaronRobinsonMSFT
Copy link
Owner

@Executor-Cheng This is because the x86 compiler is being requested, but the 64-bit version of nethost is being requested (i.e. ...\win-x64\native\libnethost.lib). See https://github.com/AaronRobinsonMSFT/DNNE#generating-a-native-binary-using-the-dnne-nupkg for how to target a specific runtime bitness in the project.

@Executor-Cheng
Copy link
Contributor Author

Thanks for your early reply.
Yeah I could build the project successfully by using --runtime win-x86 flag in dotnet CLI, my question is when I build the project via build menu, or using dotnet build without the --runtime flag, it seems that the 64-bit version of nethost is always being requested, regardless of the platform in the configuration manager, or the RuntimeIdentifiers property in csproj.
1
2

@AaronRobinsonMSFT
Copy link
Owner

@Executor-Cheng I finally got to the bottom of this issue. The cause is because from within Visual Studio the default build is running as 32-bit, but the default NETCoreSdkRuntimeIdentifier property is win-x64. The result is we select the win-x64 version of hostfxr.lib to build against, but determine we are in a 32-bit build because of pointer size:

private static bool Is64BitTarget(string arch)
{
return arch.ToLower() switch
{
"x64" => true,
"amd64" => true,
"x86" => false,
_ => IntPtr.Size == 8,
};
}

This shouldn't be too hard to fix, but it is annoying.

Thanks for reporting the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants