Link problems - undefined reference with ternary operator

I am receiving the following error during linking of my program (with g++ 2.96, RedHat 8, kernel 2.4):

/tmp/ccAC0qDg.o(.text+0x129a): In function `StartHardwareThread(void *)':
: undefined reference to `Serial::Baud9600'
/tmp/ccAC0qDg.o(.text+0x12a5): In function `StartHardwareThread(void *)':
: undefined reference to `Serial::Baud38400'


The line of code that this relates to is the following:
   Serial::BaudRate baud = (m_config.find("FastPSoC") == m_config.end()? Serial::Baud9600 : Serial::Baud38400);

The strange thing is, the following line does *not* cause the problem:
   Serial::BaudRate baud = (true? Serial::Baud9600 : Serial::Baud38400);
But this does cause the problem:
   bool thisIsTrue(true);
   Serial::BaudRate baud = (thisIsTrue? Serial::Baud9600 : Serial::Baud38400);
The problem does not occur if I use if...else to control the assignment to variable baud

It seems as if the conditional usage prevents it from linking in properly.
The Serial class is defined in a header file, object code is in a dynamic library (.so for *nix users, .dll for windows users)

Can anyone tell me why this happens?
LVL 6
boycyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bachra04Commented:
I think you must define baud variables first and then conditional usage.

like this

   Serial::BaudRate baud = NULL; // or whatever correct
   
   then add the following line:
   
   baud = (true? Serial::Baud9600 : Serial::Baud38400);
0
bachra04Commented:
Execuse me  I mean:
 
   Serial::BaudRate baud = NULL; // or whatever correct
   
   then add the following line:
   
   baud = (m_config.find("FastPSoC") == m_config.end()? Serial::Baud9600 : Serial::Baud38400);
0
NovaDenizenCommented:
I have a couple of wild guesses.  Maybe one will work for you.

   Serial::BaudRate baud = (m_config.find("FastPSoC") == m_config.end()? (Serial::Baud9600) : (Serial::Baud38400));

   Serial::BaudRate baud = (m_config.find("FastPSoC") == m_config.end()? (::Serial::Baud9600) : (::Serial::Baud38400));
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

boycyAuthor Commented:
Thanks both for replies - unfortunately neither of them worked :'(

I don't understand what's happening here. Obviously Baud9600 and Baud38400 are defined in the library I'm linking to, their identifiers must be included in the preprocessing/compilation stages otherwise it wouldn't even get to linking. So logically, for some reason the identifiers the linker is looking for are not the same as the identifiers stored in the library....depending on how I use them.
Ok bit more to go on:

   Serial::BaudRate baudLow = Serial::Baud9600;
   Serial::BaudRate baudHigh = Serial::Baud38400;
   Serial::BaudRate baud = (g_config.find("FastPSoC") == g_config.end()? baudLow : baudHigh);

that works fine, as does swapping *one* of baudLow / baudHigh in the last line for Baud9600 / Baud38400 respectively. Swapping both of them does not work. Surely this must be some sort of bug in the linker?
0
NovaDenizenCommented:
What are the exact types of Serial::Baud9600 and 38400?  How is Serial::BaudRate defined?
0
as2003Commented:
class Serial
{
public:
   typedef unsigned int BaudRate;
   static const BaudRate Baud9600 B9600;
   // ...
}
0
boycyAuthor Commented:
Oops, sorry that post was mine -- shared computer :-?
0
NovaDenizenCommented:
Try compiling your .cc to a .o file (instead of directly to an executable) and run "nm -C" on the resulting .o.  

I'm thinking you really have a compiler bug here.  Is there a reason you're using g++ 2.96?  Maybe a newer version will not have this problem.  
0
boycyAuthor Commented:
@Nova: which .cc - the one attempting to use the BaudRate constants?
Unfortunately yes there is a reason - the target is embedded Linux and compiling with anything other than those in gcc 2.96 results in link errors on target (as I recall , it attempts to dynamically link to non-existant GLIBC stuff).
0
NovaDenizenCommented:
I think you should just write it off as a compiler bug and work around it then.  You're stuck with this compiler and you have a good workaround.  There's no real upside to narrowing down the problem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
boycyAuthor Commented:
as2003 is not my account, I happen to know the guy and used his computer to post a comment, forgetting to log him out and myself in.
0
as2003Commented:
Hello,

Boycy just pointed out your comments GranMod. I can assure you we are two separate entities.

Don't closing either of our accounts. I've put a lot of effort into answering PHP questions. I'll be furious if my progress towards becoming an PHP Expert is erased.

We are good friends and once lived together. He once posted from my computer without logging me out first.

Check out the geographical location of our IPs. You'll notice it's impossible for boycy to travel 200 miles in 1 hour.

Check out our histories. We are interested in totally different topics, our writing style is different, our locations are different. etc. etc.
0
boycyAuthor Commented:
I could be using a proxy? Yeah, didn't think of that did you! Anyway I'm not.
0
as2003Commented:
Arrr, you got me! I *am* Boycy! hahaha!!! And I hereby confess that I smell of mouldy cheese and like to sniff ladies' shoes.
0
boycyAuthor Commented:
Umm...yeah ok I thnik we've established who's who now....further to earlier points I'd like to dissassociate myself from him to prevent any further embarassment...

While I'm here, NovaDenizen - thanks for your assistance on the issue. Whilst it remains unsolved, you can take the points. I will have to assume it is a compiler bug.
Cheers,
--Rob
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.