visual studio - C++ Using a single class in multiple other classes - Multiple definition error when compiling -


i downloaded library arduino communicate mcp23017 chip via i2c. goal use 1 class in various files have different functions, library of things chip.

after building code run 7-segment multiplexed display, compiled fine , able load onto arduino. after writing class use second chip inputs only, started getting compile errors due multiple definitions of base class. i'm used coding in vb, not c++, having define classes pretty confusing, , not sure fix it.

here error: (this snippet of error, since gist of section enough think. every routine in adafruit_mcp23017.cpp file has error.)

adafruit_mcp23017.cpp.o (symbol plugin)*: in function adafruit_mcp23017::bitforpin(unsigned char) (.text+0x0)*: multiple definition of adafruit_mcp23017::readgpio(unsigned char) adafruit_mcp23017.cpp.o (symbol plugin)*: (.text+0x0): first defined here 

mainfile header:

#include <arduino.h> #include <wire.h> #include <unistd.h> #include "sevensegmentdisplay_mcp23017.h" #include "i2c_input_mcp23017.h"  sevensegmentdisplay ssd; i2c_input_mcp23017 inp; 

sevensegmentdisplay.h header:

#pragma once #ifndef _adafruit_mcp23017_h_        #include <adafruit_mcp23017.h> #endif #include <arduino.h> // need serial output , 'delay' function 

sevensegmentdisplay.cpp header:

#include "sevensegmentdisplay_mcp23017.h" 

i2c_input_mcp23017.h header:

#pragma once #include <adafruit_mcp23017.h> #include <arduino.h> // need serial output , 'delay' function 

i2c_input_mcp23017.cpp header:

#include "i2c_input_mcp23017.h" 

solution edit: after reading answer posted, found problem. didn't think base class snuff (lack of comments on routines, making pretty hard use, since had no description of each routine accepted variables or did.) when doing this, included solution. the problem was including library folder , solution itself (even though solution referenced files library itself, no new files created). removed reference class in question (highlighted in picture below) , program compiled perfectly. (tested adding them in resulted in same faults).

tl;dr: if have file in library already, don't include in solution, seems want grab twice. once when #included , once in solution explorer.

here problem:

i suspect have adafruit_mcp23017 library (.c , .h files) in 2 places in arduino /libraries directory.

probably (probably!) in both /libraries/adafruit_mcp23017/ , /libraries/sevensegmentdisplay_mcp23017/utility/

adafruit make libraries beginner proof including required sub-libraries in download archives. confuses things try use sub-library directly.

if case need modify sevensegmentdisplay_mcp23017.h file change from

#include <utility/adafruit_mcp23017.h> 

to

#include <adafruit_mcp23017.h> 

and delete adafruit_mcp23017.h , adafruit_mcp23017.c /libraries/sevensegmentdisplay_mcp23017/utility/ directory.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -