# Enbedding julia in C++ , how to call savefig function?

**URL:** <https://discourse.julialang.org/t/enbedding-julia-in-c-how-to-call-savefig-function/60648>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 6, 2021, 1:26pm UTC](https://discourse.julialang.org/t/enbedding-julia-in-c-how-to-call-savefig-function/60648 "2021-05-06T13:26:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbertini](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dbertini/32/24806_2.png) [@dbertini](https://discourse.julialang.org/u/dbertini)\
**Post date:** [May 6, 2021, 1:26pm UTC](https://discourse.julialang.org/t/enbedding-julia-in-c-how-to-call-savefig-function/60648/1 "2021-05-06T13:26:48Z")

</div>

Hi  
I am trying to use the julia C interface in orger to call Julia from within my C++ program.  
I would like to save some plots but it does not seems to work.  
Here is a snapshot of the code i used so far:

```julia
{
 // here used jl_main_module not like in the Julia's Doc !
	  jl_function_t *pl_sim = jl_get_function(jl_main_module, "plot_model_sim");
	  jl_function_t *pl_data = jl_get_function(jl_main_module, "plot_model_data");
	  jl_module_t* PLOTS = (jl_module_t *)jl_eval_string("Plots");
	  jl_function_t *save = jl_get_function(PLOTS, "savefig");

	  std::cout << "\n julia: found functions? " << save << ":" << pl_sim << ":" << pl_data << std::endl;
	  
	  jl_value_t *a1 = jl_box_float64(params[0]);
	  jl_value_t *a2 = jl_box_float64(params[1]);
	  jl_value_t *a3 = jl_box_float64(params[2]);
	  jl_value_t *a4 = jl_box_float64(params[3]);
	  jl_value_t *a5 = jl_box_float64(params[4]);
	  
	  jl_value_t *args[5] = {a1 , a2, a3, a4, a5};
	  jl_value_t *plt_data = jl_call(pl_data, args, 5);
	  //jl_eval_string("savefig(\"model_data.png\")");

	  jl_value_t *plt_sim = jl_call(pl_sim, args, 5);
          JL_GC_PUSH1(&plt_sim);
	  //jl_eval_string("savefig(\"model_sim.png\")");

	  jl_value_t *title = jl_eval_string(" \"output.png\" ");
          jl_value_t *out = jl_call2(save, plt_sim, title);
	   
	  std::cout << "\n julia: outputs diagnostics " << std::endl;
	  JL_GC_POP();
	};

```

the call to savefig crashed with the output attached here.

 ![Screenshot at 2021-05-06 15-28-04](https://global.discourse-cdn.com/julialang/original/3X/f/d/fdc41eb8310a6e23dd4d17c5d5d93e6dd577b626.png)
