# \[Solved\] How do I test for a successful C library link?

**URL:** <https://forum.crystal-lang.org/t/solved-how-do-i-test-for-a-successful-c-library-link/1638>\
**Category:** Offtopic\
**Created:** [January 19, 2020, 4:40pm UTC](https://forum.crystal-lang.org/t/solved-how-do-i-test-for-a-successful-c-library-link/1638 "2020-01-19T16:40:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![C-Dev777](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@C-Dev777](https://forum.crystal-lang.org/u/C-Dev777)\
**Post date:** [January 19, 2020, 4:40pm UTC](https://forum.crystal-lang.org/t/solved-how-do-i-test-for-a-successful-c-library-link/1638/1 "2020-01-19T16:40:58Z")

</div>

I’m trying my hand at creating a Crystal binding to DRM (“direct rendering manager”). For now I just want to see if I can link to it. I have one Crystal file that says:

> @[Link(“DRM”)]

I’ve run it through “crystal run” and the “crystal build” binary. I didn’t get any error messages, but I also don’t know if it worked.

Is there some way I can test this?

---

<div class="post-metadata">

**Author:** ![mavu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/mavu/32/213_2.png) [@mavu](https://forum.crystal-lang.org/u/mavu)\
**Post date:** [January 19, 2020, 5:22pm UTC](https://forum.crystal-lang.org/t/solved-how-do-i-test-for-a-successful-c-library-link/1638/2 "2020-01-19T17:22:38Z")

</div>

The only other way I can think of is to use “ldd” if you are on some kind of unix.

ldd should print the shared objects the binary uses.

for example:

```auto
 mavu   master … 4  ~  repo  fip-get  ldd fip-get
	linux-vdso.so.1 (0x00007fff0fbfb000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f7104e6b000)
	libssl.so.1.1 => /lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f7104dd9000)
	libcrypto.so.1.1 => /lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f7104aee000)
	libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f7104a7a000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7104935000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7104914000)
	libevent-2.1.so.6 => /lib/x86_64-linux-gnu/libevent-2.1.so.6 (0x00007f71046bc000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f71046b1000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f71046ac000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7104692000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f71044d2000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f71051be000)

```

---

<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:** [January 19, 2020, 5:29pm UTC](https://forum.crystal-lang.org/t/solved-how-do-i-test-for-a-successful-c-library-link/1638/3 "2020-01-19T17:29:27Z")

</div>

If you don’t use a function from the library, the library is not linked.

I would test the library by actually using it.

---

<div class="post-metadata">

**Author:** ![C-Dev777](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@C-Dev777](https://forum.crystal-lang.org/u/C-Dev777)\
**Post date:** [January 19, 2020, 6:48pm UTC](https://forum.crystal-lang.org/t/solved-how-do-i-test-for-a-successful-c-library-link/1638/4 "2020-01-19T18:48:48Z")

</div>

Well. That would explain it then. \>.\<

Thank you!

---

<div class="post-metadata">

**Author:** ![C-Dev777](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@C-Dev777](https://forum.crystal-lang.org/u/C-Dev777)\
**Post date:** [January 21, 2020, 1:28am UTC](https://forum.crystal-lang.org/t/solved-how-do-i-test-for-a-successful-c-library-link/1638/5 "2020-01-21T01:28:22Z")

</div>

Okay. So here’s the actual corrected code:

> @[Link(“pixman-1”)]
> 
> lib LibPixman  
> fun pixman\_version\_string  
> end
> 
> LibPixman.pixman\_version\_string()

(I switched over to Pixman because I’m not quite ready for something as low-level as libdrm)
