.a file not created in Arduino

I followed the steps mentioned in the below link to create .a file.

The library code is below . After, successful compilation, the .a file is not found in build folder, but .p and .o files are created.

// Below is .h file
#ifndef mexco_add_h
#define mexco_add_h

#include "Arduino.h"
class mexco_add
{
  public:
	char addition(char a,char b);
};
#endif


// Below is .cpp file
#include "Arduino.h"
#include "mexco_add.h"

char mexco_add:: addition(char a, char b)
{
  return a+b;
}

// Below is library properties fie
name=mexco_add
version=0.1
author= <******@gmail.com>
maintainer= team <****@gmail.com>
sentence=Library for addition test for Arduino
paragraph=testing addition
category=Other
url=none
architectures=*
dot_a_linkage=true


//below is keywords.txt file
mexco_add KEYWORD1
addition KEYWORD2

// The example used to compile  the library is below:
#include <mexco_add.h>

unsigned int j = 0,k = 0,m = 0;

mexco_add M_add;
void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() 
{
  // put your main code here, to run repeatedly:
  m = M_add.addition(j,k);
}

The compile result in output window Arduino IDE are shown in image below:

Only two file .p and .o are shown in image below.


Where is mistake ?

As a default, the separate .a files are not created for every C source, instead of it the linker combine all object files to a single library .a file

But, in the attached link, .a file has been shown to created for custom library. How to enable this feature of Arduino IDE ? Also, may we use .o files as precompiled files or not ?

Hi @mexcoindia. Something the Seeed Studio tutorial doesn't mention explicitly is that the library must have the "recursive" library layout, where the library code files are stored under the src subfolder of the library instead of the root of the library folder.

When you have "flat" library layout where the code files are directly under the root of the library folder, setting dot_a_linkage=true in the library.properties metadata file has no effect.

So if you were using the "flat" layout, please move the .h and .cpp files to the src subfolder of the library and then compile the sketch again. After doing that, you should find the .a file in the temporary build folder as expected.

Hi everyone, I got .a file created ultimately. I just created src folder in my library and moved .cpp and .h files in src, while all other files (keywords, library) were outside src. It worked. Thanks everyone to read, respond and valued suggestions.

You are welcome. I'm glad it is working now.

Regards,
Per

Hi Dear, I copied the .a file to src/atmega128 folder and renamed to libmexco_add.a. Then, compilation give error that "The platform does not support 'compiler.libraries.ldflags' for ...". May you guide how to resolve it ? I using window10.

If you generated the .a file for the UNO, then that is the wrong folder name. You need to carefully check the value shown in the -mcpu flag of the compilation command, as explained in the tutorial. If you did that, you would see that the correct name for the "{Board Framework Flag}" sub-folder is atmega328p.

I'm going to ask you to post the full verbose output from a compilation.


:exclamation: This procedure is not intended to solve the problem. The purpose is to gather more information.


Please do this:

  1. Select File > Preferences... from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Check the box next to "Show verbose output during: ☐ compilation" in the "Preferences" dialog.
  3. Click the OK button.
  4. Compile a sketch that contains an #include directive for the library, just as you did when you got that "The platform does not support 'compiler.libraries.ldflags'" error.
  5. After the compilation fails you'll see a button on the right side of the orange bar in Arduino IDE: Copy error messages. Click that button.
    This copies the full output to the clipboard.
  6. Open a forum reply here by clicking the Reply button.
  7. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code tags icon on toolbar
  8. Press Ctrl+V.
    This will paste the compilation output into the code block.
  9. Move the cursor outside of the code tags before you add any additional text to your reply.
  10. Click the Reply button to post the output.

In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:

  1. Open any text editor program.
  2. Paste the copied output into the text editor.
  3. Save the file in .txt format.
  4. Open a forum reply here by clicking the Reply button.
  5. Click the "Upload" icon (image) on the post composer toolbar:
    Upload icon on toolbar
    A dialog will open.
  6. In the dialog, select the .txt file you saved.
  7. Click the Open button.
  8. Click the Reply button to publish the post.

Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.

I deleted the .cpp file from src folder. Compiled again with folder name changed to src/atmega328p. It compiled properly.

I'm glad it is working now!

FYI, there is an enhanced functionality if you set the precompiled field of the library.properties file to full instead of true as suggested in the tutorial:

https://arduino.github.io/arduino-cli/0.33/library-specification/#libraryproperties-file-format:~:text=Arduino%20CLI%200.11.0.-,full,--%20(available%20from

  • full - (available from Arduino IDE 1.8.13/arduino-builder 1.5.3/Arduino CLI 0.11.0) If the library provides a precompiled library for the board being compiled for, the source files will not be compiled. If no precompiled library was provided for the selected board, source files are compiled as a fallback. This is useful for precompiling the library to reduce compilation time for specific target hardware, but also providing support for arbitrary boards by compiling the library on demand.

With this setting, you can leave the .cpp file in place in order to allow the library to still compile for boards of other architectures than archives are provided for.

Thanks for your valued guidelines. when the pre-compiled code is to be distributed without source code, are the files: .h, .a, library and keywords.txt files sufficient (complete library folder without .cpp fie) ?

If by "library" you mean library.properties, then yes.

And in fact the keywords.txt file is also optional. This file is quite useful for Arduino IDE 1.x users, but Arduino IDE 2.x doesn't use it at all (it does automated syntax highlighting instead)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.