Kevin
Kevin

Reputation: 3

Conflicting declaration of character

I am currently working on an Arduino project where I need both the WiFi.h and MySQL_Connection.h libraries.

The variable "password" is used in both of these libraries and therefore causes a conflict.

How can I fix this problem? I am still quite new to the platform, and any possible solutions must therefore be easy to understand. Thanks in advance.

Error message provided by Arduino: "exit status 1 conflicting declaration 'char password []'"


include <Ethernet.h>
#include "WiFi.h";
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

//Wifi

//Wifi connection, this call is to the Wifi.h library
const char* ssid = "pp******";
const char* password = "*******";

//This call is to the <MySQL_Connection.h> library

IPAddress server_addr(10,0,1,35);  // IP of the MySQL *server* here
char user[] = "root";              // MySQL user login username
char password[] = "secret";        // MySQL user login password


Upvotes: 0

Views: 2600

Answers (1)

Beta
Beta

Reputation: 99144

I'd pick the header which provides fewer things to your code, and put it in a namespace:

#include "WiFi.h"

namespace mySQL
{
#include "MySQL_Connection.h"
}

using mySQL::something;
using mySQL::something_else;

...

foo(password);
bar(mySQL::password);

EDIT: It's not clear to me how the code you've posted works, but try this:

include <Ethernet.h>

namespace Wifi
{
#include "WiFi.h";
const char* password = "*******";
}
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

const char* ssid = "pp******";

IPAddress server_addr(10,0,1,35);  // IP of the MySQL *server* here
char user[] = "root";              // MySQL user login username
char password[] = "secret";        // MySQL user login password

If this doesn't work, tell me the result in a comment and we'll tinker some more. If it works, be advised that you still have to put in the effort to learn about namespaces.

Upvotes: 0

Related Questions