Thread: Can't Compile a code!!! I ran into "undefined reference to" error.

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    10

    Unhappy Can't Compile a code!!! I ran into "undefined reference to" error.

    hi i use cyqwin machine and i am new in linux. i can not compile a code i ran into these errors:
    ngram-count.o:ngram-count.cc: (.text+0xa9): undefined reference to `_Opt_Parse'
    ngram-count.o:ngram-count.cc: (.text+0x11f): undefined reference to `Vocab::Vocab(unsigned int, unsigned int)'
    ngram-count.o:ngram-count.cc: (.text+0x204): undefined reference to `SubVocab::SubVocab(Vocab&)'
    ngram-count.o:ngram-count.cc: (.text+0x245): undefined reference to `StopNgramStats::StopNgramStats(Vocab&, SubVocab&, unsigned int)'
    ngram-count.o:ngram-count.cc: (.text+0x2b5): undefined reference to `File::File(char const*, char const*, int)'
    ngram-count.o:ngram-count.cc: (.text+0x2f7): undefined reference to `File::~File()'
    ngram-count.o:ngram-count.cc: (.text+0x31f): undefined reference to `File::File(char const*, char const*, int)'
    ..........................
    I checked the include addresses in makefile and all are right.
    can anybody help me and give me some tips?

    Thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You need to make sure you are compiling all the source files, and then linking together the .o files. So either you've got all the files, and just never bothered to write those six functions, or you are missing the file that contains those functions.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Looks like this ngram-count program is from somewhere on the internet, perhaps the OP didn't write this code.

    Can you show more output? What make command are you running precisely? Where did you get this source code if you didn't write it yourself?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    10
    you know I download the code from a scientific site that it is free license.

    Here is the link:

    http://userver.ftw.at/~pucher/semanlm/semanlm0.91.zip

    if it is useful.

    Here is my make file if you are interested:

    #
    # Makefile
    #

    PROGS= ngram-count trainmodel lsalm
    CXX = g++
    #for compiling C files
    CC = cc


    #change the following variable: tcl library
    TCLLIB=/usr/share/tcllib1.13


    MACHINE_TYPE=i686
    INCLUDE_DIR=../include
    LIB_DIR=../lib
    SRC_DIR=./
    #ALL_INCLUDES = -I./ -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/srilm
    ALL_INCLUDES = -I./ -I$(INCLUDE_DIR)
    ALL_LIBRARIES = -lm -L$(LIB_DIR)/$(MACHINE_TYPE) -llattice -lflm -loolm -ldstruct -lmisc

    CXXFLAGS = -O3 -Wno-deprecated


    ################################################## #########################

    OBJ_LSALM=lsalm.o LsaNgram.o LsaLM.o LsaFile.o
    OBJ_MIPLSA = trainmodel.o miplsa.o tools.o writeModel.o option.o las2.o LsaFile.o
    OBJ_READMATRIX=ngram-count.o

    all : $(PROGS)

    .PHONY : all

    lsalm: $(OBJ_LSALM)
    $(CXX) -o $@ $(OBJ_LSALM) $(ALL_LIBRARIES) $(CXXFLAGS)

    ngram-count: $(OBJ_READMATRIX)
    $(CXX) -o $@ $(OBJ_READMATRIX) $(ALL_LIBRARIES) $(CXXFLAGS)

    trainmodel: $(OBJ_MIPLSA)
    $(CXX) -o $@ $(OBJ_MIPLSA) $(ALL_LIBRARIES)


    $(SRC_DIR)%.o: $(SRC_DIR)%.cpp
    cd $(SRC_DIR) && $(CXX) -c $(CXXFLAGS) $(ALL_INCLUDES) $*.cpp

    $(SRC_DIR)%.o: $(SRC_DIR)%.cc
    cd $(SRC_DIR) && $(CXX) -c $(CXXFLAGS) $(ALL_INCLUDES) $*.cc

    $(SRC_DIR)%.o: $(SRC_DIR)%.c
    cd $(SRC_DIR) && $(CC) -c $(ALL_INCLUDES) $*.c

    ################################################## #####################

    clean:
    rm -f *.o $(PROGS)
    --------------------------------------------------------------

    I download tcllib library from http://sourceforge.net/projects/tcll...s/tcllib/1.13/
    and i install it with this command tclsh installer.tcl

    the installer copies to these directories:
    packages ----> C:/cygwin/usr/share/tcllib1.13
    applications---->C:/cygwin/usr/bin

    I think the compiler doesn't reach to that stage to use tcllib and before that compiler stops because i omit the TCLLIB=/usr/share/tcllib1.13 line and still it has those errors.

    I write this command to see the errors "make > make.txt 2>&1" and it prints the process to make.txt and the errors are the same.

    here is the errors that i found in make.txt :

    g++ -o ngram-count ngram-count.o -lm -L../lib/i686 -llattice -lflm -loolm -ldstruct -lmisc -O3 -Wno-deprecated
    ngram-count.o:ngram-count.cc: (.text+0xa9): undefined reference to `_Opt_Parse'
    ngram-count.o:ngram-count.cc: (.text+0x11f): undefined reference to `Vocab::Vocab(unsigned int, unsigned int)'
    ngram-count.o:ngram-count.cc: (.text+0x204): undefined reference to `SubVocab::SubVocab(Vocab&)'
    ngram-count.o:ngram-count.cc: (.text+0x245): undefined reference to `StopNgramStats::StopNgramStats(Vocab&, SubVocab&, unsigned int)'
    ngram-count.o:ngram-count.cc: (.text+0x2b5): undefined reference to `File::File(char const*, char const*, int)'
    ngram-count.o:ngram-count.cc: (.text+0x2f7): undefined reference to `File::~File()'
    ngram-count.o:ngram-count.cc: (.text+0x31f): undefined reference to `File::File(char const*, char const*, int)'
    ngram-count.o:ngram-count.cc: (.text+0x339): undefined reference to `File::~File()'
    ngram-count.o:ngram-count.cc: (.text+0x36e): undefined reference to `SubVocab::SubVocab(Vocab&)'
    ngram-count.o:ngram-count.cc: (.text+0x38f): undefined reference to `File::File(char const*, char const*, int)'
    ngram-count.o:ngram-count.cc: (.text+0x39b): undefined reference to `Vocab::read(File&)'
    ngram-count.o:ngram-count.cc: (.text+0x3c7): undefined reference to `File::~File()'
    ngram-count.o:ngram-count.cc: (.text+0x3d1): undefined reference to `vtable for Vocab'
    ngram-count.o:ngram-count.cc: (.text+0x3d9): undefined reference to `LHash<unsigned int, unsigned int>::~LHash()'
    ngram-count.o:ngram-count.cc: (.text+0x3e4): undefined reference to `LHash<unsigned int, unsigned int>::~LHash()'
    ngram-count.o:ngram-count.cc: (.text+0x3fe): undefined reference to `LHash<char const*, unsigned int>::~LHash()'

    .
    .
    .
    and so on.

    Compiling this program is very important to me I dont know how to work with linux codes. could you please help me to compile these codes.

    Thanks alot

    my mail address is mybb30 AT yahoo dot com

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Code:
    OBJ_READMATRIX=ngram-count.o
    I don't feel like downloading the package -- but there's only one source file in the package? Are you sure?

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    10
    yes I am sure about that. in src folder there are 18 c files and 8 .h files.
    I am getting confused. I dont know what to do. i dont know where is the error? maybe my cygwin has some parameters that i must change them.

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So why didn't you list the 18 source files where you're supposed to list them (in the line I quoted above)?

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    10
    you are right but I don't know where and how to list them in my make file? I know nothing about linux and makefiles.

  9. #9
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by andereasmehdi View Post
    you are right but I don't know where and how to list them in my make file? I know nothing about linux and makefiles.
    It's never to late to learn

    GNU `make'

    Hopefully you know something about programming and compiling...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by andereasmehdi View Post
    you are right but I don't know where and how to list them in my make file? I know nothing about linux and makefiles.
    That's why I quoted the list you had of them, with only one file in it. Surely you can take that one file into more than one file?

  11. #11
    Registered User
    Join Date
    Jun 2011
    Posts
    10
    hi
    @MK27: thanks for your helpful links. But MK27 i don't want to learn C++, also it has not syntactic error. I don't know how to compile C++ in Cygwin.
    @tabstop: I changed Opt_Parse(argc, argv, options, Opt_Number(options), 0); to std::Opt_Parse(argc, argv, options, Opt_Number(options), 0); and it works!!!
    I skip those errors. and these are new one

    g++ -g -O3 -Wno-deprecated -c -o ngram-count.o ngram-count.cc
    In file included from ngram-count.cc:17:
    option.h:25:24: error: cfuncproto.h: No such file or directory
    ngram-count.cc:18:18: error: File.h: No such file or directory
    ngram-count.cc:19:19: error: Vocab.h: No such file or directory
    ngram-count.cc:20:22: error: SubVocab.h: No such file or directory
    ngram-count.cc:21:19: error: Ngram.h: No such file or directory
    ngram-count.cc:22:22: error: VarNgram.h: No such file or directory
    ngram-count.cc:23:25: error: TaggedNgram.h: No such file or directory
    ngram-count.cc:24:23: error: SkipNgram.h: No such file or directory
    ngram-count.cc:25:23: error: StopNgram.h: No such file or directory
    ngram-count.cc:26:24: error: NgramStats.h: No such file or directory
    ngram-count.cc:27:30: error: TaggedNgramStats.h: No such file or directory


    i checked the ALL_INCLUDES = -I./ -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/srilm and it is were my headers are there.

  12. #12
    Registered User
    Join Date
    Jun 2011
    Posts
    10
    hi tabstop, thanks for your useful tips. I understand you a little now. i changed OBJ_READMATRIX= ngram-count.o to OBJ_READMATRIX= Vocab.o option.o ngram-count.o and it works! I mean one of the errors get lost.
    But you know I ran into another one. here is error:
    Vocab.cc: In member function `VocabIndex Vocab::metaTagOfType(unsigned int)': Vocab.cc:253: error: expected primary-expression before "char".

    here is my Vocab.h:

    Code:
    /*
     * Vocab.h --
     *	Interface to the Vocab class.
     *
     *
     * SYNOPSIS
     *
     * Vocab represents sets of string tokens as typically used for vocabularies,
     * word class names, etc.  Additionally, Vocab provides a mapping from
     * such string tokens (type VocabString) to integers (type VocabIndex).
     * VocabIndex is typically used to index words in language models to
     * conserve space and speed up comparisons etc.  Thus, Vocab essentially
     * implements a symbol table into which strings can be "interned."
     *
     * INTERFACE
     *
     * VocabIndex(VocabIndex start, VocabIndex end)
     *	Initializes a Vocab and sets the index range.
     *	Indices are allocated starting at start and incremented from there.
     *	No indices are allowed beyond end.
     *	This provides a way to map several distinct Vocabs to disjoint
     *	ranges of integers, and then use them jointly without danger of
     *	confusion.
     *
     * VocabIndex addWord(VocabString token)
     *	Adds a new string to the Vocab, returning the assigned index,
     *	or looks up the index if the token already exists.
     *
     * VocabString getWord(VocabIndex index)
     *	Returns the string token associated with index, or 0 if it none
     *	exists.
     *
     * VocabIndex getIndex(VocabString token)
     *	Returns the index for a string token, or Vocab_None if none exists.
     *
     * void remove(VocabString token)
     * void remove(VocabIndex index)
     *	Deletes an item from the Vocab, either by token or by index.
     *
     * unsigned int numWords()
     *	Returns the number of tokens (and indices) in the Vocab.
     *
     * VocabIndex highIndex()
     *	Returns the highest word index in use, or Vocab_None if 
     *	vocabulary is empty.
     *
     * ITERATION
     *
     * VocabIter implements iterations over Vocabs. 
     *
     * VocabIter(Vocab &vocab)
     *	Creates and initializes an iteration over vocab.
     *
     * void init()
     *	Reset an iteration to the "first" element.
     *
     * VocabString next()
     * VocabString next(VocabIndex &index)
     *	Returns the next Vocab token in an iteration, or 0 if the
     *	iteration is finished.  index is set to the corresponding
     *	index.
     *
     * unsigned int read(File &file)
     *	Read a word list from a file into the Vocab, implicitly performing
     *	an addWord() on each token read.  Returns the number of tokens read.
     *
     * void write(File &file)
     *	Write the current set of word tokes to a file, in random order.
     *
     * NOTE: While an iteration over a Vocab is ongoing, no modifications
     * are allowed to the Vocab, EXCEPT possibly removal of the
     * "current" token/index.
     *
     * An iteration returns the elements of a Vocab in random, but deterministic
     * order. Furthermore, when copied or used in initialization of other objects,
     * VocabIter objects retain the current "position" in an iteration.  This
     * allows nested iterations that enumerate all pairs of distinct elements.
     *
     * Copyright (c) 1995-2010 SRI International.  All Rights Reserved.
     *
     * @(#)$Header: /home/srilm/devel/lm/src/RCS/Vocab.h,v 1.41 2010/06/02 05:49:58 stolcke Exp $
     *
     */
    
    #ifndef _Vocab_h_
    #define _Vocab_h_
    
    #ifdef PRE_ISO_CXX
    # include <iostream.h>
    #else
    # include <iostream>
    using namespace std;
    #endif
    
    #include "Boolean.h"
    #include "File.h"
    #include "LHash.h"
    #include "SArray.h"
    #include "Array.h"
    #include "MemStats.h"
    
    #ifdef USE_SHORT_VOCAB
    typedef unsigned short	VocabIndex;
    #else
    typedef unsigned int	VocabIndex;
    #endif
    typedef const char	*VocabString;
    
    const unsigned int	maxWordLength = 1024;
    
    const VocabIndex	Vocab_None = (VocabIndex)-1;
    
    const VocabString	Vocab_Unknown = "<unk>";
    const VocabString	Vocab_SentStart = "<s>";
    const VocabString	Vocab_SentEnd = "</s>";
    const VocabString	Vocab_Pause = "-pau-";
    
    typedef int (*VocabIndexComparator)(VocabIndex, VocabIndex);
    typedef int (*VocabIndicesComparator)(const VocabIndex *, const VocabIndex *);
    
    class Vocab
    {
        friend class VocabIter;
    
    public:
        Vocab(VocabIndex start = 0, VocabIndex end = (Vocab_None-1));
        virtual ~Vocab() {};
    
        virtual VocabIndex addWord(VocabString name);
        virtual VocabIndex addWordAlias(VocabIndex word, VocabString name);
        virtual VocabString getWord(VocabIndex index);
        virtual VocabIndex getIndex(VocabString name,
    				    VocabIndex unkIndex = Vocab_None);
        virtual void remove(VocabString name);
        virtual void remove(VocabIndex index);
        virtual unsigned int numWords() const { return byName.numEntries(); };
        virtual VocabIndex highIndex() const;
    
        /*
         * Special (pseudo-) vocabulary tokens
         */
        virtual VocabIndex &unkIndex() { return _unkIndex; };  /* <unk> index */
        virtual VocabIndex &ssIndex() { return _ssIndex; };	   /* <s> index */
        virtual VocabIndex &seIndex() { return _seIndex; };	   /* </s> index */
        virtual VocabIndex &pauseIndex() { return _pauseIndex; }; /* -pau- index */
    
        virtual Boolean &unkIsWord() { return _unkIsWord; };
    					/* consider <unk> a regular word */
    
        virtual Boolean &toLower() { return _toLower; };
    					/* map word strings to lowercase */
    
        /*
         * Some Vocab tokens/indices are "pseudo words", i.e., they don't
         * get probabilities since they can only occur in contexts.
         */
        virtual Boolean isNonEvent(VocabString word)	/* pseudo-word? */
    	{ return isNonEvent(getIndex(word)); };
        virtual Boolean isNonEvent(VocabIndex word) const	/* non-event? */
    	{ return (!_unkIsWord && (word == _unkIndex)) ||
    		 nonEventMap.find(word) != 0; };
    
        virtual VocabIndex addNonEvent(VocabIndex word);
        virtual VocabIndex addNonEvent(VocabString name)
    	{ return addNonEvent(addWord(name)); };
        virtual Boolean addNonEvents(Vocab &nonevents);
        virtual Boolean removeNonEvent(VocabIndex word);
    
        /*
         * Handling of meta-count tags: these are tags that represent a token
         * count total, or a type frequency count (count-of-count).
         * If metaTag == "__META__", the following tags acquire special meaning:
         *
         *	__META__		a word count total
         *	__META__1		count of singleton word types
         *	__META__2		count of word types occurring twice
         *	...			...
         *	__META__N		count of word types occurring N times
         */
        virtual VocabString &metaTag() { return _metaTag; }; /* meta-count tag */
        Boolean isMetaTag(VocabIndex word)
    	{ return metaTagMap.find(word) != 0; };
        unsigned typeOfMetaTag(VocabIndex word)
    	{ unsigned *type = metaTagMap.find(word);
    	  return type != 0 ? *type : (unsigned)-1; };
        VocabIndex metaTagOfType(unsigned);
    
        /*
         * Utilities for handling Vocab sequences
         */
        virtual unsigned int getWords(const VocabIndex *wids,
    			  VocabString *words, unsigned int max);
        virtual unsigned int addWords(const VocabString *words,
    			  VocabIndex *wids, unsigned int max);
        virtual unsigned int getIndices(const VocabString *words,
    			    VocabIndex *wids, unsigned int max,
    			    VocabIndex unkIndex = Vocab_None);
        virtual Boolean checkWords(const VocabString *words,
    			       VocabIndex *wids, unsigned int max);
        static unsigned int parseWords(char *line,
    				   VocabString *words, unsigned int max);
    
        static unsigned int length(const VocabIndex *words);
        static unsigned int length(const VocabString *words);
        static VocabIndex *copy(VocabIndex *to, const VocabIndex *from);
        static VocabString *copy(VocabString *to, const VocabString *from);
        static VocabIndex *reverse(VocabIndex *words);
        static Boolean contains(const VocabIndex *words, VocabIndex word);
        static VocabString *reverse(VocabString *words);
        static void write(File &file, const VocabString *words);
    
        /*
         *  Comparison of Vocabs and their sequences
         */
        static int compare(VocabIndex word1, VocabIndex word2);
    				/* order on word indices induced by Vocab */
        static int compare(VocabString word1, VocabString word2)
    	{ return strcmp(word1, word2); };
        static int compare(const VocabIndex *word1, const VocabIndex *word2);
    				/* order on word index sequences */
        static int compare(const VocabString *word1, const VocabString *word2);
    
        VocabIndexComparator compareIndex() const;
        VocabIndicesComparator compareIndices() const;
        Boolean ngramsInRange(VocabString *startRange, VocabString *endRange);
    
        /*
         * Miscellaneous
         */
        virtual unsigned int read(File &file);
        virtual unsigned int readAliases(File &file);
        virtual void write(File &file, Boolean sorted = true) const;
        virtual void use() const { outputVocab = (Vocab *)this; }; // discard const
    
        virtual Boolean readIndexMap(File &file, Array<VocabIndex> &map,
    						Boolean limitVocab = false);
        virtual void writeIndexMap(File &file);
    
        virtual void memStats(MemStats &stats) const;
    
        static Vocab *outputVocab;  /* implicit parameter to operator<< */
    
        static Vocab *compareVocab;	/* implicit parameter to compare() */
    protected:
        LHash<VocabString,VocabIndex> byName;
        Array<VocabString> byIndex;
        VocabIndex nextIndex;
        VocabIndex maxIndex;
    
        LHash<VocabIndex, unsigned> nonEventMap;	/* set of non-event words */
        LHash<VocabIndex, unsigned> metaTagMap;	/* maps metatags to their type:
    						   0	count total
    						   1	single counts
    						   ...
    						   N	count of count N */
    
        // hidden data members (accessed through virtual functions
        VocabIndex _unkIndex;		/* <unk> index */
        VocabIndex _ssIndex;		/* <s> index */
        VocabIndex _seIndex;		/* </s> index */
        VocabIndex _pauseIndex;		/* -pau- index */
        Boolean _unkIsWord;			/* consider <unk> a regular word */
        Boolean _toLower;			/* map word strings to lowercase */
        VocabString _metaTag;		/* meta-count tag */
    };
    
    ostream &operator<< (ostream &, const VocabString *words);
    ostream &operator<< (ostream &, const VocabIndex *words);
    
    class VocabIter
    {
    public:
        VocabIter(const Vocab &vocab, Boolean sorted = false);
        void init();
        VocabString next() { VocabIndex index; return next(index); };
        VocabString next(VocabIndex &index);
    private:
        LHa........er<VocabString,VocabIndex> myIter;
    };
    
    /* 
     * We sometimes use strings over VocabIndex as keys into maps.
     * Define the necessary support functions (see Map.h, LHash.cc, SArray.cc).
     */
    static inline unsigned
    LHash_hashKey(const VocabIndex *key, unsigned maxBits)
    {
        unsigned i = 0;
    
        /*
         * The rationale here is similar to LHash_hashKey(unsigned),
         * except that we shift more to preserve more of the typical number of
         * bits in a VocabIndex.  The value was optimized to encoding 3 words
         * at a time (trigrams).
         */
        for (; *key != Vocab_None; key ++) {
    	i += (i << 12) + *key;
        }
        return LHash_hashKey(i, maxBits);
    }
    
    static inline const VocabIndex *
    Map_copyKey(const VocabIndex *key)
    {
        VocabIndex *copy = new VocabIndex[Vocab::length(key) + 1];
        assert(copy != 0);
    
        unsigned i;
        for (i = 0; key[i] != Vocab_None; i ++) {
    	copy[i] = key[i];
        }
        copy[i] = Vocab_None;
    
        return copy;
    }
    
    static inline void
    Map_freeKey(const VocabIndex *key)
    {
        delete [] (VocabIndex *)key;
    }
    
    static inline Boolean
    LHash_equalKey(const VocabIndex *key1, const VocabIndex *key2)
    {
        unsigned i;
        for (i = 0; key1[i] != Vocab_None && key2[i] != Vocab_None; i ++) {
    	if (key1[i] != key2[i]) {
    	    return false;
    	}
        }
        if (key1[i] == Vocab_None && key2[i] == Vocab_None) {
    	return true;
        } else {
    	return false;
        }
    }
         
    static inline int
    SArray_compareKey(const VocabIndex *key1, const VocabIndex *key2)
    {
        unsigned int i = 0;
    
        for (i = 0; ; i++) {
    	if (key1[i] == Vocab_None) {
    	    if (key2[i] == Vocab_None) {
    		return 0;
    	    } else {
    		return -1;	/* key1 is shorter */
    	    }
    	} else {
    	    if (key2[i] == Vocab_None) {
    		return 1;	/* key2 is shorted */
    	    } else {
    		int comp = SArray_compareKey(key1[i], key2[i]);
    		if (comp != 0) {
    		    return comp;	/* they differ at pos i */
    		}
    	    }
    	}
        }
        /*NOTREACHED*/
    }
    
    #endif /* _Vocab_h_ */
    Thanks for your tips. but It takes a while to me to understand it. so I already Thank for everything.

  13. #13
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    But you know I ran into another one. here is error:
    Vocab.cc: In member function `VocabIndex Vocab::metaTagOfType(unsigned int)': Vocab.cc:253: error: expected primary-expression before "char".
    And we're supposed to be psychic and know what line 253 of Vocab.cc contains?

    Code:
    LHa........er<VocabString,VocabIndex> myIter;
    LOL...pwn3d by the filter!

  14. #14
    Registered User
    Join Date
    Jun 2011
    Posts
    10
    LOL

    Here is the Line that makes the error:
    Code:
    makeArray(char, tagName, strlen(_metaTag) + 20);
    I know that we can not pass a type as an argument but I don't know maybe it is a macro or something
    I checked all the files but there is no definition for makeArray I am confused.
    all files just use makeArray !!!
    maybe you want to see Array.cc:
    Code:
    /*
     * Array.cc --
     *	Extensible array implementation
     *
     */
    
    #ifndef _Array_cc_
    #define _Array_cc_
    
    #ifndef lint
    static char Array_Copyright[] = "Copyright (c) 1995,1997 SRI International.  All Rights Reserved.";
    static char Array_RcsId[] = "@(#)$Header: /home/cvsb2/semanlm/include/srilm/Array.cc,v 1.1 2006/01/12 14:48:17 pucher Exp $";
    #endif
    
    #include <assert.h>
    #include <stdlib.h>
    #include <string.h>
    
    #include "C:\cygwin\semanlm\include\srilm\Array.h"
    
    #undef INSTANTIATE_ARRAY
    #define INSTANTIATE_ARRAY(DataT) \
    	template class Array<DataT>
    
    /*
     * extend the size of an Array to accomodate size elements
     * 	Note we want to zero-initialize the data elements by default,
     *	so we call their initializers with argument 0.  This means
     *	that all data type used as arguments to the Array template
     *	need to provide an initializer that accepts 0 as a single argument.
     */
    template <class DataT>
    void
    Array<DataT>::alloc(unsigned int size)
    {
        unsigned int newSize = size + 1 + alloc_size/2;
        DataT *newData = new DataT[newSize];
        assert(newData != 0);
    
    #ifdef ZERO_INITIALIZE
        memset(newData, 0, newSize * sizeof(DataT));
    #endif
    
        for (unsigned i = 0; i < alloc_size; i++) {
    	newData[i] = _data[i];
        }
    
        delete [] _data;
    
        _data = newData;
        alloc_size = newSize;
    }
    
    template <class DataT>
    void
    Array<DataT>::memStats(MemStats &stats) const
    {
        stats.total += _size * sizeof(_data[0]);
        stats.wasted += (alloc_size - _size) * sizeof(_data[0]);
    }
    
    template <class DataT>
    Array<DataT> &
    Array<DataT>::operator= (const Array<DataT> &other)
    {
        // cerr << "warning: Array::operator= called\n";
    
        if (&other == this) {
    	return *this;
        }
    
        delete [] _data;
    
        _base = other._base;
        _size = other._size;
        alloc_size = other.alloc_size;
    
        _data = new DataT[alloc_size];
        assert(_data != 0);
    
    #ifdef ZERO_INITIALIZE
        memset(_data, 0, alloc_size * sizeof(DataT));
    #endif
    
        for (unsigned i = 0; i < alloc_size; i++) {
    	_data[i] = other._data[i];
        }
    
        return *this;
    }
    
    #endif /* _Array_cc_ */

  15. #15
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LwIP issue: "undefined reference".
    By DaMunky89 in forum Windows Programming
    Replies: 6
    Last Post: 01-16-2011, 12:29 PM
  2. Replies: 4
    Last Post: 12-16-2008, 08:00 PM
  3. Error "undefined reference to"
    By Bargi in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2007, 05:12 AM
  4. Error "undefined reference to"
    By Bargi in forum Linux Programming
    Replies: 1
    Last Post: 09-13-2007, 04:47 AM
  5. Replies: 5
    Last Post: 06-01-2006, 04:37 PM