Try to compiler my NFC ACR122 file

Please I need a help, on this code , I just bought a new NFC device and try to run this code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

 #include <stdio.h>
#include<ctacs/ct_api.h>

 int main(int argc, char *argv[])
 {
     char ret;
 
      unsigned short ctn;
      unsigned short pn;
      unsigned short sad;
      unsigned short dad;
 
      // REQUEST ICC
      unsigned char command[] = { 0x20, 0x12, 0x01, 0x00, 0x00 };
      unsigned short lenc = sizeof(command);
 
      unsigned char response[300];
      unsigned short lenr = sizeof(response);
 
       ctn = 1;
       pn = 1;
 
      // Initialize card terminal
      ret = CT_init(ctn, pn);
      if (ret != OK)
      {
          printf("Error: CT_init failed with error %d\n", ret);
          return 1;
      }
 
      sad = 2; // Source = Host
      dad = 1; // Destination = Card Terminal
 
      // Send command
      ret = CT_data(ctn, (unsigned char*)&dad, (unsigned char*)&sad, lenc, command, &lenr, response);
      if (ret != OK)
          printf("Error: CT_data failed with error %d\n", ret);
      else
      {
          // Display response
          printf("Response: ");
          for (int i = 0; i < lenr; i++)
              printf("%02X ", response[i]);
          printf("\n");
      }
 
      // Close card terminal
      ret = CT_close(ctn);
      if (ret != OK)
          printf("Error: CT_close failed with error %d\n", ret);
 
      return 0;
  }




but this error is showing

/tmp/cc4UxCLi.o: In function `main':
testNFC.cpp:(.text+0x78): undefined reference to `CT_init'
testNFC.cpp:(.text+0xf1): undefined reference to `CT_data'
testNFC.cpp:(.text+0x178): undefined reference to `CT_close'
collect2: ld returned 1 exit status



I guess I may need a library file but don't know which library thanks
I need help please thanks for you time
¿what package?
¿what does it contain?

You could
1
2
3
4
5
6
7
#!/bin/bash

for K in lib*.so; do 
 	if nm -CD "$K" 2>/dev/null | grep CT_init -q; then 
		echo "$K";
	fi;
done
Also try with lib*.a (but it would be just nm -C)
I am try to write application for ACR122 NFC device I have install the Package (libctacs_linux_bin-1.0.0) already and when I try to compiler it it complains that the fucnction are not found

This is the link to the library http://www.acs.com.hk/index.php?pid=product&id=ACR122U for linux
I will much appreciate
First you need to `# ./install.sh' the library

Then to build
$ g++ $(pkg-config --cflags ctacs) -c main.cpp -o main.o
$ g++ main.o $(pkg-config --libs ctacs) -o a.out
(Note: you need only to #include<ct_api.h> as pkg-config takes care of the directory)

If you have issues with that try to specify the whole library name, by instance
$ g++ main.o /whatever/it/is/libctacs_linux_bin-1.0.0/lib64/libctacs.a -o a.out
Last edited on
Thanks your help but I am still confuse of that, can you explain has if u are teaching a novice please thanks
It would be easier if you ask what you don't get.

getting the package (# means `root')
 $ wget http://www.acs.com.hk/drivers/eng/ACR122_LIB-CTAPI_Lnx_100_P.zip
$ unzip ACR122_LIB-CTAPI_Lnx_100_P.zip
$ cd ACR122_LIB-CTAPI_Lnx_100_P/
$ tar xvf libctacs_linux_bin-1.0.0-20110912.tar.bz2
$ cd libctacs_linux_bin-1.0.0/
# ./install.sh 


install would copy the libraries (*.so *.a) to a place where
the programs that want to use them can find them ( /usr/lib/ )
Using the library.
There is the file `/usr/lib/pkgconfig/libctacs.pc' that contains information
about how to compile and link agains the library
1
2
Libs: -L${libdir} -lctacs
Cflags: -I${includedir} -pthread

That tells us that you should compile with
$ g++ -c -pthread main.cpp
And link with
$ g++ main.o -lctacs

Or simply do
$ g++ $(pkg-config --cflags --libs ctacs) main.cpp
pkg-config reads the *.pc file (note that you don't put the lib prefix or the .pc sufix)
then you ask for the compilation flags and the libraries.


Finally, you need to understand that doing -lctacs is simply a shortcut
It's a replacement to /usr/lib/libctacs.so meaning that you could write
$ g++ main.o /usr/lib/libctacs.so


If anything is unclear, please ask.
Topic archived. No new replies allowed.