Thread: Linker error

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    40

    Linker error

    I have been chasing this bug all night! When I go to link my code it gives me the error:

    webCrawlerTest.cpp.text+0x1ad): undefined reference to `stopWord::Test(std::basic_ostream<char, std::char_traits<char> >&)'
    It is called from here:

    Code:
    int main(int argc, char* argv[])
    {
    	LinkedList<string>::Test(cout);
    	HashSet<string>::Test(cout);
    	stopWord::Test(cout);  //HERE IS THE FUNCTION CALL
    	return 0;
    }
    The class it's calling is here:

    Code:
    include "stopWord.h"
    #include "UnitTest.h"
    #include <sstream>
    using namespace std;
    
    //Include file has a private HashSet called stopWords that contains all the stop words
    stopWord::stopWord(std::fstream & file)
    {
    	string line, word;
    	
    	while(file>>line)
    	{
    		std::stringstream wholeLine(line);
    		
    		while(wholeLine>>word)
    			stopWords.Add(&word);
    	}
    }
    
    bool stopWord::Contains(std::string &s)
    {
    	return stopWords.Contains(s);
    }
    
    static bool Test(ostream & os)
    {
    	os<<"Begin stop word testing\r\n";
    	bool success = true;
    	
    	fstream file;
    	file.open("tests/stop.txt");
    	TEST(file);
    	stopWord test(file);
    	
    	string testStr="been";
    	TEST(test.Contains(testStr));
    	testStr="into";
    	TEST(test.Contains(testStr));
    	testStr="z";
    	TEST(test.Contains(testStr));
    	testStr="mancala";
    	TEST(!test.Contains(testStr));
    	
    	file.close();
    	return success;
    }
    Finally for completness' sake, here is the makefile I'm using. It should be easy to understand.

    Code:
    # Dustin Nicholes
    # CS 240 makefile project
    # October 8, 2008
    
    BIN_FILE = bin/webCrawler
    OBJ_FILES = obj/webCrawler.o  obj/stopWord.o obj/URL.o
    TEST_OBJ = obj/webCrawlerTest.o obj/stopWord.o obj/URL.o
    HEADER_FILES = inc/URL.h inc/HashSet.h inc/LinkedList.h inc/stopWord.h
    LIB_OBJ = utils/obj/CommandRunner.o utils/obj/FileInputStream.o utils/obj/FileSystem.o utils/obj/HTTPInputStream.o utils/obj/InputStream.o\
    	 	utils/obj/StringUtil.o
    LIB_NAME = lib/cs240Utils.a
    TEST_FILE = bin/webCrawlerTest
    EXE_FILE = bin/webCrawler
    
    LIB = #-lboost_program_options -lboost_filesystem -lboost_iostreams
     
    #### bin command
    bin : $(BIN_FILE)
    	
    $(BIN_FILE) : $(OBJ_FILES) $(LIB_NAME) 
    	g++ -g -Wall -o $(BIN_FILE) $(OBJ_FILES) -lboost_regex $(LIB_NAME) 
    	chmod ugo+x $(BIN_FILE)
    	
    obj/webCrawler.o : src/webCrawler.cpp inc/HashSet.h inc/LinkedList.h inc/stopWord.h inc/URL.h
    			g++ -c -o obj/webCrawler.o -I utils/include -I inc src/webCrawler.cpp $(LIB)
    			
    obj/stopWord.o : src/stopWord.cpp inc/stopWord.h inc/HashSet.h inc/LinkedList.h inc/URL.h
    			g++ -c -o obj/stopWord.o -I utils/include -I inc src/stopWord.cpp $(LIB)
    			
    obj/URL.o : src/URL.cpp inc/HashSet.h inc/LinkedList.h inc/stopWord.h inc/URL.h
    			g++ -c -o obj/URL.o -I utils/include -I inc src/URL.cpp $(LIB)
    	
    run : $(EXE_FILE)
    	$(EXE_FILE)
    	
    #### test command
    test : $(TEST_FILE) run_test
    
    $(TEST_FILE) : $(TEST_OBJ) $(LIB_NAME)
    	g++ -g -Wall -o $(TEST_FILE) $(TEST_OBJ) -lboost_regex $(LIB_NAME)
    	chmod ugo+x $(TEST_FILE) 
    	
    obj/webCrawlerTest.o : src/webCrawlerTest.cpp inc/HashSet.h inc/LinkedList.h inc/stopWord.h inc/URL.h
    			g++ -c -o obj/webCrawlerTest.o -I utils/include -I inc src/webCrawlerTest.cpp $(LIB)
    
    run_test : $(TEST_FILE)
    	$(TEST_FILE)
    
    #### build lib files
    lib : $(LIB_NAME)
     
    $(LIB_NAME) : $(LIB_OBJ)  
    	ar r $(LIB_NAME) $(LIB_OBJ)
    
    utils/obj/CommandRunner.o : utils/src/CommandRunner.cpp utils/include/CS240Exception.h utils/include/StringUtil.h utils/include/CommandRunner.h
    	g++ -c -o utils/obj/CommandRunner.o -I utils/include utils/src/CommandRunner.cpp
    	
    utils/obj/FileInputStream.o : utils/src/FileInputStream.cpp utils/include/InputStream.h utils/include/FileInputStream.h utils/include/CS240Exception.h 
    	g++ -c -o utils/obj/FileInputStream.o -I utils/include utils/src/FileInputStream.cpp
    
    utils/obj/FileSystem.o : utils/src/FileSystem.cpp utils/include/FileSystem.h utils/include/CS240Exception.h utils/include/UnitTest.h
    	g++ -c -o utils/obj/FileSystem.o -I utils/include utils/src/FileSystem.cpp
    
    utils/obj/HTTPInputStream.o : utils/src/HTTPInputStream.cpp utils/include/CS240Exception.h \
    			utils/include/StringUtil.h utils/include/HTTPInputStream.h utils/include/InputStream.h 
    	g++ -c -o utils/obj/HTTPInputStream.o -I utils/include utils/src/HTTPInputStream.cpp
    
    utils/obj/InputStream.o : utils/src/InputStream.cpp utils/include/StringUtil.h utils/include/HTTPInputStream.h \
    		     utils/include/FileInputStream.h utils/include/InputStream.h
    	g++ -c -o utils/obj/InputStream.o -I utils/include utils/src/InputStream.cpp
    
    utils/obj/StringUtil.o : utils/src/StringUtil.cpp utils/include/StringUtil.h
    	g++ -c -o utils/obj/StringUtil.o -I utils/include utils/src/StringUtil.cpp
    
    #### clean command
    clean  :
    	- rm -f obj/*
    	- rm -f bin/*
    	- rm -f lib/*
    	- rm -f utils/obj/*
    PLEASE PLEASE PLEASE help. I can't figure this one out! Thanks you guys!

  2. #2
    Registered User
    Join Date
    Dec 2006
    Posts
    40
    And I'm trying to run make test. Take a look? Give some suggestions?

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    40
    Okay, since no one has responded, I will include the entire output of make test. It is:

    Code:
    g++ -c -o obj/webCrawler.o -I utils/include -I inc src/webCrawler.cpp 
    g++ -c -o obj/stopWord.o -I utils/include -I inc src/stopWord.cpp 
    g++ -c -o obj/URL.o -I utils/include -I inc src/URL.cpp 
    g++ -c -o utils/obj/CommandRunner.o -I utils/include utils/src/CommandRunner.cpp
    g++ -c -o utils/obj/FileInputStream.o -I utils/include utils/src/FileInputStream.cpp
    g++ -c -o utils/obj/FileSystem.o -I utils/include utils/src/FileSystem.cpp
    g++ -c -o utils/obj/HTTPInputStream.o -I utils/include utils/src/HTTPInputStream.cpp
    g++ -c -o utils/obj/InputStream.o -I utils/include utils/src/InputStream.cpp
    g++ -c -o utils/obj/StringUtil.o -I utils/include utils/src/StringUtil.cpp
    ar r lib/cs240Utils.a utils/obj/CommandRunner.o utils/obj/FileInputStream.o utils/obj/FileSystem.o utils/obj/HTTPInputStream.o utils/obj/InputStream.o utils/obj/StringUtil.o
    ar: creating lib/cs240Utils.a
    g++ -g -Wall -o bin/webCrawler obj/webCrawler.o  obj/stopWord.o obj/URL.o -lboost_regex lib/cs240Utils.a 
    obj/webCrawler.o: In function `main':
    webCrawler.cpp:(.text+0x1ad): undefined reference to `stopWord::Test(std::basic_ostream<char, std::char_traits<char> >&)'
    collect2: ld returned 1 exit status
    make: *** [bin/webCrawler] Error 1

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    static bool stopWord::Test(ostream & os)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Posts
    40
    Sorry to bother everyone, I just figured out my mistake! Thanks for looking.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No need to apologize. I found it almost at once, just after skimming through the code.
    No time spent pondering about your problem.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM