2

Problem

If I try to compile c-code (from a FMU exported by JModelica) with emcc, I get an error that the header file "gnu/stubs-32.h" was not found.

emcc -I /usr/include/ -I /usr/include/x86_64-linux-gnu/ -I /usr/include/x86_64-linux-gnu/bits/ -I /home/osboxes/Programme/JModelica/include/RuntimeLibrary/ -I /home/osboxes/Programme/JModelica/ThirdParty/FMI/2.0/ BouncingBall.c

Error

/usr/include/x86_64-linux-gnu/gnu/stubs.h:7:11 fatal error: 'gnu/stubs-32.h' file not found

I already tried to provide the compiler with the required header files by installing libc6-dev:i386 . But it will not work because compiling 32-bit software on a 64-bit machine. The guys from emscripten already told me, that there is no working 32-bit version of the emcc compiler available. So I think the only way is to go on with 64-bit...

I found in gnu/stubs.h the file which is responsible for the selection of the wrong header file:

#if !defined __x86_64__
# include <gnu/stubs-32.h>
#endif
#if defined __x86_64__ && defined __LP64__
# include <gnu/stubs-64.h>
#endif
#if defined __x86_64__ && defined __ILP32__
# include <gnu/stubs-x32.h>
#endif

Therefore I conclude that __LP64__ is not defined but should be defined to be able to use the 64-bit header files.

Does anyone has in idea how I am able to compile the c-code with emcc?

Addition (added 16.08.2019)

I started another try:

Compiling without system headers emcc -I /home/osboxes/Programme/JModelica/include/RuntimeLibrary/ -I /home/osboxes/Programme/JModelica/ThirdParty/FMI/2.0/ BouncingBall.c results in this error 'linux/limits.h' file not found.

So I visited the file where 'linux/limits.h' gets included. It is a header file of JModelica with name /../JModelica/include/RuntimeLibrary/jmi_utils.h:

...
#if !defined(NO_FILE_SYSTEM) && (defined(RT) || defined(NRT))
#define NO_FILE_SYSTEM
#endif

#ifndef NO_FILE_SYSTEM    
    #ifdef _WIN32
      #include <windows.h>
      #define JMI_PATH_MAX MAX_PATH
    #else
      #define _GNU_SOURCE
      #include <dlfcn.h>
      #ifdef __APPLE__
        #include <limits.h>
        #define JMI_PATH_MAX PATH_MAX
      #else
        #include <linux/limits.h>
        #define JMI_PATH_MAX PATH_MAX
      #endif
    #endif

    #include <sys/types.h>
    #include <sys/stat.h>
#endif
...

So I defined 'RT' by passing emcc -I /home/osboxes/Programme/JModelica/include/RuntimeLibrary/ -I /home/osboxes/Programme/JModelica/ThirdParty/FMI/2.0/ BouncingBall.c -DRT to the emcc compiler and everything worked without errors.

But what are the variables RT and NRT? Do I have to worry about something by doing that?


My environment:

  • Ubuntu 18.10 (64-bit)
  • JModelica (version r12614)
  • Emscripten (emcc: 1.3820 / clang: 6.0.1 / Target: x86_64-unknown-linux-gnu / selected gcc: /usr/lib/gcc/x86_64-linux-gnu/8)
19leunam93
  • 21
  • 2
  • 1
    I don't think you will be able to compile anything using emscripten with system header files (libc6-dev, doesn't matter it's amd64 nor i386), as someone pointed out in the discussion in the link. Emscripten uses its own libc (it's derived from musl, not even from GNU) because of the browser/WASM environment. – Bumsik Kim Jul 09 '19 at 13:24
  • thank you for your answer, you mean I would need to use the header files of emsctipten instead? Or does that mean that JModelica should provide the required header files for the targeted environment? sry, I am a bloody beginner in compiling code... – 19leunam93 Jul 10 '19 at 15:17
  • I have no experience in JModelica but I'm saying it in general in order to compile an Emscripten app. Though the header `gnu/xxxx.h` sounds like it is GNU-specific stuff but Emscripten system headers are usually located at `emsdk_path/emscripten/incoming/system/` so you can try to look for headers you need. If I were you I would ask JModelica guy if there is a way to ditch GNU stubs headers. – Bumsik Kim Jul 10 '19 at 16:40

2 Answers2

0

First of all, why do you need to explicitly specify system headers?

  • if you just want to link to libc then it should be achieved by default
  • if you need some specific library, then you would have to build it on your own, but for some libraries such as Zlib or SDL you could use Emscripten Ports machinery built into the emcc

On the bitness of the compiler: you probably use the 64-bit emcc compiler (I don't know, whether it exists as a 32-bit executable, I use 64-bit one), but the code it generates is AFAIK inherently 32-bit for now.

Meanwhile, are you tied specifically to JModelica? I'm not familiar with JModelica, but OpenModelica on Linux generates FMUs with the sources directory inside with configure script, so one could probably run something like emconfigure ./configure CC=-m32 (so it will target 32-bit code when accidentally falling back to native compilation from emconfigure, if it is still applicable). Then you could use emmake make, etc., as explained in the Emscripten docs. Hope the license on run-times of OpenModelica is acceptable...

Meanwhile, the Modelica by Example book already uses somehow OpenModelica+Emscripten to provide in-browser simulations.

  • I am using JModelica because OpenModelica does only provide the Euler integration solver for the exported FMUs. This solver is not acceptable in many cases. I will try to compile with your instructions... thx – 19leunam93 Jul 22 '19 at 07:31
  • `emconfigure ./configure CC=-m32` does not work, because there is no `configure` script in the sources folder with JModelica. See the pictures of the sources folder in the FMU of JModelica – 19leunam93 Jul 22 '19 at 09:05
0

The sources folder of the FMU from JModelica contains the c-files only. Thats why I have to grab the header-files from somewhere else.

JModelica: sources folder in the FMU

OpenModelica: sources folder in the FMU

19leunam93
  • 21
  • 2