我已经成功编译了libnfc并且示例都正常工作。现在,我正在尝试自己编译其中一个示例,以了解如何执行此操作。
我要编译的文件与libnfc self不在同一个文件夹中。当我编译它时,给我以下错误(和警告):
C:\thesis\libnfc\dev>gcc -m32 test.c -o test -L"C:\thesis\libnfc\libnfc-build\libnfc" -lnfc
In file included from test.c:48:0:
utils/nfc-utils.h:97:14: warning: 'str_nfc_baud_rate' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
C:\Users\xxxx\AppData\Local\Temp\cc2LqPG1.o:test.c:(.text+0x2e): undefined reference to `print_hex_bits'
C:\Users\xxxx\AppData\Local\Temp\cc2LqPG1.o:test.c:(.text+0xaf): undefined reference to `print_hex_bits'
C:\Users\xxxx\AppData\Local\Temp\cc2LqPG1.o:test.c:(.text+0xe8): undefined reference to `print_hex'
C:\Users\xxxx\AppData\Local\Temp\cc2LqPG1.o:test.c:(.text+0x15a): undefined reference to `print_hex'
C:\Users\xxxx\AppData\Local\Temp\cc2LqPG1.o:test.c:(.text+0xa87): undefined reference to `print_hex'
collect2.exe: error: ld returned 1 exit status
这些函数在nfc-utils中定义。我假设这些也被编译成了dll?我把文件夹utils和内容nfc-utils.c和.h放在同一个文件夹中,但这也无济于事。
test.c文件与nfc-anticol.c文件具有相同的内容。
有什么建议吗?
答案 0 :(得分:0)
好的,自己找到了。
我显然忘记在gcc -c步骤中将utils / nfc-utils.c与test.c一起编译。 分两步找到了它。
C:\thesis\libnfc\dev>gcc -m32 test.c utils/nfc-utils.c -c
In file included from test.c:48:0:
utils/nfc-utils.h:97:14: warning: 'str_nfc_baud_rate' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
In file included from utils/nfc-utils.c:37:0:
utils/nfc-utils.h:97:14: warning: 'str_nfc_baud_rate' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
C:\thesis\libnfc\dev>gcc -m32 test.o nfc-utils.o -o test -L"C:\thesis\libnfc\libnfc-build\libnfc" -lnfc
这给出了两个警告,但是当我运行它时,它会起作用。