Skip to main content
added 984 characters in body
Source Link

I am making a multi-file arduino project, but the compiler can't recognize a function. I am using the arduino-cli version 0.10.0

This is the error I received

undefined reference to pin_init() collect2.exe: error: ld returned 1 exit status Error during build: exit status 1

This is the command:

arduino-cli compile -b arduino:avr:uno C:\Users\Cioccarelli\Desktop\transmitterCopy\main

main.ino:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

void setup() {
    pin_init();
}

void loop() {}

automation.h:

#pragma once

// This is where the components input pins are stored, they are put here by the add_pin function
byte pinSetup[0];
byte pinSetupSize = 0;

// This function is called in the setup() and it initializes every pin listed in pinSetup[] as input
void pin_init();

automation.cpp:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

extern pinSetup;
extern pinSetupSize;

void pin_init() {
    for (int i = 0; i < pinSetupSize; i++)
        pinMode(i, INPUT);
}

I think this issue might have to do with the fact that I don't completely understand file inclusion, but I haven't found anything useful in my research

On the left is the file setup

Update: today I rebuilt the project with different names and I cut everything which wasn't related to the problem, in hope to identify it.

new main:

#include "C:\Arduino\transmitter\nightmare\nightmare.h"

void setup() {
    pin_init();
}

void loop() {}

new automation.h (nightmare.h):

#pragma once

// This function is called in the setup() and it initializes every pin listed 
//in pinSetup[] as input
void pin_init();

new automation.cpp (nightmare.cpp):

#include "C:\Arduino\transmitter\nightmare\nightmare.h"

void pin_init() {}

new file structure:

enter image description here

I also made a copy and made some changes so it could become a C++ file (substituting the setup() with main() and replace every "byte" type with "int")

I then put it in Visual studio, it compiled perfectly. The arduino IDE gives the same error

I am making a multi-file arduino project, but the compiler can't recognize a function. I am using the arduino-cli version 0.10.0

This is the error I received

undefined reference to pin_init() collect2.exe: error: ld returned 1 exit status Error during build: exit status 1

This is the command:

arduino-cli compile -b arduino:avr:uno C:\Users\Cioccarelli\Desktop\transmitterCopy\main

main.ino:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

void setup() {
    pin_init();
}

void loop() {}

automation.h:

#pragma once

// This is where the components input pins are stored, they are put here by the add_pin function
byte pinSetup[0];
byte pinSetupSize = 0;

// This function is called in the setup() and it initializes every pin listed in pinSetup[] as input
void pin_init();

automation.cpp:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

extern pinSetup;
extern pinSetupSize;

void pin_init() {
    for (int i = 0; i < pinSetupSize; i++)
        pinMode(i, INPUT);
}

I think this issue might have to do with the fact that I don't completely understand file inclusion, but I haven't found anything useful in my research

On the left is the file setup

I am making a multi-file arduino project, but the compiler can't recognize a function. I am using the arduino-cli version 0.10.0

This is the error I received

undefined reference to pin_init() collect2.exe: error: ld returned 1 exit status Error during build: exit status 1

This is the command:

arduino-cli compile -b arduino:avr:uno C:\Users\Cioccarelli\Desktop\transmitterCopy\main

main.ino:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

void setup() {
    pin_init();
}

void loop() {}

automation.h:

#pragma once

// This is where the components input pins are stored, they are put here by the add_pin function
byte pinSetup[0];
byte pinSetupSize = 0;

// This function is called in the setup() and it initializes every pin listed in pinSetup[] as input
void pin_init();

automation.cpp:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

extern pinSetup;
extern pinSetupSize;

void pin_init() {
    for (int i = 0; i < pinSetupSize; i++)
        pinMode(i, INPUT);
}

I think this issue might have to do with the fact that I don't completely understand file inclusion, but I haven't found anything useful in my research

On the left is the file setup

Update: today I rebuilt the project with different names and I cut everything which wasn't related to the problem, in hope to identify it.

new main:

#include "C:\Arduino\transmitter\nightmare\nightmare.h"

void setup() {
    pin_init();
}

void loop() {}

new automation.h (nightmare.h):

#pragma once

// This function is called in the setup() and it initializes every pin listed 
//in pinSetup[] as input
void pin_init();

new automation.cpp (nightmare.cpp):

#include "C:\Arduino\transmitter\nightmare\nightmare.h"

void pin_init() {}

new file structure:

enter image description here

I also made a copy and made some changes so it could become a C++ file (substituting the setup() with main() and replace every "byte" type with "int")

I then put it in Visual studio, it compiled perfectly. The arduino IDE gives the same error

I am making a multi-file arduino project, but the compiler can't recognize a function. I am using the arduino-cli version 0.10.0

This is the error I received

undefined reference to pin_init() collect2.exe: error: ld returned 1 exit status Error during build: exit status 1

This is the command:

arduino-cli compile -b arduino:avr:uno C:\Users\Cioccarelli\Desktop\transmitterCopy\main

main.ino:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

void setup() {
    pin_init();
}

void loop() {}

automation.h:

#pragma once

// This is where the components input pins are stored, they are put here by the add_pin function
byte pinSetup[0];
byte pinSetupSize = 0;

// This function is called in the setup() and it initializes every pin listed in pinSetup[] as input
void pin_init();

automation.cpp:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

extern pinSetup;
extern pinSetupSize;

void pin_init() {
    for (int i = 0; i < pinSetupSize; i++)
        pinMode(i, INPUT);
}

I think this issue might have to do with the fact that I don't completely understand file inclusion, but I haven't found anything useful in my research

On the left is the file setup

I am making a multi-file arduino project, but the compiler can't recognize a function. I am using the arduino-cli version 0.10.0

This is the error

undefined reference to pin_init() collect2.exe: error: ld returned 1 exit status Error during build: exit status 1

This is the command:

arduino-cli compile -b arduino:avr:uno C:\Users\Cioccarelli\Desktop\transmitterCopy\main

main.ino:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

void setup() {
    pin_init();
}

void loop() {}

automation.h:

#pragma once

// This is where the components input pins are stored, they are put here by the add_pin function
byte pinSetup[0];
byte pinSetupSize = 0;

// This function is called in the setup() and it initializes every pin listed in pinSetup[] as input
void pin_init();

automation.cpp:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

extern pinSetup;
extern pinSetupSize;

void pin_init() {
    for (int i = 0; i < pinSetupSize; i++)
        pinMode(i, INPUT);
}

I think this issue might have to do with the fact that I don't completely understand file inclusion, but I haven't found anything useful in my research

On the left is the file setup

I am making a multi-file arduino project, but the compiler can't recognize a function. I am using the arduino-cli version 0.10.0

This is the error I received

undefined reference to pin_init() collect2.exe: error: ld returned 1 exit status Error during build: exit status 1

This is the command:

arduino-cli compile -b arduino:avr:uno C:\Users\Cioccarelli\Desktop\transmitterCopy\main

main.ino:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

void setup() {
    pin_init();
}

void loop() {}

automation.h:

#pragma once

// This is where the components input pins are stored, they are put here by the add_pin function
byte pinSetup[0];
byte pinSetupSize = 0;

// This function is called in the setup() and it initializes every pin listed in pinSetup[] as input
void pin_init();

automation.cpp:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

extern pinSetup;
extern pinSetupSize;

void pin_init() {
    for (int i = 0; i < pinSetupSize; i++)
        pinMode(i, INPUT);
}

I think this issue might have to do with the fact that I don't completely understand file inclusion, but I haven't found anything useful in my research

On the left is the file setup

Source Link

Function declared in another file not recognized (undefined reference to)

I am making a multi-file arduino project, but the compiler can't recognize a function. I am using the arduino-cli version 0.10.0

This is the error

undefined reference to pin_init() collect2.exe: error: ld returned 1 exit status Error during build: exit status 1

This is the command:

arduino-cli compile -b arduino:avr:uno C:\Users\Cioccarelli\Desktop\transmitterCopy\main

main.ino:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

void setup() {
    pin_init();
}

void loop() {}

automation.h:

#pragma once

// This is where the components input pins are stored, they are put here by the add_pin function
byte pinSetup[0];
byte pinSetupSize = 0;

// This function is called in the setup() and it initializes every pin listed in pinSetup[] as input
void pin_init();

automation.cpp:

#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

extern pinSetup;
extern pinSetupSize;

void pin_init() {
    for (int i = 0; i < pinSetupSize; i++)
        pinMode(i, INPUT);
}

I think this issue might have to do with the fact that I don't completely understand file inclusion, but I haven't found anything useful in my research

On the left is the file setup