Collect2.exe: error: ld returned 1 exit status *** [.pio\build\teensy40\firmware.elf] Error 1

Hi there!

I know a bunch of people have posted about this, but I’m getting this error and was not able to find any solutions. When trying to build my code, I get no warnings or errors but when linking it fails. This is what the terminal output looks like:

My codebase can be found HERE (GitHub - AnonymousVikram/E80-team27 at newLogger)

Any advice would be greatly appreciated. Thank you!

lib_extra_dirs = ~/Documents/Arduino/libraries

This is not a good idea and should be removed.
Only add libraries to your project that are really needed.

Unfortunately I cannot compile your project. I get the following errors:

In file included from src\Default_Robot.cpp:18:
lib\main/PressureSensor.h:30:31: error: unable to find numeric literal operator 'operator""F'
   30 |   float pressure_cal_slope = -5F;
      |                               ^~
Compiling .pio\build\teensy40\lib372\Adafruit_BusIO\Adafruit_SPIDevice.cpp.o
lib\SD\src\File.cpp: In constructor 'SDLib::File::File(SdFile, const char*)':
lib\SD\src\File.cpp:25:11: warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'class SdFile' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   25 |     memcpy(_file, &f, sizeof(SdFile));
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from lib\SD\src/SD.h:20,
                 from lib\SD\src\File.cpp:15:
lib\SD\src/utility/SdFat.h:151:7: note: 'class SdFile' declared here
  151 | class SdFile : public Print {
      |       ^~~~~~
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_build.cpp: In member function 'char* Adafruit_GPS::build(char*, const char*, const char*, char, bool)':
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_build.cpp:76:10: warning: 'char* strncpy(char*, const char*, size_t)' output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
   76 |   strncpy(p, thisSource, strlen(thisSource));
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_build.cpp:78:10: warning: 'char* strncpy(char*, const char*, size_t)' output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
   78 |   strncpy(p, thisSentence, strlen(thisSentence));
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_build.cpp:593:10: warning: 'sprintf' argument 3 overlaps destination object 'nmea' [-Wrestrict]
  593 |   sprintf(buff, "%s*%02X", buff, cs);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_build.cpp:68:33: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
   68 | char *Adafruit_GPS::build(char *nmea, const char *thisSource,
      |                           ~~~~~~^~~~
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_build.cpp:568:12: warning: 'sprintf' argument 3 overlaps destination object 'nmea' [-Wrestrict]
  568 |     sprintf(nmea, "%s\r\n", nmea);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_build.cpp:68:33: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
   68 | char *Adafruit_GPS::build(char *nmea, const char *thisSource,
      |                           ~~~~~~^~~~
Compiling .pio\build\teensy40\lib77c\Adafruit_Unified_Sensor\Adafruit_Sensor.cpp.o
*** [.pio\build\teensy40\src\Default_Robot.cpp.o] Error 1
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_build.cpp: In member function 'void Adafruit_GPS::addChecksum(char*)':
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_build.cpp:593:10: warning: 'sprintf' argument 3 overlaps destination object 'buff' [-Wrestrict]
  593 |   sprintf(buff, "%s*%02X", buff, cs);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_build.cpp:586:38: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
  586 | void Adafruit_GPS::addChecksum(char *buff) {
      |                                ~~~~~~^~~~
lib\SD\src\utility\SdFile.cpp: In member function 'uint8_t SdFile::open(SdFile*, const char*, uint8_t)':
lib\SD\src\utility\SdFile.cpp:532:15: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
  532 |     dateTime_(&p->creationDate, &p->creationTime);
      |               ^~~~~~~~~~~~~~~~
lib\SD\src\utility\SdFile.cpp:532:15: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
lib\SD\src\utility\SdFile.cpp:532:33: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
  532 |     dateTime_(&p->creationDate, &p->creationTime);
      |                                 ^~~~~~~~~~~~~~~~
lib\SD\src\utility\SdFile.cpp:532:33: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
lib\SD\src\utility\SdFile.cpp: In member function 'uint8_t SdFile::sync(uint8_t)':
lib\SD\src\utility\SdFile.cpp:1155:17: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
 1155 |       dateTime_(&d->lastWriteDate, &d->lastWriteTime);
      |                 ^~~~~~~~~~~~~~~~~
lib\SD\src\utility\SdFile.cpp:1155:17: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
lib\SD\src\utility\SdFile.cpp:1155:36: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
 1155 |       dateTime_(&d->lastWriteDate, &d->lastWriteTime);
      |                                    ^~~~~~~~~~~~~~~~~
lib\SD\src\utility\SdFile.cpp:1155:36: warning: taking address of packed member of 'directoryEntry' may result in an unaligned pointer value [-Waddress-of-packed-member]
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_parse.cpp: In member function 'char* Adafruit_GPS::parseStr(char*, char*, int)':
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_parse.cpp:766:14: warning: 'char* strncpy(char*, const char*, size_t)' specified bound depends on the length of the source argument [-Wstringop-truncation]
  766 |       strncpy(buff, p, len); // or to the end or max capacity
      |       ~~~~~~~^~~~~~~~~~~~~~
.pio\libdeps\teensy40\Adafruit GPS Library\src\NMEA_parse.cpp:765:28: note: length computed here
  765 |       len = min((int)strlen(p), n - 1);
      |                      ~~~~~~^~~

This project seems to be very extensive and contains symbolic links to other repositories in the lib folder.

Can the project be built with the Arduino IDE?
There is a description in the original repository: GitHub - HMC-E80/E80: Files for E80

Line 30 in lib/main/Pressuresensor.h containts an error!
Chage it from
float pressure_cal_slope = -5F;
to
float pressure_cal_slope = -5.0F;

Sorry, the codebase was provided as a starting point, meant for the Arduino IDE. I then migrated to platformIO and wrote a few files to add functionality, so it cannot be built with Arduino anymore.

Also, I believe you might have seen the main branch, rather than the newLogger (the -5F was fixed in the newLogger branch). With that fix, I was able to compile everything, but since then rewrote the logger, resulting in this problem.

After fixing the -5F issue, everything compiles for me (still with a bunch of warnings).

Try a full clean and rebuild the project
image

I tried the full clean and rebuild with the newLogger code, but it still seems to give the same error

You’re right, i cloned the main (default) branch.

I’ll try the newLogger branch…

Yeah I get the same error

in function '_open_r':
(.text._open_r+0x14): undefined reference to '_open'

Unfortunately, I am not familiar with the teensy platform. :pensive:
I hope another expert who knows teensy can help you. :crossed_fingers:

No worries, thank you for your time!

Due to the complexity, I suspect that one of the libraries used is not compatible.

A similar situation also occurred in this thread: Error compiling for Teensy 3.1

Update for anyone who sees this in the future: the issue for me was using fstream. Oversight on my part (coming from C++ for computers), but the Teensy doesn’t have a file system built in so fstream can’t be used. Ended up fixing it by just writing directly using the SD library. (Code has been updated to reflect the changes)