Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Undefined References - C

Options
  • 19-11-2014 11:52am
    #1
    Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭


    This is starting to do my nut in at the moment. I'm analyzing C code relevant to a series of manufacturing process, written long before I even started College. The system it was developed for is an old version of HP-UX and I'm sure it worked well back then, but now, when I attempt to compile the code on my own Windows 7 machine using Dev C++, which can be used to develop and compile for C, I am getting arms length lists of "Undefined Reference to 'Particular Variable'".

    Now, in some cases, I've been able to resolve some of the warnings by creating additional references to certain variables with some success, but the rest remain a problem. I've Googled potential solutions all day yesterday until I was blue in the face. Anyone have any idea what the issue might be or what I am missing?

    EDIT: Just to point out, I am porting the code to RHEL v6.3 and have also tried to compile the code there, with the same issues. The Windows 7 Machine is just for providing what I hoped would have been a method of resolving problems like these quickly.


Comments

  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    I just figured out that the previous developer/s never defined certain variables within a certain class. I don't know how they got away with that in the past.


  • Registered Users Posts: 1,109 ✭✭✭Skrynesaver


    Itzy wrote: »
    I just figured out that the previous developer/s never defined certain variables within a certain class. I don't know how they got away with that in the past.

    A forgiving compiler?


  • Registered Users Posts: 40,038 ✭✭✭✭Sparks


    Itzy wrote: »
    I just figured out that the previous developer/s never defined certain variables within a certain class. I don't know how they got away with that in the past.

    Because they wrote it in C which doesn't have classes and compiled it with a C compiler instead of a C++ compiler?

    Seriously, if it's that old, install gcc and try to compile it that way.


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    I had been compiling using GCC on Linux and it provided me with a list of errors when I compiled each c file. I've found that some edits have to be made to the code for it to run without warnings and so on. Just to remember, some of this code is nearly 20 years old, running on aging HP-UX Servers. The code is bound to need some work before it will run on Red Hat.


  • Registered Users Posts: 40,038 ✭✭✭✭Sparks


    Yeah, but I'd guess it's more the libc version than the unix version that's the main problem :P


  • Advertisement
  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    Exactly :P


  • Registered Users Posts: 7,157 ✭✭✭srsly78


    Is it because of namespace stuff? The old defaults were slightly different I think. There might even be a compiler flag to use old defaults??

    TBH I have had the pleasure of doing similar work, and the output from gcc can be quite arcane. You can change some link flags to get more verbose output, but this also seems to produce extra spurious errors.


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    I've had to check the make file to see what flags were used during compile time. The class files will compile, but with warnings, which require some fiddling with to get rid of said warnings. I could test the code on the original server, but it's currently running as production, so that's not a possibility, just to see if there are any compile time issues in the original environment.

    I could ask if I could get a VM set up just like the current environment for testing.


  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    Why are you referring to classes and C++? You claim it's C and that is most definitely a different language. If it was developed for HPUX, a UNIX variant, why are you doing it on Windoze? Stay with RH and gcc. And while we're on the subject of RH, I thought that RHEL 6.4 was out of support shortly, so why are you still on 6.3?

    Anyway, my guess as to your undefined variables is exactly because you're using a C++ compiler - it's expecting a mangled reference, so you need to surround all external IDs with the extern "C" stuff.


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    On C, I have a bad habit of referring to a file as a class. The hazards of learning Java and C# I suppose. I refer to the tool Dev C++, which allows one to compile C using a C compiler if so desired. As for RHEL v6.3, it wasn't my choice to use that particular distribution, it was a Company wide decision. I'd certainly opt for a more recent version if I had an input.

    As for your final statement, see above, regarding the tool and compiler I use.


  • Advertisement
  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    I'd still try putting the following into your header files:
    #ifdef __cplusplus
    extern "C" {
    #endif
    /* Put your function def here */
    #ifdef __cplusplus
    }
    #endif
    


  • Registered Users Posts: 2,018 ✭✭✭Colonel Panic


    Why do that until you actually need to do that?


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    The code was being migrated from an old Unix Server to RHEL. I did suggest testing on a similar system so I wasn't chasing problems that technically exist. So after a few days of pricking about trying to create a fix they finally gave in and moved it to another UNIX Server that will be remaining in production for some time.


  • Registered Users Posts: 2,018 ✭✭✭Colonel Panic


    If that's a response to me, I was addressing the suggestion to force C linkage on function declarations in a program written in C compiled by a C compiler!

    If you're just providing an update, sounds like you're off the hook for a bit! I really enjoy porting old code and doing cross platform stuff, but it can be really frustrating!


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    Sorry Colonel I was actually posting an update. I loved the challenge of trying to port code to the new Linux from an old Unix box :P Was interesting to say the least. I found there seemed to be a difference in compiler. I'll provide the c compiler versions for the two boxes tomorrow. Might provide some insight into the issues I was having.


Advertisement