Error compiling cpp file

Discussion in 'Simulation' started by Gautam, May 16, 2017.

  1. Hi,
    I am trying to compile a file having MLP_Basic.xml model for simulation but I am getting these errors, I am using 1.5 version on OSX.

    Code:
    Undefined symbols for architecture x86_64:
      "_mj_deleteData", referenced from:
          _main in g-625ea2.o
      "_mj_deleteModel", referenced from:
          _main in g-625ea2.o
      "_mj_loadXML", referenced from:
          _main in g-625ea2.o
      "_mj_makeData", referenced from:
          _main in g-625ea2.o
      "_mj_step", referenced from:
          _main in g-625ea2.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation
     
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    You cannot compile an XML file. This is a model which which is loaded at runtime.

    Looking at the errors, my guess is that you did not link the mujoco dynamic library in your project, and the linker cannot find the functions you are trying to call from your code. Look at the makefile in the sample directory in the MuJoCo distribution; it shows how to compile and link with mujoco.
     
  3. The make file in the sample directory is a .exe file and there is no mention of how to compile and link with mujoco. Another question is how can I run OpenAI models because they have used 1.3 version and Mac with NVM disks can only run 1.5 version as you had mentioned before so unable to get a good grasp since I have no example to test with like perform some simulations.
     
  4. Emo Todorov

    Emo Todorov Administrator Staff Member

    makefile is a plain text file. The command-line tool 'make' uses this file to compile and link all the code samples.

    There is no way to run MuJoCo prior to 1.50 on a Mac with NVMs disk and a hardware-locked activation key (as in trial and personal licenses). You could either update the OpenAI models to 1.50, or if you have an institutional license (which is unlocked) that will also work.
     
  5. Ok but I am trying to run this code and getting the above errors, I ran the make file as you instructed here is the code

    Code:
    #include "mujoco.h"
    #include "stdio.h"
    
    char error[1000];
    mjModel* m;
    mjData* d;
    
    int main(void)
    {
     
       m = mj_loadXML("MPL_Basic.xml", NULL, error, 1000);
       if( !m )
       {
          printf("%s\n", error);
          return 1;
       }
    
       d = mj_makeData(m);
    
       while( d->time<10 )
          mj_step(m, d);
       mj_deleteData(d);
       mj_deleteModel(m);
    
       return 0;
    }
    
     
  6. Emo Todorov

    Emo Todorov Administrator Staff Member

    This should work, assuming you link with the mujoco dynamic library and the linker is able to find it.

    Does the makefile work on your system? If it does, try replacing one of the code samples with your code. If the makefile does not work, then something on your system is messed up...
     
  7. Hmmm I ran the make file and did some debugging but unable to find the error