Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

emscripten linker flags

Discussion in 'Web' started by sdc-unity3d, Jun 19, 2015.

  1. sdc-unity3d

    sdc-unity3d

    Joined:
    Jun 15, 2015
    Posts:
    6
    Hi!
    I have a compiled to bitcode library that I need to use in my Unity3d plugin.
    On a sample C++ project, compiled with emscripten and linked against this lib it works flaweslly.
    How to customize emscripten linker undo unity for my webgl project?

    Thanks!
     
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    If your library is a bc file, I think you should be able to just add it to your assets folder, and it should automatically be passed to the emscripten linker.
     
  3. sdc-unity3d

    sdc-unity3d

    Joined:
    Jun 15, 2015
    Posts:
    6
    Hi,
    I built the .bc file and put them on my asset folder for webgl
    /Assets/Plugins/WebGL/CWrapper.bc

    but the compilation process fail in Unity, with the message:

    Failed running python "/Applications/Unity/Unity.app/Contents/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/emcc" @"/Users/daniel/local/proys/builds/git/pvisci/Unity/Arteria/Assets/../Temp/emcc_arguments.resp"

    stdout:
    stderr:
    warning: ignoring debug info with an invalid version (2) in /Users/daniel/local/proys/builds/git/pvisci/Unity/Arteria/Assets/Plugins/WebGL/CWrapper.bc
    /Applications/Unity/Unity.app/Contents/PlaybackEngines/WebGLSupport/BuildTools/Emscripten_FastComp_Mac/llvm-link: linked module is broken!
    Traceback (most recent call last):
    File "/Applications/Unity/Unity.app/Contents/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/emcc", line 1225, in <module>
    shared.Building.link(linker_inputs, in_temp(target_basename + '.bc'), force_archive_contents=len([temp for i, temp in temp_files if not temp.endswith(STATICLIB_ENDINGS)]) == 0)
    File "/Applications/Unity/Unity.app/Contents/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/tools/shared.py", line 1395, in link
    assert os.path.exists(target) and (output is None or 'Could not open input file' not in output), 'Linking error: ' + output
    AssertionError: Linking error:

    UnityEditor.HostView:OnGUI()

    The first warning (and the content in emcc_arguments.resp) confirm that Jose is using it.
    But I can understand yet why emcc fail.

    By the way, I can use the CWrapper.bc file to generate a valid JS file, using emscripten (emcc -o CWrapper.js CWrapper.bc) so, I can't found why emscripten are failing when is invoke from Unity.

    I must take some extra consideration when I'm building e .bc file for Unity?
    Thanks!
     
  4. sdc-unity3d

    sdc-unity3d

    Joined:
    Jun 15, 2015
    Posts:
    6
    Hi, was my mistake.
    The .bc file was wrong. Now I built a static library .a, and works fine on Unity.
     
  5. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Seems you figured it out.

    But, for future reference: the llvm bc format is not locked between emscripten versions and may not be compatible (which can result in linker errors when used with mismatching versions). So when you want to use bc files, always use the emscripten version supplied with Unity.

    Not sure, but that might also apply to .a files.
     
  6. sdc-unity3d

    sdc-unity3d

    Joined:
    Jun 15, 2015
    Posts:
    6
    Hi Again,

    Everything worked well with many 3rd party bitcoded libraries.

    But now, I need to debug one that is crashing (it has some algorithms). I have the C source code, and I compiled with -g4 flag (for source maps).
    The problem is that I don't know how to force Unity compiles and links everything with -g4 (I've saw that emcc_arguments.resp file and it contains a -g) so the final .js contains a source map (obviously, I have the source of my library).

    Any help would be appreshiated
    Thanks
     
  7. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    You can call this (undocumented and unsupported) API in editor script code to add agruments to the emscripten "link" command line used to generate the final js:

    Code (csharp):
    1.  
    2. PlayerSettings.SetPropertyString("emscriptenArgs","-g4", BuildTargetGroup.WebGL);
    3.  
     
  8. sdc-unity3d

    sdc-unity3d

    Joined:
    Jun 15, 2015
    Posts:
    6
    Tryied that but on the emcc_arguments.resp mixes both -g and -g4. Is this ok?
     
  9. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    I believe that whatever comes last on the command line should be authoritative.
     
  10. sdc-unity3d

    sdc-unity3d

    Joined:
    Jun 15, 2015
    Posts:
    6
    I can confirm that i doesn't take the last. On the emcc_arguments.resp file contains first the -g and then the -g4 argument. The build takes only the -g . Any help?

    Thanks
     
  11. Lszt

    Lszt

    Joined:
    Sep 28, 2015
    Posts:
    38
    Did you tried to add an empty line at the end of your file ?
    Depending on how the file is parsed, sometimes the last line of the file could be excluded.
     
  12. rickomax

    rickomax

    Joined:
    Jun 11, 2013
    Posts:
    683
    Hi. I'm having the same kind of problem.

    I've compiled a Emscripten custom library (.A file, tried renaming to .BC too), putted it on "WebGL/Plugins" folder
    I already have the [DllImport("__Internal")] wrapper class ready.

    But Unity is generating "dummy" functions on the place of the custom library functions, like this:
    Code (JavaScript):
    1.   function _aiImportFile() {
    2.   Module['printErr']('missing function: aiImportFile'); abort(-1);
    3.   }
    Any tip?

    (Using Unity 5.6.2f1)