# Crystal is not continuing after a call to the C library

**URL:** <https://forum.crystal-lang.org/t/crystal-is-not-continuing-after-a-call-to-the-c-library/518>\
**Category:** Help & Support\
**Created:** [March 6, 2019, 11:14am UTC](https://forum.crystal-lang.org/t/crystal-is-not-continuing-after-a-call-to-the-c-library/518 "2019-03-06T11:14:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillaume](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@Guillaume](https://forum.crystal-lang.org/u/Guillaume)\
**Post date:** [March 6, 2019, 11:14am UTC](https://forum.crystal-lang.org/t/crystal-is-not-continuing-after-a-call-to-the-c-library/518/1 "2019-03-06T11:14:42Z")

</div>

Hello,

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?

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [March 6, 2019, 11:57am UTC](https://forum.crystal-lang.org/t/crystal-is-not-continuing-after-a-call-to-the-c-library/518/2 "2019-03-06T11:57:27Z")

</div>

We can’t help you without code.

---

<div class="post-metadata">

**Author:** ![Guillaume](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@Guillaume](https://forum.crystal-lang.org/u/Guillaume)\
**Post date:** [March 6, 2019, 1:47pm UTC](https://forum.crystal-lang.org/t/crystal-is-not-continuing-after-a-call-to-the-c-library/518/3 "2019-03-06T13:47:25Z")

</div>

The code is simple, I bind my library here:

```auto
@[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
end

```

and I call it like this:

```auto
LibSnarc.generateR1cs( "simple_example.arith", "simple_example.in" )
debugger
LibSnarc.VCSetup("simple_example.arith") #, out ts
debugger
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:

```cpp
void VCSetup(char* arithFile/*, char** ts*/)
{
(...)
	std::ofstream o("tsetup.json");
	o << tsetup;
        o.close();
	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.

---

<div class="post-metadata">

**Author:** ![bcardiff](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bcardiff/32/3_2.png) [@bcardiff](https://forum.crystal-lang.org/u/bcardiff)\
**Post date:** [March 6, 2019, 3:59pm UTC](https://forum.crystal-lang.org/t/crystal-is-not-continuing-after-a-call-to-the-c-library/518/4 "2019-03-06T15:59:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Guillaume](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@Guillaume](https://forum.crystal-lang.org/u/Guillaume)\
**Post date:** [March 6, 2019, 4:19pm UTC](https://forum.crystal-lang.org/t/crystal-is-not-continuing-after-a-call-to-the-c-library/518/5 "2019-03-06T16:19:21Z")

</div>

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.
