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

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:


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?

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:

 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)

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

I would test the library by actually using it.


Well. That would explain it then. >.<

Thank you!

Okay. So here’s the actual corrected code:


lib LibPixman
fun pixman_version_string


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

1 Like