Progressions.
Code:
$ gcc example2.c
example2.c:2:17: fatal error: pci.h: No such file or directory
compilation terminated.
Oh, didn't find where to include pci.h from, so add a -I path.
Code:
$ gcc -I./lib example2.c
/tmp/ccTriEvn.o: In function `main':
example2.c:(.text+0x3f): undefined reference to `pci_alloc'
example2.c:(.text+0x55): undefined reference to `pci_init'
example2.c:(.text+0x64): undefined reference to `pci_scan_bus'
example2.c:(.text+0x98): undefined reference to `pci_read_block'
example2.c:(.text+0xf2): undefined reference to `pci_cleanup'
collect2: error: ld returned 1 exit status
Better, but missing the pci library. So add the -L and -l options.
Code:
$ gcc -I./lib -L./lib example2.c -lpci
./lib/libpci.a(names-parse.o): In function `id_parse_list':
names-parse.c:(.text+0xcc): undefined reference to `gzgets'
names-parse.c:(.text+0x240): undefined reference to `gzeof'
names-parse.c:(.text+0x45f): undefined reference to `gzeof'
./lib/libpci.a(names-parse.o): In function `pci_load_name_list':
names-parse.c:(.text+0x5d5): undefined reference to `gzopen'
names-parse.c:(.text+0x5ff): undefined reference to `gzclose'
names-parse.c:(.text+0x6b3): undefined reference to `gzopen'
names-parse.c:(.text+0x6d9): undefined reference to `gzerror'
names-parse.c:(.text+0x6e9): undefined reference to `gzclose'
names-parse.c:(.text+0x70e): undefined reference to `zError'
names-parse.c:(.text+0x719): undefined reference to `gzclose'
names-parse.c:(.text+0x73a): undefined reference to `gzclose'
./lib/libpci.a(names-hwdb.o): In function `pci_id_hwdb_lookup':
names-hwdb.c:(.text+0xd4): undefined reference to `udev_hwdb_get_properties_list_entry'
names-hwdb.c:(.text+0xe9): undefined reference to `udev_list_entry_get_next'
names-hwdb.c:(.text+0xfd): undefined reference to `udev_list_entry_get_name'
names-hwdb.c:(.text+0x114): undefined reference to `udev_list_entry_get_value'
names-hwdb.c:(.text+0x249): undefined reference to `udev_new'
names-hwdb.c:(.text+0x256): undefined reference to `udev_hwdb_new'
./lib/libpci.a(names-hwdb.o): In function `pci_id_hwdb_free':
names-hwdb.c:(.text+0x27e): undefined reference to `udev_hwdb_unref'
names-hwdb.c:(.text+0x294): undefined reference to `udev_unref'
collect2: error: ld returned 1 exit status
Now we're missing other dependent libraries as well. Find out where they're resolved.
Obviously, 'gz' and 'udev' are common themes, so pick a symbol from each. Where one is, the rest are pretty sure to be found.
Code:
$ find /lib /usr/lib -name "*.a" | xargs nm --print-file-name --extern-only --defined-only 2>/dev/null | grep gzclose
/usr/lib/x86_64-linux-gnu/libz.a:gzclose.o:0000000000000000 T gzclose
/usr/lib/x86_64-linux-gnu/libz.a:gzread.o:0000000000000ea0 T gzclose_r
/usr/lib/x86_64-linux-gnu/libz.a:gzwrite.o:0000000000001170 T gzclose_w
$ find /lib /usr/lib -name "*.a" | xargs nm --print-file-name --extern-only --defined-only 2>/dev/null | grep udev_hwdb_get_properties_list_entry
On my system, libz is installed, but there is nothing for udev. At this point, you hit google to find out the appropriate package name for the missing library.
So anyway, let's try half of it.
Code:
$ gcc -I./lib -L./lib example2.c -lpci -lz
./lib/libpci.a(names-hwdb.o): In function `pci_id_hwdb_lookup':
names-hwdb.c:(.text+0xd4): undefined reference to `udev_hwdb_get_properties_list_entry'
names-hwdb.c:(.text+0xe9): undefined reference to `udev_list_entry_get_next'
names-hwdb.c:(.text+0xfd): undefined reference to `udev_list_entry_get_name'
names-hwdb.c:(.text+0x114): undefined reference to `udev_list_entry_get_value'
names-hwdb.c:(.text+0x249): undefined reference to `udev_new'
names-hwdb.c:(.text+0x256): undefined reference to `udev_hwdb_new'
./lib/libpci.a(names-hwdb.o): In function `pci_id_hwdb_free':
names-hwdb.c:(.text+0x27e): undefined reference to `udev_hwdb_unref'
names-hwdb.c:(.text+0x294): undefined reference to `udev_unref'
collect2: error: ld returned 1 exit status
Good, -lz resolved all the 'z' functions. All that is needed now is to obtain libudev (or whatever it's called).