Crystal is not continuing after a call to the C library



I have a weird issue, when calling a function from my C library, the crystal code execute the function and then quit the program, not execution the code after the library call.
Note that I have other functions in my library that works; I can call them and Crystal continues with the rest. The function in the library is executed properly. I called it also in a test C++ application and there it is working fine.
I don’t know what can I do more to debug this, does somebody have some ideas?


We can’t help you without code.


The code is simple, I bind my library here:

@[Link(ldflags: "#{__DIR__}/../libsnarc.a -lstdc++ -L#{__DIR__}/../ -lsnark -lff -lgmp -lm -lzm -lprocps")]
lib LibSnarc
  # test..
  fun test(name : UInt8*) : Void
  fun generateR1cs(arithFile : UInt8*, inputsFile : UInt8*) : Void
  fun VCSetup(arithFile : UInt8*) : Void   #ts : UInt8**
  fun MyFunction(res : UInt8**) : Bool
  #fun Prove(setup: UInt8*, inputs : UInt8*): UInt8*
  #fun Verify(setup: UInt8*, inputs : UInt8*, proof : UInt8*): Bool
  #fun ProofTest() : Void

and I call it like this:

LibSnarc.generateR1cs( "simple_example.arith",  "" )
LibSnarc.VCSetup("simple_example.arith")   #, out ts
puts "setup is done"

The first call works fine, but not the VCSetup. The program stops after and I never get to the second breakpoint nor I see the “setup is done”. I know the function is working well because it works in a C++ sample application (calling the same library), plus the very last step of VCSetup is to create a file:

void VCSetup(char* arithFile/*, char** ts*/)
	std::ofstream o("tsetup.json");
	o << tsetup;
	return ;

And I see the file is created and correctly filled, from the Crystal call.
Thank you for your support and let me know if you need anything else.


Are you sure that the libsnarc.a is up to date? Because things can go wrong if the commented argument in C was present when compiling libsnarc.a and if the lib in Crystal does not have it.


Yes, I just re-checked and I confirm the library is up-to-date. I was already having the issue with the commented argument, which I removed and made the library to write the result in a file just to have a simpler case and to be sure the library had no problem executing the call.