Thread: Compiles on gcc 3.3 but not on gcc 4.0.3

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    271

    Compiles on gcc 3.3 but not on gcc 4.0.3

    This regards a source I downloaded. On one computer, an OS X, I have gcc 3.3 installed. On another, a Linux, I have gcc 4.0.3. The website I got it from stated that it would compile on both Linux and OS X, but it only compiles on OS X. With regard to a previous post,
    http://cboard.cprogramming.com/showthread.php?t=87969
    I'm guessing this is more an issue of gcc version rather than platform.

    Well, I've run into more trouble, and this time, it has to do with the declaration of an external variable.

    Here's the relevant declaration in "Globals.h"
    Code:
    extern float PROB_SMOOTH;
    Unfortunately, this PROB_SMOOTH variable is being used in tons of other places, for example, the header "NTables.h" makes use of this.

    A sample bit of code is:
    Code:
    template <class VALTYPE>
    class nmodel
    {
     private:
      Array2<VALTYPE, Vector<VALTYPE> > ntab;
     public:
      nmodel(int maxw, int maxn)
        : ntab(maxw, maxn, 0.0)
        {}
      VALTYPE getValue(int w, unsigned int n)const
        {
          massert(w!=0);
          if(n>=ntab.getLen2())
    	return 0.0;
          else
    	return max(ntab(w, n), VALTYPE(PROB_SMOOTH)); \\throws error here
    
    ....
    As I've commented in the last line, gcc 4.0.3 on Linux throws an error about "PROB_SMOOTH" was not declared in this scope. And it's true. I've traced back all the headers that are included in "NTables.h" and none of them are "Globals.h".

    The strange thing about it is, if I use gcc 3.3 on Mac OS 10.3, the entire thing compiles.

    And the external declaration doesn't make sense to me either. By my understanding, you declare "extern" in the file where it's going to be used. Here, it's declared once in "Globals.h" where there are no function definitions whatsoever.

    One way I could fix it, I guess is by including "Globals.h" in the file or declaring PROB_SMOOTH in every file that uses it as "extern". But I have a nagging feeling that that is incorrect.

    Sorry I've been so long-winded. Any help would be dearly appreciated.

    And for the curious, here's a link to the entire source:
    http://www.fjoch.com/GIZA++.2003-09-30.tar.gz

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by cunnus88 View Post
    And the external declaration doesn't make sense to me either. By my understanding, you declare "extern" in the file where it's going to be used. Here, it's declared once in "Globals.h" where there are no function definitions whatsoever.
    This is the typical way of doing it. By putting the extern declaration in a header, all the modules which use that variable do not have to declare it "extern." You're seeing normal usage.

    Exactly which .cc file is failing to compile?

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    271
    Every .h file which references PROB_SMOOTH.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by cunnus88 View Post
    Every .h file which references PROB_SMOOTH.
    That's not what I asked... .h files do not get compiled, only .cc files are compiled. What is the name of a .cc file which fails to compile (any one of them is fine)? I.e. run the make and see where it dies. On my local system, it all compiles fine. If you give me the name of a failing file I can dig deeper.

    EDIT: Actually looked at the README file. Looks like a statistical translator trained on example bitexts. Cool! I've done a bit of NLP programming myself.
    Last edited by brewbuck; 03-29-2007 at 12:14 PM.

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    271
    Thanks for looking into this. I really appreciate it.

    It seems you have downloaded the source. Well, when I run "make opt" on the command line, it hits this particular directive
    Code:
    g++   -Wall -W -Wno-deprecated -O2 -DNDEBUG -DWORDINDEX_WITH_4_BYTE  \
    -c model3.cc -o optimized/model3.o
    Then it throws out the following messages
    Code:
    NTables.h: In member function ‚:
    NTables.h:48: error: ‚ was not declared in this scope
    ATables.h: In constructor ‚:
    ATables.h:98: error: ‚ was not declared in this scope
    ATables.h: In member function ‚:
    ATables.h:114: error: ‚ was not declared in this scope
    ATables.h:116: error: ‚ was not declared in this scope
    make: *** [optimized/model3.o] Error 1
    Sad to say, I'm accessing the code through an X11 terminal, and the error messages are not displaying properly.

    In both instances, I'm actually guessing that it's PROB_SMOOTH and MAX_SENTENCE_LENGTH that's causing the problems since the other pieces of code seem fairly straightforward to me.

  6. #6
    Registered User
    Join Date
    Oct 2005
    Posts
    271
    Yes, I think it's probably the most well-known non-commercial text-alignment program out there. It could also use some improvement.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Gcc can't find obvious copy constructor
    By SevenThunders in forum C++ Programming
    Replies: 13
    Last Post: 03-19-2009, 02:41 PM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Replies: 4
    Last Post: 09-02-2007, 08:47 PM
  4. Undefined symbols from ld? ; making bundle; gcc 3.3
    By profxtjb in forum C Programming
    Replies: 5
    Last Post: 06-15-2004, 01:31 AM
  5. gcc
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-22-2003, 03:46 PM