[SOLVED] Function Prototypes Not Created ("<function> not defined in scope")

Hello,

I am compiling a .ino for a project. When compiling it under Windows (IDE 1.6.13) it compiles successfully. When compiling it under Linux (1.8.1 and 1.6.13), I receive numerous errors related to missing definitions.

The solution - in normal C/C++ - is to create a function prototype or move the definition above the lines that use it. However, Arduino should preprocess sketch files so that this is done already. And, as noted, the same version of the IDE does not have the error when run under Windows.

There's a number of posts on the forum asking questions about the same subject. They may be this same issue. Is it platform specific? Will it be fixed?

Reference: function not declared in scope - Syntax & Programs - Arduino Forum

You have provided no information about your issue.
No code, and no error output.
So it is impossible for anyone to comment much about your issue.

The key is to pay close attention to the actual errors as they are telling you what is wrong.
The most important information is the first error.
In some cases it is the IDE, but in some cases it is bad code that is causing the issue.

When I see/hear things working on Windows but not on Linux then one of the first things that comes to mind is bad code.
I have seen many cases where code will have incorrect spelling of file names (using the wrong case)
and using backwards slashes in file names. While this is wrong, it will still work on Windows.
Backwards slashes are not to be used in file/path names including on Windows.

The only way to know if it is an IDE issue is to look at the error and then go look the .cpp file generated to see if the IDE created a broken .cpp file.
While the IDE has been known to do this, it doesn't do it very often anymore.

Delta_G:
What happens when you rely on the IDE to do the thinking for you is that sometimes it thinks wrong and puts the prototypes in the wrong place. The obvious fix is to not rely on the IDE to generate them for you.

There is no way that I now of to completely disable the IDE from doing some prototype or other "magic" since it converts the .ino file to a .cpp file for compilation.
There are some versions of the IDE that you simply need to avoid to do broken protype issues that you cannot work around even if you do your own prototypes.
Some IDEs will misinsert the #include <Arduino.h> and break things.
There have been many prototyping issues over the years but by far the worst I saw was was in IDE 1.6.6
But with recent IDEs like 1.6.9 and newer, most of those issues are now gone now there is a separate builder program that uses the actual C preprocessor to do some of the work.

--- bill

bperrybap:
You have provided no information about your issue.
No code, and no error output.
So it is impossible for anyone to comment much about your issue.

The key is to pay close attention to the actual errors as they are telling you what is wrong.
The most important information is the first error.
In some cases it is the IDE, but in some cases it is bad code that is causing the issue.

When I see/hear things working on Windows but not on Linux then one of the first things that comes to mind is bad code.
I have seen many cases where code will have incorrect spelling of file names (using the wrong case)
and using backwards slashes in file names. While this is wrong, it will still work on Windows.
Backwards slashes are not to be used in file/path names including on Windows.

The only way to know if it is an IDE issue is to look at the error and then go look the .cpp file generated to see if the IDE created a broken .cpp file.
While the IDE has been known to do this, it doesn't do it very often anymore.

If a more verbose version of the message is required please check the link I included. Here is a test case:

void loop() {
    func();
}

void func() {
}

The compiler says "func" is not defined in the scope it is used. That is all there is to the error. The only thing I can assume is it is, in fact, an error with the Linux version of the IDE. I've since created a virtual machine and used IDE 1.8.1 to compile the code successfully under Windows. I suppose that will have to be my solution until I can port the code away from reliance on the Arduino IDE.

Delta_G:
What happens when you rely on the IDE to do the thinking for you is that sometimes it thinks wrong and puts the prototypes in the wrong place. The obvious fix is to not rely on the IDE to generate them for you.

Indeed, I might have to go back and create prototypes for each function myself. I am working to remove the IDE from my workflow but find it hard to do. I looked into arduino-builder, but that hasn't been much help. No doubt due to misconfiguration on my part but on the other hand, tools need to be easy to use.

bperrybap:
There is no way that I now of to completely disable the IDE from doing some prototype or other "magic" since it converts the .ino file to a .cpp file for compilation.
There are some versions of the IDE that you simply need to avoid to do broken protype issues that you cannot work around even if you do your own prototypes.
Some IDEs will misinsert the #include <Arduino.h> and break things.
There have been many prototyping issues over the years but by far the worst I saw was was in IDE 1.6.6
But with recent IDEs like 1.6.9 and newer, most of those issues are now gone now there is a separate builder program that uses the actual C preprocessor to do some of the work.

--- bill

Thank you for the information. This reinforces my opinion that it is some bug in the IDE. For now I suppose I will build the code in a virtual machine.

Delta_G:
What happens when you rely on the IDE to do the thinking for you is that sometimes it thinks wrong and puts the prototypes in the wrong place. The obvious fix is to not rely on the IDE to generate them for you.

Isn't this somewhat odd advice for an IDE which (I thought) had been designed for new users with little experience of programming?

That link you posted doesn't relate to the issue you are having.
Also the sample code you just posted

void loop() {
    func();
}

void func() {
}

Is not a valid Arduino sketch. It should compile but will not link as it is not a valid Arduino sketch.
It does not have a setup() function.

I've since created a virtual machine and used IDE 1.8.1 to compile the code successfully under Windows.

While it may compile it will not link no matter what OS or version of the IDE you use.

The code you posted compiles for me (but will not link because it is invalid sketch) on linux Mint 17.1 for an Arduino board, when using Arduino 32 bit versions of IDE versions
1.8.1, 1.8.0, 1.6.13, 1.0.5

(I have every single version of the Arduino IDE on my machine as I do lots of testing across versions to test my libraries)

So far I have seen conflicting information and there is still much information that has not been provided.

Accurate details matter. In order to get anyone to help you, you must post accurate information.
This includes posting the EXACT error messages you get from the compiler.

Also, you need to post the EXACT code you are using and provide all the details of your environment, OS, IDE version, board type etc, to allow others to recreate you issue.

i.e. post the error messages you got and the exact code, along with all the IDE information used to get those errors.

Without that, lots of time gets wasted.

--- bill

bperrybap:
That link you posted doesn't relate to the issue you are having.
Also the sample code you just posted

void loop() {

func();
}

void func() {
}



Is not a valid Arduino sketch. It should compile but will not link as it is not a valid Arduino sketch.
It does not have a setup() function.While it may compile it will not link no matter what OS or version of the IDE you use.

The code you posted compiles for me (but will not link because it is invalid sketch) on linux Mint 17.1 for an Arduino board, when using Arduino 32 bit versions of IDE versions
1.8.1, 1.8.0, 1.6.13, 1.0.5

(I have every single version of the Arduino IDE on my machine as I do lots of testing across versions to test my libraries)

So far I have seen conflicting information and there is still much information that has not been provided.

Accurate details matter. In order to get anyone to help you, you must post accurate information.
This includes posting the EXACT error messages you get from the compiler.

Also, you need to post the EXACT code you are using and provide all the details of your environment, OS, IDE version, board type etc, to allow others to recreate you issue.

i.e. post the error messages you got and the exact code, along with all the IDE information used to get those errors.

Without that, lots of time gets wasted.

--- bill

My apologies, the complete test case is:

void setup() {
}

void loop () {
    func();
}

void func() {
}

What is especially infuriating is that the test case given compiles, but a similar situation in the complete sketch produces the error given in the thread I referenced: function not declared in scope - Syntax & Programs - Arduino Forum, admittedly with a different name. I will reproduce it here: "In function 'void setup()': error: 'setColorInterval' was not declared in this scope."

This exact same sketch exhibits different behavior when compiled under the Windows IDE.

I'm not trying to withhold any information, there's just nothing to say.

It turns out the IDE was pulling in a file in the same folder with a .cpp extension. Deleting the file allowed IDE to compile the sketch.

R0b0t1:
It turns out the IDE was pulling in a file in the same folder with a .cpp extension. Deleting the file allowed IDE to compile the sketch.

And THAT is a great example why we need to see the all messages from the compile and have all the code being used.
Just seeing the compiler messages we likely would have seen the problem and then having all the code, it would have been fairly straight forward to see what the problem was.

You mislead us by not giving us all the information as well as giving us incorrect information.

--- bill

bperrybap:
And THAT is a great example why we need to see the all messages from the compile and have all the code being used.
Just seeing the compiler messages we likely would have seen the problem and then having all the code, it would have been fairly straight forward to see what the problem was.

You mislead us by not giving us all the information as well as giving us incorrect information.

--- bill

The .cpp file had the same contents as the .ino; there was literally no indication to the cause of the issue I was experiencing, unless newer IDEs keep the .ino extension in error messages.

R0b0t1:
The .cpp file had the same contents as the .ino; there was literally no indication to the cause of the issue I was experiencing, unless newer IDEs keep the .ino extension in error messages.

There were likely indications.

Without seeing the actual code it is hard to tell what you had done, but
it is likely that the the IDE and compiler messages during the build would have shown the two files & filenames and that this extra file was being used and compiled.

Not to mention the IDE should have been showing a tab for the .cpp file.

So again that is why we need to see all the code and build messages not just the code or the fragments of the code you may think are relevant.

I still can't figure out how a sketch directory with this issue could build on Windows but not on Linux.
But there is no way to know, since you won't provide us with the code and other details that we would need to replicate the issue.

--- bill