How to include GTK library for MuJoCo simulation in Visual Studio Code (Windows10)

76 views Asked by At

What I'm trying to do

I'm practicing MuJoCo simulation based on the YouTube lecture by Pranav Bhounsule.

In this lecture, the code for simulation is written in C language, and makefile for running the simulation is provided (as below).

    COMMON=/O2 /MT /EHsc /arch:AVX /I../../include /Fe../../bin/
    LIBS = ../../lib/glfw3dll.lib  ../../lib/mujoco.lib 
    CC = cl

    ROOT = project_name

    all:
        $(CC) $(COMMON) main.c $(LIBS) -o ../../bin/$(ROOT)

    main.o:
    $(CC) $(COMMON) -c main.c

    clean:
    rm *.o ../../bin/$(ROOT)

I have been working in Visual Studio 2022 and it worked fine until now.

Currently, I want to add GUI components by using GTK-3.0 library and I installed GTK-3.0 with vcpkg.

I've practiced some examples of GTK in Visual Studio 2022 and it worked fine.

And now, I'm trying to add GTK libraries in my MuJoCo simulation code so that I can integracte my simulation project in Visual Studio Code (I heard that using VSCode is better cause it is lightweight, versatile, ... and so on compared to IDE like VS2022).

My Project Directory in detail

Basically, my MuJoCo project is constructed as below. In the follwing directory, C:/.../mujoco-2.2.1-windows-x86_64

|-- include
|   |-- GLFW            // include GLFW headers e.g. glfw3.h, ...
|   |-- mujoco          // include mujoco headers e.g. mujoco.h, ...
|-- lib                 // include libraries e.g. glfw3dll.lib, mujoco.lib
|-- myProject
|   |-- project_name
|   |   |-- main.c      // this is the main code for MuJoCo simulation
|   |   |-- makefile    // makefile for complie as shown in above.
|   |   |-- run_win.bat // batch file for executing the simulation

Additionally, I installed GTK libraries using vcpkg in the following directory. C:/.../vcpkg/installed/x64-windows

|-- bin             // include GTK-related .dll files
|-- ...
|-- include         // include GTK-related header files
|   |-- atk-1.0
|   |-- cairo
|   |-- gtk-3.0
|       |-- gdk
|       |-- gtk     // gtk.h, ...
|   |-- ...
|-- lib             // include GTK-related .lib files
|   |-- gdk-pixbuf-2.0
|   |-- glib-2.0
|   |-- ...
|-- ...

Problem Statement

As I mentioned above, I'm trying to include GTK libraries for my MuJoCo project in VSCode. In the main.c, the relating headers are included as follows.

    #include <GLFW/glfw3.h>
    #include <mujoco/mujoco.h>
    #include <gtk-3.0/gdk/gtk.h>

But, when I tired to run the simulation (even without including GTK libraries), error occurred in the terminal such that;

    gcc -c -g main.c ../../lib/glfw3dll.lib ../../lib/mujoco.lib
    main.c:9:10: fatal error: GLFW/glfw3.h: No such file or directory
        9 | #include <GLFW/glfw3.h>
    compilation terminated.

(The similar error occurred for mujoco.h or gtk.h too.)

I guess it even can't find the directory for GLFW and mujoco headers (I don't know why). I've included path for headers in [C/C++ Extension pack: IntelliSense Configurations] - [Include path] as below.

    ${workspaceFolder}/**
    C:\...\mujoco-2.2.1-windows-x86_64\include\**
    C:\...\mujoco-2.2.1-windows-x86_64\lib\**
    C:\...\vcpkg\installed\x64-windows\include\**
    C:\...\vcpkg\installed\x64-windows\lib\**

(I didn't type '...' literally. '...' indicates the middle of the path I omitted. I actually typed all the path.)

I thought I did include the paths for including libraries and headers for GLFW, mujoco, and GTK correctly. But terminal said it can't find such file or directory.

So, I want to ask what did I missed or did wrong and what should I change in order to include GTK libraries and run the simulation correctly.

For Your Information

  • When I practiced GTK examples in VS2022, I included all the .dll files, header files, and .lib files correctly in [Property Manager]-[VC++ Directories, C/C++, Linkger]. -> it worked fine.

  • When I run the simulation in VS2022, I used 'cl' as a complier and 'nmake' for build the code and I typed 'run_win.bat' in the terminal in order to run the simulation. -> it worked fine.

  • In VSCode, I installed MinGW so as to use 'gcc' for a complier and editted batch file as below which build the code using 'mingw32-make'.

    mingw32-make
    SET var=%cd%
    cd ../../bin && quad_leg_floating
    cd %var%
  • In [C/C++ Configurations], I chose [Compiler path] as 'C:/MinGW/bin/gcc.exe', and [IntelliSense mode] as 'windows-gcc-x64'.

As I mentioned previous,

When I practiced MuJoCo simulation in VS2022, with the specified makefile(with cl compiler), I can run the simulation by typing 'run_win.bat' in the terminal which commands 'nmake'.

Now, when I tried to run the same simulation in VSCode, I tried to use gcc as a complier and editted batch file 'mingw32-make' for build, but it didn't work.

I tried to add some settings in 'settings.json' as below, but it didn't work too.

    "C_Cpp.default.includePath": [
        "C:/.../mujoco-2.2.1-windows-x86_64/include/mujoco",
        "C:/.../mujoco-2.2.1-windows-x86_64/include/GLFW"
     ]
1

There are 1 answers

1
Pranav Bhounsule On BEST ANSWER

If you are building a GUI, you can use the gui provided in mujoco, see the file simulate.c

Here is a barebones simulate file that you can modify. https://pab47.github.io/reports/MuJoCo%20UI%20Projectile%20Game.zip