Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Error when importing .a library packed with emcc

Discussion in 'WebGL' started by wechat_os_Qy08O4uD4os_Q3aM60rRiZU7Y, Oct 17, 2022.

  1. wechat_os_Qy08O4uD4os_Q3aM60rRiZU7Y

    wechat_os_Qy08O4uD4os_Q3aM60rRiZU7Y

    Joined:
    Sep 29, 2022
    Posts:
    7
    Hello, I am trying to import a c++ project that contains 2 cpp files, 2 header files, and two dependency libraries, namely Eigen and igl. The code compiles and runs fine through emcc, however when I pack it into a .a library through emcc and emar and import into unity, this error pops up. Can anyone give me some possible idea on where to look? Thanks

    Code (CSharp):
    1. Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js: undefined symbol: _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE25__init_copy_ctor_externalEPKcm (referenced by top-level compiled C/C++ code)
     
    Last edited: Oct 17, 2022
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,191
  3. wechat_os_Qy08O4uD4os_Q3aM60rRiZU7Y

    wechat_os_Qy08O4uD4os_Q3aM60rRiZU7Y

    Joined:
    Sep 29, 2022
    Posts:
    7
    I have previously looked into this and instead used .a static libraries, and I have successfully imported with this method simple hello functions in unity. It is with a specific build that I have failed.
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,191
    I'm surprised that worked at all but maybe static libraries are somewhat different, since they are static, the IL2CPP linker may simply integrate them.

    However, have you tested this to work across platforms in the browser? If you build a C++ static library, same as with DLLs, the compiled code will be for a specific platform such as Windows, OS X, Linux, Android, iOS, etc. and that code will fail to work on most other platforms.
     
  5. wechat_os_Qy08O4uD4os_Q3aM60rRiZU7Y

    wechat_os_Qy08O4uD4os_Q3aM60rRiZU7Y

    Joined:
    Sep 29, 2022
    Posts:
    7
    Indeed my trial runs was in the browser, since I did pack it with emscripten
     
  6. wechat_os_Qy08O4uD4os_Q3aM60rRiZU7Y

    wechat_os_Qy08O4uD4os_Q3aM60rRiZU7Y

    Joined:
    Sep 29, 2022
    Posts:
    7
    Update: the problem seems to occur when
    1. nlohmann::json::parse is called in the C++ part
    2. when I attempt to use the assignment
    Code (Boo):
    1. std::vector<std::string> vec2 = vec1_ref;
    where vec2 is a vector of strings, and vec1_ref is a reference to a vector of strings passed by reference from function parameters. Either of these two will cause this error in compilation, but I can't seem to find a fix. Can anyone offer some insights?