LudovicRousseau / PCSC

pcsc-lite: PC/SC implementation
https://pcsclite.apdu.fr/
Other
254 stars 107 forks source link

Build issue with Meson not linking libpcsclite against libpthread #200

Closed brad0 closed 1 month ago

brad0 commented 1 month ago

pcsc 2.2.3

When switching our port from autoconf to Meson we noticed that the built shared library for libpcsclite does not link against libpthread which breaks programs dependent on libpcsclite.

LudovicRousseau commented 1 month ago

libpcsc_real is linked against pthread. See https://github.com/LudovicRousseau/PCSC/blob/master/meson.build#L170 But libpcsclite is not because it does not use threads.

What if the error message exactly? Does your application uses pthreads?

brad0 commented 1 month ago

libpcsc_real is linked against pthread. See https://github.com/LudovicRousseau/PCSC/blob/master/meson.build#L170 But libpcsclite is not because it does not use threads.

But it's not. I see that line should do something regarding detecting pthreads from the Meson documentation.

Dynamic Section:
  SONAME      libpcsclite_real.so.0.0
  RELA        0xef8
  RELASZ      0x78
  RELAENT     0x18
  RELACOUNT   0x2
  JMPREL      0xf70
  PLTRELSZ    0x408
  PLTGOT      0xce40
  PLTREL      0x7
  SYMTAB      0x350
  SYMENT      0x18
  STRTAB      0xc0c
  STRSZ       0x2eb
  GNU_HASH    0x968
  HASH        0x9fc
  FINI_ARRAY  0xcce0
  FINI_ARRAYSZ 0x8
  INIT        0xb350
  FINI        0xb370

With the autoconf built pcsc the libraries ARE linked against libpthread.

cc -DHAVE_CONFIG_H -I.    -I/usr/local/include/PCSC -O2 -pipe -I/usr/local/include/PCSC -MT pcsc_scan-pcsc_scan.o -MD -MP -MF .deps/pcsc_scan-pcsc_scan.Tpo -c -o pcsc_scan-pcsc_scan.o `test -f 'pcsc_scan.c' || echo './'`pcsc_scan.c
mv -f .deps/pcsc_scan-pcsc_scan.Tpo .deps/pcsc_scan-pcsc_scan.Po
cc -I/usr/local/include/PCSC -O2 -pipe -I/usr/local/include/PCSC   -o pcsc_scan pcsc_scan-pcsc_scan.o -L/usr/local/lib -lpcsclite
pcsc_scan.c(pcsc_scan-pcsc_scan.o:(main)): warning: sprintf() is often misused, please use snprintf()
ld: error: undefined symbol: pthread_create
>>> referenced by pcsc_scan.c
>>>               pcsc_scan-pcsc_scan.o:(main)

ld: error: undefined symbol: pthread_join
>>> referenced by pcsc_scan.c
>>>               pcsc_scan-pcsc_scan.o:(main)
cc: error: linker command failed with exit code 1 (use -v to see invocation)

From pcsc-tools. I see the pcsc-tools code does use threads. But I don't see any code in the autoconf script to detect the presence of threads.

From rdesktop.

cc -O2 -pipe -Wall -Wextra -I/usr/X11R6/include -I/usr/X11R6/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include/p11-kit-1 -I/usr/local/include/PCSC -I/usr/local/include -I/usr/local/include  -I/usr/X11R6/include -DPACKAGE_NAME=\"rdesktop\" -DPACKAGE_TARNAME=\"rdesktop\" -DPACKAGE_VERSION=\"1.9.0\" -DPACKAGE_STRING=\"rdesktop\ 1.9.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DL_ENDIAN=1 -DHAVE_SYS_SELECT_H=1 -DHAVE_SYS_FILIO_H=1 -DHAVE_LOCALE_H=1 -DHAVE_LANGINFO_H=1 -DHAVE_SYSEXITS_H=1 -DHAVE_XRANDR=1 -DHAVE_XCURSOR=1 -DWITH_SCARD=1 -DWITH_PNP_NOTIFICATIONS=1 -DEGD_SOCKET=\"/var/run/egd-pool\" -DHAVE_LIBSAMPLERATE=1 -DWITH_RDPSND=1 -DRDPSND_LIBAO=1 -DHAVE_DIRENT_H=1 -DHAVE_DIRFD=1 -DHAVE_DECL_DIRFD=1 -DHAVE_ICONV_H=1 -DHAVE_ICONV=1 -DICONV_CONST= -DHAVE_SYS_STATVFS_H=1 -DHAVE_SYS_PARAM_H=1 -DHAVE_SYS_MOUNT_H=1 -DSTAT_STATVFS=1 -DHAVE_STRUCT_STATVFS_F_NAMEMAX=1 -DKEYMAP_PATH=\"/usr/local/share/rdesktop/keymaps/\" -o rdesktop rdesktop.o xwin.o xkeymap.o ewmhints.o xclip.o cliprdr.o ctrl.o rdpsnd.o rdpsnd_dsp.o rdpsnd_libao.o tcp.o asn.o iso.o mcs.o secure.o licence.o rdp.o orders.o bitmap.o cache.o rdp5.o channels.o rdpdr.o serial.o printer.o disk.o parallel.o printercache.o mppc.o pstcache.o lspci.o seamless.o ssl.o utils.o stream.o dvc.o rdpedisp.o scard.o  -L/usr/local/lib -lgmp  -L/usr/X11R6/lib -lXrandr -L/usr/X11R6/lib -lXcursor -L/usr/local/lib -ltasn1 -L/usr/local/lib -lnettle -L/usr/local/lib -lhogweed -L/usr/local/lib -lgnutls -L/usr/local/lib -lpcsclite -L/usr/local/lib -lsamplerate -L/usr/local/lib -lao -liconv  -L/usr/X11R6/lib  -lX11
ctrl.c(ctrl.o:(ctrl_init)): warning: strcpy() is almost always misused, please use strlcpy()
printer.c(printer.o:(printer_enum_devices)): warning: strcat() is almost always misused, please use strlcat()
printer.c(printer.o:(printer_create)): warning: sprintf() is often misused, please use snprintf()
ld: error: undefined symbol: pthread_create
>>> referenced by scard.c
>>>               scard.o:(scard_enum_devices)
>>> referenced by scard.c
>>>               scard.o:(queue_handler_function)
cc: error: linker command failed with exit code 1 (use -v to see invocation)

It looks like libpcsclite not being linked against libpthread like the autoconf build does has exposed two legitimate bugs. It appears each respective downstream project should be linking these bits of code with libpthread, but they're not.

LudovicRousseau commented 1 month ago

Fixed in https://github.com/LudovicRousseau/pcsc-tools/commit/6acb170784b0349b3e43682d0ba1e3131652dc8e

Thanks