Search Unity

Problem building Linux build on Windows.

Discussion in 'Linux' started by jj-steele, Jul 10, 2021.

  1. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    I am getting the following error when building using 2020.3.12.

    Exception: Unity.IL2CPP.Building.BuilderFailedException: clang++: error: unsupported option '-fPIC' for target 'x86_64-pc-windows-msvc'

    any idea what I'm doing wrong?

    I’ve tried building a small test build and that yields without issue, and this main build builds fine in Mono.

    John
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,678
    Hey, do you have a clang++.exe in PATH environment variable by any chance? It looks like wrong one gets picked up: instead of the one from Unity Linux package, the one that exists on your system gets invoked.
     
  3. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    Not that I can see, if I type clang++ at a command prompt it comes back "
    'clang++' is not recognized as an internal or external command,"
    searching for clang++.exe only shows the exe in
    C:\Program Files\Unity\Hub\Editor\......
     
  4. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    If you run the clang++ from windows-x86_64-linux-x86_64
    C:\Users\jjs\AppData\Local\unity3d\cache\sysroots>windows-x86_64-linux-x86_64\llvm-9.0.0-1\bin\clang++ --version
    clang version 9.0.0 (tags/RELEASE_900/final)
    Target: x86_64-pc-windows-msvc
    Thread model: posix
    InstalledDir: C:\Users\jjs\AppData\Local\unity3d\cache\sysroots\windows-x86_64-linux-x86_64\llvm-9.0.0-1\bin

    Surely this wrong?
     
  5. davidbuckley_unity

    davidbuckley_unity

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    6
    What version of the com.unity.toolchain.win-x86_64-linux-x86_64 package do you have installed?
     
  6. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    It is 1.20-preview.
     
  7. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    From the Editor Log this is what it has invoked:-
    Invocation was: Executable: "C:\Users\jjs\AppData\Local\unity3d\cache\sysroots\windows-x86_64-linux-x86_64\llvm-9.0.0-1\bin\clang++.exe"
    Arguments: --sysroot=C:\Users\jjs\AppData\Local\unity3d\cache\sysroots\linux-x86\9.1.0-2.17-v0_608efc24a3b402ec57809211b16a6d32d519f891d4038e1fc8509fe300c395b2-1 -DNET_4_0 -DUNITY_AOT -DIL2CPP_MONO_DEBUGGER_DISABLED -DGC_NOT_DLL -DRUNTIME_IL2CPP -DBASELIB_INLINE_NAMESPACE=il2cpp_baselib -D__linux__ -DLINUX -D_GNU_SOURCE -I"C:\Program Files\Unity\Hub\Editor\2020.3.14f1\Editor\Data\il2cpp\libil2cpp" -I"C:\Program Files\Unity\Hub\Editor\2020.3.14f1\Editor\Data\il2cpp\libil2cpp" -I"C:\Program Files\Unity\Hub\Editor\2020.3.14f1\Editor\Data\il2cpp\external\bdwgc\include" -I"C:\Program Files\Unity\Hub\Editor\2020.3.14f1\Editor\Data\il2cpp\external\xxHash" -I"C:\Program Files\Unity\Hub\Editor\2020.3.14f1\Editor\Data\il2cpp\external\baselib\Include" -I"C:\Program Files\Unity\Hub\Editor\2020.3.14f1\Editor\Data\il2cpp\external\baselib\Platforms\Linux\Include" -I"C:\Program Files\Unity\Hub\Editor\2020.3.14f1\Editor\Data\il2cpp\libil2cpp\pch" -I"D:\RallyRacers\Library\Il2cppBuildCache\StandaloneLinux64\il2cppOutput" --sysroot=C:\Users\jjs\AppData\Local\unity3d\cache\sysroots\linux-x86\9.1.0-2.17-v0_608efc24a3b402ec57809211b16a6d32d519f891d4038e1fc8509fe300c395b2-1 -g -c -fvisibility=hidden -fvisibility-inlines-hidden -fno-strict-overflow -fexceptions -fno-rtti -ffunction-sections -fdata-sections -fPIC -pthread -std=c++11 --sysroot=C:\Users\jjs\AppData\Local\unity3d\cache\sysroots\linux-x86\9.1.0-2.17-v0_608efc24a3b402ec57809211b16a6d32d519f891d4038e1fc8509fe300c395b2-1 -m64 -Wno-null-conversion -O3 -mcx16 -Wno-extern-initializer -Wno-trigraphs -Wno-tautological-compare -Wswitch -Wno-invalid-offsetof -Wno-unused-value -Wno-null-conversion -d2ssa-cfg-jt- "D:\RallyRacers\Library\Il2cppBuildCache\StandaloneLinux64\il2cppOutput\Il2CppCCalculateTypeValues.cpp" -o "D:\RallyRacers\Library\il2cpp_cache\F8578EEA809CBABF3E2A4FAEF67E0F02.o"
     
  8. davidbuckley_unity

    davidbuckley_unity

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    6
    Does it build successfully if you remove the Compiler Additional Arguments you have set? I see '-d2ssa-cfg-jt-' which seems to be specific to VS.
     
  9. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    How would I specify compiler options?
     
  10. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    Just checked and it says "List is empty".
     
  11. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    441
    Do you have the
    IL2CPP_ADDITIONAL_ARGS
    environment variable set to something?

    You can check that by typing
    echo %IL2CPP_ADDITIONAL_ARGS%
    in a command prompt.
     
  12. jj-steele

    jj-steele

    Joined:
    Jul 24, 2012
    Posts:
    34
    No, it isn't set to anything.
     
  13. davidbuckley_unity

    davidbuckley_unity

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    6
    The problem here turned out to be having
    PlayerSettings.additionalIl2CppArgs
    set to
    --compiler-flags=-d2ssa-cfg-jt-
    , which conflicts with the toolchain packages compiler flags.

    IL2CPP takes only the last --compiler-flags option it sees, and these additional options are pasted onto the IL2CPP command line last.

    This option,
    -d2ssa-cfg-jt-
    , is a VS option being used to get around some issues with IL2CPP code generation on Windows, when VS 2019 is being used. It is not needed for compiling to il2cpp for linux, which uses the clang toolchain. In fact, clang will complain if it sees this option.

    See: https://developercommunity.visualstudio.com/t/visual-studio-2019-miscompile-in-release-build/1021935 for a report of the VS 2019/IL2CPP problem. It may be fixed in the latest VS 2019 update (16.10).

    Both the environment variable (
    IL2CPP_ADDITIONAL_ARGS
    ) and this project setting have no concept of target, so the customer needs to manage setting these based on the target they for which they are compiling.There are two ways the customer can do this:1. In the customers' build script they can use
    PlayerSettings.SetAdditionalIl2CppArgs
    when build target is Windows, and clear it for everything else:

    Code (CSharp):
    1.    if (buildTarget == StandaloneWindows64)
    2.         ProjectSettings.SetAdditionalIl2CppArgs("--compiler-flags=d2ssa-cfg-jt-"
    3.     else
    4.         ProjectSettings.SetAdditionalIl2CppArgs("")
    But this will only work for cases where
    -executeMethod
    is used to invoke the build script, and not for the case where the the build is invoked from the Build dialog.2. They can hook
    IPreprocessBuildWithReport
    , and do the same thing, which will work for both the build scripts and the Build dialog:
    Code (CSharp):
    1.    class MyCustomPreprocessBuild: IPreprocessBuildWithReport
    2.     {
    3.         public int callbackOrder { get { return 0; } }        public void OnPreprocessBuild(BuildReport report)
    4.         {
    5.             string addlArgs = "";
    6.             if (report.summary.platform == BuildTarget.StandaloneWindows || report.summary.platform == BuildTarget.StandaloneWindows64)
    7.                 addlArgs = "--compiler-flags=\"-d2ssa-cfg-jt-\"";
    8.             UnityEngine.Debug.Log($"Setting Additional IL2CPP Args = \"{addlArgs}\" for platform {report.summary.platform}");
    9.             PlayerSettings.SetAdditionalIl2CppArgs(addlArgs);
    10.         }
    11.     }
    Alternatively, if they can get the latest VS 2019 (16.10), they may be able to just delete this option.