Go to Post It's easy to get overwhelmed. Don't get overwhelmed, just keep working at things a little bit at a time. (Oh, and don't forget to have fun!) - DominickC [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 20-02-2013, 17:23
Michael_Lee Michael_Lee is offline
Registered User
FRC #2976
 
Join Date: Jan 2012
Location: Issaquah, WA
Posts: 21
Michael_Lee is an unknown quantity at this point
How to detect unresolved references at compile time?

Sometimes, when I try running the code on the robot, it refuses to transfer over during debug mode because of "unresolved references". It then displays a popup containing the semi-garbled names of various functions or classes that I placed in my header files but forgot to actually write in the corresponding .cpp file.

It's relatively easy to catch them at this stage, but is there some way to catch these errors at compile time? It's frustrating to have to wait until I'm next to a cRIO so I can catch these sorts of mistakes, instead of being able to detect them at home while coding.

I did find a Stack Overflow thread which listed a few compiler flags which should be able to do what I want, but I couldn't figure out how to apply them to my WindRiver project.

Help?
Reply With Quote
  #2   Spotlight this post!  
Unread 21-02-2013, 17:55
codes02 codes02 is offline
Randolph aka Roxbury aka R_______
AKA: Cody Schafer
no team (Formerly: Team 11, MORT)
 
Join Date: Oct 2007
Rookie Year: 2008
Location: MA, USA
Posts: 57
codes02 is on a distinguished road
Re: How to detect unresolved references at compile time?

Assuming a unix like shell
Code:
powerpc-wrs-vxworks-readelf -s FRC_UserProgram.out
will list all symbols in your program. The ones marked 'UND' are undefined.

A simple filter for them (not exact, you also only need worry about GLOBAL syms, not LOCAL ones).
Code:
powerpc-wrs-vxworks-readelf -s FRC_UserProgram.out | grep UND
A better one (that only prints symbol names):
Code:
powerpc-wrs-vxworks-readelf -s FRC_UserProgram.out \
| awk '{ if ($5 == "GLOBAL" && $7 == "UND") print $8 }'
Of course, vxworks provides some of those unresolved symbols, and what is useful to you is determining whether your program uses symbols that vxworks does not provide.

Potentially you could construct a list of symbols provided by vxworks (adding new ones that your code uses as needed), filter those out, and if any are left produce an error in your build scripts.

The following shows how to filter out known vxworks symbols (assuming you list them, 1 per line, in vxworks_syms.txt):
Code:
powerpc-wrs-vxworks-readelf -s FRC_UserProgram.out \
 | awk '{ if ($5 == "GLOBAL" && $7 == "UND") print $8 }' \
 | grep -vFf vxworks_syms.txt

Edit: also, sorry that this is not quite compile time . I can't help you there (though -Wmissing-prototypes helps)

Last edited by codes02 : 21-02-2013 at 17:58.
Reply With Quote
  #3   Spotlight this post!  
Unread 21-02-2013, 19:54
AlexBrinister AlexBrinister is offline
Registered User
AKA: Alex Brinister
FRC #1768 (RoboChiefs)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Bolton, MA
Posts: 93
AlexBrinister will become famous soon enough
Re: How to detect unresolved references at compile time?

If you wanted to add those build options to your project, all you have to do is (in Wind River) go to your project properties (right click on project and click the Properties option) and then to your Build Properties. Under one of the tabs (I forget which one) there will be a bunch of GCC configuration stuff. There is a box with a bunch of compiler args. All you have to do is add yours in there.

Alex Brinister
Reply With Quote
  #4   Spotlight this post!  
Unread 02-03-2013, 15:18
Michael_Lee Michael_Lee is offline
Registered User
FRC #2976
 
Join Date: Jan 2012
Location: Issaquah, WA
Posts: 21
Michael_Lee is an unknown quantity at this point
Re: How to detect unresolved references at compile time?

Quote:
Originally Posted by codes02 View Post
A bunch of stuff
Thanks, this helped a lot!

I couldn't find the powerpc-wrs-vxworks-readelf program on Linux, but I did discover that the FRC_UserProgram.out file is actually a readable text file, so I could search for the undefined symbols directly from it.

In case anybody else has the same problem as I did, I wrote up a quick Python script to find the undefined symbols from it. (see attached). It should be cross-platform, and should work on at least Python 2.7 and probably Python 3.x.

It's not quite compile time, but it worked for me.
Attached Files
File Type: zip find_missing_symbols.zip (3.2 KB, 6 views)
Reply With Quote
  #5   Spotlight this post!  
Unread 02-03-2013, 15:30
codes02 codes02 is offline
Randolph aka Roxbury aka R_______
AKA: Cody Schafer
no team (Formerly: Team 11, MORT)
 
Join Date: Oct 2007
Rookie Year: 2008
Location: MA, USA
Posts: 57
codes02 is on a distinguished road
Re: How to detect unresolved references at compile time?

the powerpc-wrs-vxworks-readelf program should be installed with windriver on windows, where you can use cygwin to get the other parts (a shell, awk, and grep).

On linux, you can use the readelf from a binutils compiled with multi-target support, or a custom build bintuils for the powerpc-wrs-vxworks target. See http://www.chiefdelphi.com/forums/sh...d.php?t=109385 for some info on that (and building your own gcc). Note that building binutils (which includes readelf) for powerpc-wrs-vxworks does not need the vxworks headers, nor does it require any patching. It should just work.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:35.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi