OzGrant 22 Posted January 13, 2015 Share Posted January 13, 2015 G'day I'm porting a sketch from F5529 to Tiva, and want to be able to use the sketch on both (until debugged). I thought the following would work: #define _TIVA true //true for Tiva, false for F5529 #if (_TIVA) #include "TM4C_DS18B20.h"#else #include "GFDS18B20.h"#endif But I get multiple definition of `DS18B20:.. errors , when I compile. Is there a way around this. Quote Link to post Share on other sites
cde 334 Posted January 13, 2015 Share Posted January 13, 2015 Try: #define _TIVA true //true for Tiva, false for F5529#ifdef _TIVA #include "TM4C_DS18B20.h"#endif#ifndef _TIVA #include "GFDS18B20.h"#endif Quote Link to post Share on other sites
OzGrant 22 Posted January 14, 2015 Author Share Posted January 14, 2015 Cde, Nop, still got the same error Quote Link to post Share on other sites
cde 334 Posted January 14, 2015 Share Posted January 14, 2015 Try changing the Marco name. _TIVA might trigger something weird. Try TivaBug or something. Quote Link to post Share on other sites
OzGrant 22 Posted January 14, 2015 Author Share Posted January 14, 2015 Nope again, Might have to keep a duplicate copy of sketch for each Launchpad. But my main problem is the unavailability of the Tiva Serial1 port, but that's in another post. Sort of stuck between two launchpads, F5529 one runs out of ROM the other has Serial1 problems. Anyway will push on. Grant Quote Link to post Share on other sites
LiviuM 43 Posted January 14, 2015 Share Posted January 14, 2015 Hello Grant, For the lm4f (TIVAC), Energia.h (../energia/hardware/lm4f/cores/lm4f/) has the following defines: #if defined(__TM4C129XNCZAD__) #define TARGET_IS_SNOWFLAKE_RA0 #define PART_TM4C129XNCZAD #elif defined(__TM4C1294NCPDT__) #define TARGET_IS_SNOWFLAKE_RA0 #define PART_TM4C1294NCPDT #elif defined(__LM4F120H5QR__) || defined(__TM4C123GH6PM__) #define TARGET_IS_BLIZZARD_RB1 #define PART_TM4C1233H6PM #define PART_LM4F120H5QR #else #error "**** No PART defined or unsupported PART ****" #endif Maybe you can use some of these defines? Regards, Liviu Quote Link to post Share on other sites
OzGrant 22 Posted January 14, 2015 Author Share Posted January 14, 2015 Still nope, But tks Livium, at least I can use (__TM4C123GH6PM__) instead of _TIVA. But still get multiple definition of `DS18B20:.. errors #if defined(__TM4C123GH6PM__) #include "TM4C_DS18B20.h"#else #include "GFDS18B20.h"#endif Quote Link to post Share on other sites
cde 334 Posted January 15, 2015 Share Posted January 15, 2015 Wait. Maybe its a whitespace thing. Don't indent those include lines. Quote Link to post Share on other sites
pabigot 355 Posted January 15, 2015 Share Posted January 15, 2015 Whitespace before #include directives should make no difference. Try just doing: #include "TM4C_DS18B20.h"unconditionally and see if the problem goes away. I suspect that with most of your attempts you're only getting that file included, and the problem is entirely within it. (Or that something somewhere else is including the conflicting definitions.) Quote Link to post Share on other sites
OzGrant 22 Posted January 15, 2015 Author Share Posted January 15, 2015 Both includes work OK When I comment out #include "TM4C_DS18B20.h" and leave #include "GFDS18B20.h" the sketch is compiles and tests OK for F5529 and when I comment out #include "GFDS18B20.h" and leave #include "TM4C_DS18B20.h" the sketch is compiles and tests OK for Tiva. I am trying to use the same sketch(while I port over to Tiva), by making _TIVA true for Tiva, or _TIVA false for F5529. It appears the compiler always tests both includes, regardless of _TIVA state . Quote Link to post Share on other sites
abecedarian 330 Posted January 15, 2015 Share Posted January 15, 2015 What is the text of the actual error you receive? Quote Link to post Share on other sites
OzGrant 22 Posted January 15, 2015 Author Share Posted January 15, 2015 G'day Compied with E14 for a Tiva with the following code #if defined(__TM4C123GH6PM__) #include "TM4C_DS18B20.h"#else #include "GFDS18B20.h"#endif get the following errors : GFDS18B20V2\GFDS18B20.cpp.o: In function `DS18B20::DS18B20(unsigned char)':GFDS18B20.cpp:(.text._ZN7DS18B20C2Eh+0x0): multiple definition of `DS18B20::DS18B20(unsigned char)'TM4C_DS18B20\TM4C_DS18B20.cpp.o:TM4C_DS18B20.cpp:(.text._ZN7DS18B20C2Eh+0x0): first defined hereGFDS18B20V2\GFDS18B20.cpp.o: In function `DS18B20::DS18B20(unsigned char)':GFDS18B20.cpp:(.text._ZN7DS18B20C2Eh+0x0): multiple definition of `DS18B20::DS18B20(unsigned char)' etc. for many many lines It is no longer a big issue as I have now have two sketches, and with the porting is nearly over will only require the sketch to compile on the Tiva. Grant Quote Link to post Share on other sites
pabigot 355 Posted January 15, 2015 Share Posted January 15, 2015 That's not a compiler error related to the include file. It's a linker error because you're putting both object files into the target-specific executable. Link GFDS18B20.cpp.o or TM4C_DS18B20.cpp.o but not both. Quote Link to post Share on other sites
OzGrant 22 Posted January 15, 2015 Author Share Posted January 15, 2015 Yes its a linker error that is picking up both includes. But the following should inform the linker what include is to be used, and not Both #if defined(__TM4C123GH6PM__) #include "TM4C_DS18B20.h" // use this when compiling with Tiva#else #include "GFDS18B20.h" //use this when compiling with F5529#endif Quote Link to post Share on other sites
Rickta59 589 Posted January 15, 2015 Share Posted January 15, 2015 Yes its a linker error ... It is easier to figure out what the problem is, if you post all the code you are using. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.