1

I am using the Arduino IDE 1.6.0, There is a project that has compiled both for Due and Mega on another computer. But on my machine, it only compiles for Due. When compiling for "Mega or Mega 2560", I get the following error:

/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/bin/ld: skipping incompatible /Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/libc.a when searching for -lc /Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/bin/ld: cannot find -lc collect2: error: ld returned 1 exit status Error compiling.

My newbie guess is something is wrong with AVR libraries. But how to solve it? Also could someone please explain what -lc is, which cannot be found? At first glance it looks like an option.

3 Answers 3

1

tldr; -lc means "link with the libc.a library"

The compiler takes your source code (*.c, *.ino) and produces "object" files ending in *.o.

The linker takes those compiled modules and links them all together to make the final executable, linking symbols in one file (such as variable references and function calls) with the definitions in the others (the actual variables and functions). But it also takes libraries - predefined collections of object files - and links those in as well, if necessary.

Libraries are files of the form lib*.a (a is for "archive"), and are distributed by software vendors as easy containers for their modules. The compiler/linker itself also uses them as the implementations for languages features such as printf() and digitalWrite(). The most fundamental library is libc.a - the library containing the standard C implementation.

When you want to get the linker to use a library, you give it the -l option, with the library name appended (not including the lib prefix and .a extension). In short, -lc means "link with the libc.a library".

But if your development machine has support for numerous processors, there will be a number of libc.a files on it - how does the linker know where to look? Another linker option is -L (note uppercase), which defines the directories to look in to find libraries. The linker will look through the directories in turn until it finds the referenced library.

If you attempt to link modules that have been compiled for different processors, you will get linker errors when it does a sanity check. The reason your fix worked is because it now uses the correct directories to find what it is looking for.

1

I think you have included some libraries in the sketch. The problem is that one of the libraries doesn't support the Arduino Mega.

As a solution, I suggest you to comment out the libraries one by one and then try to compile the program. If code runs successfully,try to install that library with other versions. Don't forget to remove the previous library.

0

So what I did that solved the problem was, I downloaded the latest Arduino IDE, titled "Windows ZIP file for non admin install". Then I unzipped the download, and I copied all of the files of the new IDE and pasted them into the old installation. But I did not replace anything. i.e. For each file that existed, I kept the old file.

~400 new files were copied. Now it compiles without error.

BTW since this has been a blind workaround, I will not accept this as the final answer.

2
  • What was the point of copying one version over the top of another version? Why didn't you just upgrade to the new version instead?
    – per1234
    Commented Jul 27, 2017 at 3:05
  • All i remember right now is that the newest update at the time had compatibility issues. I don't remember what it was. That's why I tried to keep the older files.
    – Makan
    Commented Aug 1, 2017 at 13:37

Your Answer

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

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