crossmax crossmax - 10 months ago 56
C Question

Developing with libpcsclite error compiling (undefined)

Im trying to test a sample PCSC application on Linux that I've seen on the web http://ludovicrousseau.blogspot.com.es/2010/04/pcsc-sample-in-c.html

This application use libpsclite library that I installed with apptitude install libpcsclite-dev.

Why I get references undefined error when compile it?

gcc -I/usr/include/PCSC -lpcsclite sample.c -o sample/tmp/ccY4bNdm.o: En la función

main':
sample.c:(.text+0x9b): referencia a
SCardEstablishContext' sin definir
sample.c:(.text+0xb2): referencia a
pcsc_stringify_error' sin definir
sample.c:(.text+0xf8): referencia a
SCardListReaders' sin definir
sample.c:(.text+0x10f): referencia a
pcsc_stringify_error' sin definir
sample.c:(.text+0x171): referencia a
SCardConnect' sin definir
sample.c:(.text+0x188): referencia a
pcsc_stringify_error' sin definir
sample.c:(.text+0x1b7): referencia a
g_rgSCardT0Pci' sin definir
sample.c:(.text+0x1bd): referencia a
g_rgSCardT0Pci' sin definir
sample.c:(.text+0x1cc): referencia a
g_rgSCardT1Pci' sin definir
sample.c:(.text+0x1d2): referencia a
g_rgSCardT1Pci' sin definir
sample.c:(.text+0x21f): referencia a
SCardTransmit' sin definir
sample.c:(.text+0x236): referencia a
pcsc_stringify_error' sin definir
sample.c:(.text+0x2e5): referencia a
SCardTransmit' sin definir
sample.c:(.text+0x2fc): referencia a
pcsc_stringify_error' sin definir
sample.c:(.text+0x37b): referencia a
SCardDisconnect' sin definir
sample.c:(.text+0x392): referencia a
pcsc_stringify_error' sin definir
sample.c:(.text+0x3c0): referencia a
SCardFreeMemory' sin definir
sample.c:(.text+0x3d7): referencia a
pcsc_stringify_error' sin definir
sample.c:(.text+0x3fa): referencia a
SCardReleaseContext' sin definir
sample.c:(.text+0x411): referencia a `pcsc_stringify_error' sin definir
collect2: error: ld returned 1 exit status

Thanks for any help received!!

Answer Source

Just for reference. It seems that the makefile that is provided in that link is broken (at least for me). This is a working makefile for me:

# Linux
PCSC_CFLAGS := $(shell pkg-config --cflags libpcsclite)
LDLIBS := $(shell pkg-config --libs libpcsclite)

# Mac OS X
#PCSC_CFLAGS := -framework PCSC

CFLAGS += $(PCSC_CFLAGS)

sample: sample.c

clean:
    rm -f sample