Header File Causing Compilation Errors

My code fails to compile when I add a second header file.

Currently the header files are:
#include <LiquidCrystal.h>
and I want to add #include <ezTime.h>

But when I add the second header file to my code the program does not compile. Once I remove the header it compiles without any issue.

I have installed the library for ezTime and it is currently in Documents/Arduino/Libraries.

The error message is "Compilation error: Error: 2 UNKNOWN: exit status 1"

Any help is greatly appreciated.

Hi @whuty. I'm going to ask you to post some additional information that might help us to identify the problem.

Please do this:

  1. Select File > Preferences from the Arduino IDE's menus.
  2. Check the box next to "Show verbose output during: [] compilation".
  3. Click the OK button.
  4. Select Sketch > Verify/Compile from the Arduino IDE's menus.
  5. Wait for the compilation to end.
  6. Right click on the black "Output" pane at the bottom of the Arduino IDE 2.x window.
  7. From the context menu, click Copy All.
  8. Open a forum reply here by clicking the Reply button.
  9. Click the </> 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 block
  10. Press Ctrl+V. This will paste the compilation output into the code block.
  11. Move the cursor outside of the code tags before you add any additional text to your reply.
  12. Click the Reply button to post the output.
Using board 'uno' from platform in folder: C:\Users\tom_g\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3
Using core 'arduino' from platform in folder: C:\Users\tom_g\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3
Detecting libraries used...
"C:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "C:\\Users\\tom_g\\AppData\\Local\\Temp\\arduino-sketch-D258226A06DE46236BB444FCAA1FEEC2\\sketch\\EmailNotification.ino.cpp" -o nul
Alternatives for LiquidCrystal.h: []
ResolveLibrary(LiquidCrystal.h)
  -> candidates: []
Compilation error: Error: 2 UNKNOWN: exit status 1

@pert

I should mention that I have tried moving the files around to see if a different configuration would work. But still not working.

The classic Arduino IDE comes with a collection of fundamental libraries pre-installed. Because of this, we are accustomed to these libraries always being available and you will find documentation and tutorials that make this assumption. The LiquidCrystal library is one of these built-in libraries.

Arduino IDE 2.x does not currently come with any libraries pre-installed, so you must install every library used by your sketch. Fortunately, this is easy enough to do using the IDE's Library Manager feature.

Please try this:

  1. Select Sketch > Include Library > Manage Libraries... from the Arduino IDE's menus.
  2. Wait for the update to finish.
  3. In the "Filter your search" field, type liquidcrystal.
  4. Scroll down through the list of libraries until you see "LiquidCrystal by Arduino, Adafruit". Click on it.
  5. Click the INSTALL button.
  6. Wait for the installation to finish.

You should now be able to compile your sketch without getting this error.

@pert

I have both libraries installed already through the Manage Libraries tab.

My issue occurs when I include a header file other than LiquidCrystal. LiquidCrystal works fine but when I install and include another library it won't compile.

The secondary library is in the same location as LiquidCrystal in the Libraries folder but it does not work and causes the whole program to not compile.

Please post your full sketch.

  1. Select Tools > Auto Format from the Arduino IDE's menus. This will make it easier for you to spot bugs and make it easier for us to read.
  2. Select Edit > Copy for Forum from the Arduino IDE's menus.
  3. In a forum reply here, click on the post composer field.
  4. Press Ctrl+V. This will paste the sketch to the post composer.
  5. Move the cursor outside of the code tags before you add any additional text to your reply.
  6. Repeat the above process if your sketch has multiple tabs.
  7. Click the Reply button to post your reply.

When your code requires a library that's not included with the Arduino IDE please post a link to where you downloaded that library from or if you installed it using Library Manager (Sketch > Include Library > Manage Libraries in the Arduino IDE) then say so and state the full name of the library.

Very strange! What it seems to be saying is that it found the file "LiquidCrystal.h" just fine but when it tried to find the library directory that contained "LiquidCrystal.h", it didn't find any!

My guess is that the quickest fix would be to re-install the IDE.

This is incorrect. Here's a demo:

#include <NonexistentHeader.h>
void setup() {}
void loop() {}
Alternatives for NonexistentHeader.h: []
ResolveLibrary(NonexistentHeader.h)
  -> candidates: []
Compilation error: Error: 2 UNKNOWN: exit status 1

The [] is indicating the empty array of alternatives/candidates.

This is the unfortunate cryptic output you get from Arduino IDE 2.x right now when a header file is not found. This is a known issue that is in the bug tracker already. Hopefully we can get back to seeing our old familiar "No such file or directory" soon.

There is no such condition as "my code fails to compile". There is always a specific error message when it fails to compile. Every single time, without exception. If you do not include that error message in your question, there is no hope of answering the question.

My first suspicion is that ezTime.h requires some other header file, which it failed to #include; this would be a bug in ezTime.h. My second suspicion is that it is including a header file that has already been included, and that header file did not have "include guards", which is a bug in that second header file. But without seeing the actual error message, there is no way to tell. Never report a compilation error without including the error message text, copied from the output window. You may further include the specific line on which the error occurs.
The Arduino IDE is defective in not providing a way to add per-module compilation options, or even global options for all compilations. This is a very serious defect in its design, yet there has been no attempt to correct it, in spite of numerous requests. Because there is a third reason for a compilation error, which is very hard to discover: ezTime.h might contain a name which has been #defined as a macro in an earlier included file. This means that the source code has a genuine syntax error in it. Without the option to see the preprocessor output (which should at least be a checkbox!) there is no easy way to determine if this is the cause.

Wow, are you OK @Flounder? That was quite the rant triggered by a simple missing header file.

It was added 7 years ago:

You're telling me there are only three reasons for compilation errors?

How is that going to cause LiquidCrystal.h to go missing?

@pert @johnwasser

Ok, maybe I was too cryptic to get a good answer. Let me clarify.

[code]
#include <LiquidCrystal.h> 

//Include^
//Init
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); /*Initialize the LCD and
                                        tell it which pins is
                                        to be used for communicating*/

//Global Var
#define contra 9  //Define the pin that controls the contrast of the screen
#define bri 10    //Define the pin the controls the brightness of the screen
//Both pins are PWM so you can analogWrite to them and have them output a variable value


void setup() {  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  // put your setup code here, to run once:
  lcd.begin(16, 2);         //Tell the LCD that it is a 16x2 LCD
  pinMode(contra, OUTPUT);  //set pin 9 to OUTPUT
  pinMode(bri, OUTPUT);     //Set pin 10 to OUTPUT
  //pinMode-ing OUTPUT makes the specified pin output power
  digitalWrite(contra, LOW); /*outputs no power to the contrast pin.
                            this lets you see the words*/
  analogWrite(bri, 255);     //Outputs full power to the screen brightness LED
  lcd.print("   You have an");
  lcd.setCursor(0, 1);
  lcd.print("     EMAIL    ");
}  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void loop() {  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  lcd.clear();
  lcd.setCursor(0, 0);
  String s = "   You have an ";
  for (int i = 0; i < s.length(); i++) {
    lcd.print(s[i]);
    delay(500);
  }
  lcd.setCursor(0, 1);
  String e = "     EMAIL!";
  for (int i = 0; i < e.length(); i++) {
    lcd.print(e[i]);
    delay(500);
  }
}  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[/code]

No issues with this code, can verify, compile, and upload to arduino.

However, when I add #include <ezTime.h>

[code]
#include <LiquidCrystal.h>
#include <ezTime.h>

//Include^
//Init
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); /*Initialize the LCD and
                                        tell it which pins is
                                        to be used for communicating*/

//Global Var
#define contra 9  //Define the pin that controls the contrast of the screen
#define bri 10    //Define the pin the controls the brightness of the screen
//Both pins are PWM so you can analogWrite to them and have them output a variable value


void setup() {  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  // put your setup code here, to run once:
  lcd.begin(16, 2);         //Tell the LCD that it is a 16x2 LCD
  pinMode(contra, OUTPUT);  //set pin 9 to OUTPUT
  pinMode(bri, OUTPUT);     //Set pin 10 to OUTPUT
  //pinMode-ing OUTPUT makes the specified pin output power
  digitalWrite(contra, LOW); /*outputs no power to the contrast pin.
                            this lets you see the words*/
  analogWrite(bri, 255);     //Outputs full power to the screen brightness LED
  lcd.print("   You have an");
  lcd.setCursor(0, 1);
  lcd.print("     EMAIL    ");
}  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void loop() {  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  lcd.clear();
  lcd.setCursor(0, 0);
  String s = "   You have an ";
  // if time between 8 am and 6pm, uk folks are alright to contact
  for (int i = 0; i < s.length(); i++) {
    lcd.print(s[i]);
    delay(500);
  }
  lcd.setCursor(0, 1);
  String e = "     EMAIL!";
  for (int i = 0; i < e.length(); i++) {
    lcd.print(e[i]);
    delay(500);
  }
}  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[/code]

Not only does ezTime not work, but neither does LiquidCrystal.

The errror is as follows:

Using board 'uno' from platform in folder: C:\Users\tom_g\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3
Using core 'arduino' from platform in folder: C:\Users\tom_g\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3
Detecting libraries used...
"C:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "C:\\Users\\tom_g\\AppData\\Local\\Temp\\arduino-sketch-636370EFEAD2D1438107F4489F470816\\sketch\\EmailNotification.ino.cpp" -o nul
Alternatives for LiquidCrystal.h: [LiquidCrystal.h@1.0.7]
ResolveLibrary(LiquidCrystal.h)
  -> candidates: [LiquidCrystal.h@1.0.7]
"C:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "-IC:\\Users\\tom_g\\OneDrive\\Documents\\Arduino\\libraries\\LiquidCrystal.h\\src" "C:\\Users\\tom_g\\AppData\\Local\\Temp\\arduino-sketch-636370EFEAD2D1438107F4489F470816\\sketch\\EmailNotification.ino.cpp" -o nul
Alternatives for ezTime.h: [ezTime.h@0.8.3]
ResolveLibrary(ezTime.h)
  -> candidates: [ezTime.h@0.8.3]
"C:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "-IC:\\Users\\tom_g\\OneDrive\\Documents\\Arduino\\libraries\\LiquidCrystal.h\\src" "-IC:\\Users\\tom_g\\OneDrive\\Documents\\Arduino\\libraries\\ezTime.h\\src" "C:\\Users\\tom_g\\AppData\\Local\\Temp\\arduino-sketch-636370EFEAD2D1438107F4489F470816\\sketch\\EmailNotification.ino.cpp" -o nul
"C:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "-IC:\\Users\\tom_g\\OneDrive\\Documents\\Arduino\\libraries\\LiquidCrystal.h\\src" "-IC:\\Users\\tom_g\\OneDrive\\Documents\\Arduino\\libraries\\ezTime.h\\src" "C:\\Users\\tom_g\\OneDrive\\Documents\\Arduino\\libraries\\LiquidCrystal.h\\src\\LiquidCrystal.cpp" -o nul
"C:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "-IC:\\Users\\tom_g\\OneDrive\\Documents\\Arduino\\libraries\\LiquidCrystal.h\\src" "-IC:\\Users\\tom_g\\OneDrive\\Documents\\Arduino\\libraries\\ezTime.h\\src" "C:\\Users\\tom_g\\OneDrive\\Documents\\Arduino\\libraries\\ezTime.h\\src\\ezTime.cpp" -o nul
Alternatives for EEPROM.h: [EEPROM@2.0]
ResolveLibrary(EEPROM.h)
  -> candidates: [EEPROM@2.0]
"C:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "-IC:\\Users\\tom_g\\OneDrive\\Documents\\Arduino\\libraries\\LiquidCrystal.h\\src" "-IC:\\Users\\tom_g\\OneDrive\\Documents\\Arduino\\libraries\\ezTime.h\\src" "-IC:\\Users\\tom_g\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\libraries\\EEPROM\\src" "C:\\Users\\tom_g\\OneDrive\\Documents\\Arduino\\libraries\\ezTime.h\\src\\ezTime.cpp" -o nul
Alternatives for WiFi.h: []
ResolveLibrary(WiFi.h)
  -> candidates: []
Using library LiquidCrystal.h at version 1.0.7 in folder: C:\Users\tom_g\OneDrive\Documents\Arduino\libraries\LiquidCrystal.h 
Using library ezTime.h at version 0.8.3 in folder: C:\Users\tom_g\OneDrive\Documents\Arduino\libraries\ezTime.h 
Using library EEPROM at version 2.0 in folder: C:\Users\tom_g\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\libraries\EEPROM 
Compilation error: Error: 2 UNKNOWN: exit status 1

I have the LiquidCrystal and ezTime header files in Documents/Arduino/Libraries.

My thought would be that ezTime includes header files that I don't have installed but not sure why that would cause issues with LiquidCrystal.

Here's the problem:

Now if you will tell us where we can find the libraries you installed we would be able to provide you with instructions to fix this error.


This thing where you add a .h to the library folder names is bound to cause confusion.

The libraries I installed are:

Which I installed through Arduino IDE using Manage Library.

The other is LiquidCrystal:

Also, I removed the .h from the file name. I was just being stupid.

There is this code in the ezTime library:

#ifdef EZTIME_NETWORK_ENABLE
	#ifdef EZTIME_CACHE_NVS
		#include <Preferences.h>		// For timezone lookup cache
	#endif
	#ifdef EZTIME_CACHE_EEPROM
		#include <EEPROM.h>
	#endif	
	#if defined(ESP8266)
		#include <ESP8266WiFi.h>
		#include <WiFiUdp.h>
	#elif defined(ARDUINO_SAMD_MKR1000)
		#include <SPI.h>
		#include <WiFi101.h>
		#include <WiFiUdp.h>
	#elif defined(EZTIME_ETHERNET)
		#include <SPI.h>
		#include <Ethernet.h>
		#include <EthernetUdp.h>
	#else
		#include <WiFi.h>
		#include <WiFiUdp.h>
	#endif
#endif

In order to get the current time from an NTP server, the library must have network connectivity. It is designed to support several ways of connecting:

  • Using an ESP8266-based Arduino board, which has a built-in WiFi radio
  • Using an Arduino MKR1000 board, which has a built-in WiFi radio.
  • Using a WizNet W5100/W5200/W5500 Ethernet shield or module connected to any Arduino board.
  • An ESP32-based Arduino board, which has a built-in WiFi radio
  • Perhaps also any Arduino board with the long retired Arduino WiFi Shield attached?

These preprocessor conditionals are intended to automatically pick the right library for the boards with built-in network connectivity. However, this is not possible with your Uno. In this case, it falls back to the default of using the WiFi library. There are two different common Arduino libraries that have these file names. The library author tested the library for ESP32. It's possible the other library will work, since the ESP32 was based on it, but it's unlikely that you'll find that old Arduino WiFi Shield, so I would recommend forgetting about the Arduino WiFi library.

So what we need to know is what your goals were with this ezTime library. Are you planning to get the time from an NTP server? If so, how will you connect your Uno to the Internet?

Don't worry about it. The IDE was able to handle the odd folder name correctly (though it is best to leave them as Library Manager names them because it can cause problems in some rare cases). It's only that I think it can cause confusion to humans. When we see a path to a folder of this name, it looks like a file at first glance (it did to me at least), and if that was a file then it would definitely cause the missing header file errors. But I was able to see from the compilation commands that it was actually a folder and not a file, so I avoided that particular confusion.

@pert
I want to get GMT time so I can determine whether my UK coworkers are up/available for work.

It seems ezTime may not be the right library for this but it seemed like the best out of the options.

Is there a library more suited for something like this?

I understand now that ezTime is going to require the board to be connected to the internet in order to make calls to the NTP server. So I'll look into connecting it to the internet without the the WiFi library. (Maybe an ethernet shield)

I don't have any experience with this library, but it looks like the author has given it a lot of care and that it is reasonably popular. So I wouldn't necessarily discount it,

It looks like it does have support for other time sources if you don't want to use an NTP server:
https://github.com/ropg/ezTime#setting-date-and-time-manually

NTP is a common approach to getting the current time, but you could even connect a realtime clock (RTC) to your Uno and just manually set the time once. The RTC will keep the time accurately enough after that without needing to get it from external sources like NTP or GPS.

That is a good option for the Uno.

@pert

Looks like I need to do some more reading of the library and look at the alternatives it offers.

Thank you for all the help with this. I think I can figure it out now.

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