0

I am working on a project which includes Arduino and a fingerprint scanner. It is completely based on embedded system. But then, I have downloaded a library for the fingerprint scanner. When I run the program I get an error which maps to the cpp file of the library file. See below to see the error and the library file.

Error

FPS_GT511C3\FPS_GT511C3.c.cpp.o: In function Command_Packet::GetPacketBytes()': C:\Users\Dipti\Documents\Arduino\libraries\FPS_GT511C3/FPS_GT511C3.c.cpp:17: undefined reference tooperator new[](unsigned int)' FPS_GT511C3\FPS_GT511C3.c.cpp.o: In function FPS_GT511C3::GetResponse()': C:\Users\Dipti\Documents\Arduino\libraries\FPS_GT511C3/FPS_GT511C3.c.cpp:735: undefined reference tooperator new[](unsigned int)' collect2.exe: error: ld returned 1 exit status

Library File (CPP)

byte* packetbytes= new byte[12];

byte* resp = new byte[12];

10
  • 1
    Not sure if having your files having an extension of .c.cpp would confuse things, it they're C++ it'd be more conventional if they were just .cpp.
    – PeterJ
    Oct 7, 2015 at 10:27
  • No. That doesn't make any difference because it is just the file name with .cpp extension.
    – Abel Luke
    Oct 7, 2015 at 10:29
  • 2
    Do you have a typedef for byte somewhere in scope at that location? byte is not a fundamental type and is usually typedef'ed to char or unsigned char. Oct 7, 2015 at 11:08
  • What version of the IDE are you using?
    – Majenko
    Oct 7, 2015 at 16:17
  • I am using Arduino IDE 1.6.5. But then, I tried it with different version of IDE like 1.0.5, 1.0.6. It still shows the same problem. @Majenko
    – Abel Luke
    Oct 8, 2015 at 6:24

1 Answer 1

1

The core of the problem is that the code is being compiled as C and not C++.

The error says 'new[]' is undefined at the link stage. This is because the linker is not pulling in the C++ standard libraries. The built-in function new[] it doesn't exist in C.

The filename FPS_GT511C3.c.cpp is the elephant in the room. You could consider renaming it (and others) to FPS_GT511C3.cpp. Although the plain Arduino IDE does not really have a problem with building them.

Another option might be to modify the new[] (and delete[]) for C's malloc() and free(). However this is only appropriate for the allocation of simple types (byte, int, etc). If the code also allocates objects, it's not possible to simply swap these functions out since C++ (default) initialisation is be going on.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.