title: Undefined symbols in .so after compiling despite supplying libs
body: <p>Attempting to compile .so from hidapi's linux/hid.c but not very experienced with tasks of this nature. Shared lib has undefined symbols but I don't know why they are being left undefined.</p>
  <p>Using said .so from my program gets straightforward error:</p>
  <blockquote>
  <p>symbol lookup error: libhid.so: undefined symbol: udev_new</p>
  </blockquote>
  <p>Using a modified version of hidapi's linux makefile:</p>
  <pre><code>all: hidtest
  
  CC       ?= gcc
  CFLAGS   ?= -Wall -fPIC -c -g
  
  CXX      ?= g++
  CXXFLAGS ?= -Wall -fPIC -g
  
  COBJS     = hid.o
  CPPOBJS   = ../hidtest/hidtest.o
  OBJS      = $(COBJS) $(CPPOBJS)
  LIBS      = `pkg-config libudev --libs`
  INCLUDES ?= -I../hidapi `pkg-config libudev --cflags`
  
  
  hidtest: $(OBJS)
      $(CXX) $(CXXFLAGS) $(LDFLAGS) $^ $(LIBS) -o hidtest
  
  $(COBJS): %.o: %.c
      $(CC) $(CFLAGS) -c $(INCLUDES) $&lt; -o $@
  
  $(CPPOBJS): %.o: %.cpp
      $(CXX) $(CXXFLAGS) -c $(INCLUDES) $&lt; -o $@
  
  clean:
      rm -f $(OBJS) hidtest
  
  .PHONY: clean
  </code></pre>
  <p>...which is then built to .so:</p>
  <blockquote>
  <p>gcc -shared <code>pkg-config libudev --libs</code> -o libhid.so hid.o</p>
  </blockquote>
  <p>... my pkg-config output is:</p>
  <pre><code>$ pkg-config libudev --libs
  -ludev -lrt
  </code></pre>
  <p>Confirming the undefined symbols:</p>
  <blockquote>
  <p>nm libhid.so | grep udev</p>
  <p>000000000000181f t copy_udev_string</p>
  <pre><code>             U udev_device_get_devnode
               U udev_device_get_parent_with_subsystem_devtype
               U udev_device_get_sysattr_value
               U udev_device_new_from_devnum
               U udev_device_new_from_syspath
               U udev_device_unref
               U udev_enumerate_add_match_subsystem
               U udev_enumerate_get_list_entry
               U udev_enumerate_new
               U udev_enumerate_scan_devices
               U udev_enumerate_unref
               U udev_list_entry_get_name
               U udev_list_entry_get_next
               U udev_new
               U udev_unref
  </code></pre>
  </blockquote>
  <p>And udev deps don't show up in the .so:</p>
  <pre><code>$ldd libhid.so   
  linux-vdso.so.1 =&gt; (0x00007ffffcffe000) 
  libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc9d03a3000)
  /lib64/ld-linux-x86-64.so.2 (0x00007fc9d099e000)
  </code></pre>
  <p>Thank you</p>