Gnarly Linking Error HELP!!!!

This is a discussion on Gnarly Linking Error HELP!!!! within the C++ Programming forums, part of the General Programming Boards category; Okay. Fairly complicated program involving templates, classes, and a driver program. All files are within the same directory. Pretty damn ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    40

    Gnarly Linking Error HELP!!!!

    Okay. Fairly complicated program involving templates, classes, and a driver program. All files are within the same directory. Pretty damn sure that all functions are defined and declaired... just not sure on the linking process with this many files. Using gnu g++ as a compiler.

    ERROR ->
    Code:
    brooksbp@brooksbp-laptop:~/csci2270/assign5$ g++ studentDemo.cxx -o test
    /tmp/ccZiNVfI.o: In function `main':
    studentDemo.cxx:(.text+0x88): undefined reference to `assignment5::create_database()'
    studentDemo.cxx:(.text+0x102): undefined reference to `assignment5::print_in_record(assignment5::heapnode<assignment5::studentRecord, int>*)'
    studentDemo.cxx:(.text+0x179): undefined reference to `assignment5::print_pre_record(assignment5::heapnode<assignment5::studentRecord, int>*)'
    studentDemo.cxx:(.text+0x1f0): undefined reference to `assignment5::print_post_record(assignment5::heapnode<assignment5::studentRecord, int>*)'
    studentDemo.cxx:(.text+0x26f): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
    studentDemo.cxx:(.text+0x2f6): undefined reference to `assignment5::change_major(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
    studentDemo.cxx:(.text+0x3a6): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
    studentDemo.cxx:(.text+0x425): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
    studentDemo.cxx:(.text+0x4f9): undefined reference to `assignment5::change_grade(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
    studentDemo.cxx:(.text+0x5a9): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
    studentDemo.cxx:(.text+0x628): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
    studentDemo.cxx:(.text+0x704): undefined reference to `assignment5::add_course(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long, int, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
    studentDemo.cxx:(.text+0x7b4): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
    studentDemo.cxx:(.text+0x82b): undefined reference to `assignment5::print_perfect_gpa(assignment5::heapnode<assignment5::studentRecord, int>*)'
    studentDemo.cxx:(.text+0x8aa): undefined reference to `assignment5::remove_student(assignment5::heapnode<assignment5::studentRecord, int>*&, unsigned long)'
    studentDemo.cxx:(.text+0x921): undefined reference to `assignment5::print_perfect_gpa(assignment5::heapnode<assignment5::studentRecord, int>*)'
    studentDemo.cxx:(.text+0xd03): undefined reference to `assignment5::add_student(assignment5::heapnode<assignment5::studentRecord, int>*&, assignment5::studentRecord const&)'
    studentDemo.cxx:(.text+0xd9d): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
    studentDemo.cxx:(.text+0xe14): undefined reference to `assignment5::print_in_record(assignment5::heapnode<assignment5::studentRecord, int>*)'
    studentDemo.cxx:(.text+0xe93): undefined reference to `assignment5::remove_student(assignment5::heapnode<assignment5::studentRecord, int>*&, unsigned long)'
    studentDemo.cxx:(.text+0xf0a): undefined reference to `assignment5::print_in_record(assignment5::heapnode<assignment5::studentRecord, int>*)'
    collect2: ld returned 1 exit status
    heap.h
    Code:
    #include <iostream>  
    #include <cstdlib>  // Provides NULL and size_t
    #include <stack>
    using namespace std;
    
    namespace assignment5
    {
        template <class Item, class Key>
        class heapnode
        {
    		//class stuff here
        };
    
    	template <class Process, class Item, class Key>
    	void inorder_processing(heapnode<Item, Key> *root, Process f);
    	template <class Process, class Item, class Key>
    	void preorder_processing(heapnode<Item, Key> *root, Process f);
    	template <class Process, class Item, class Key>
    	void postorder_processing(heapnode<Item, Key> *root, Process f);
    	template <class Item, class Key>
    	bool check_node(heapnode<Item, Key>* root, Key k);
    	template <class Item, class Key>
    	void insert_node(heapnode<Item, Key>*& root, Key k, const Item& entry);
    	template <class Item, class Key>
    	void remove_node(heapnode<Item, Key>*& root, Key k);
    	template <class Process, class Param, class Item, class Key>
    	bool process_node(heapnode<Item, Key> *root, Key k, Process f, Param p);
    	
    	template <class Item, class Key>
    	size_t size(heapnode<Item, Key> *root);
    	template <class Item, class Key>
    	heapnode<Item, Key>* freeParent(heapnode<Item, Key> *root);
    	template <class Item, class Key>
    	heapnode<Item, Key>* lastNode(heapnode<Item, Key> *root);
    	template <class Item, class Key>
    	void swap(heapnode<Item, Key> *a, heapnode<Item, Key> *b);
    	template <class Item, class Key>
    	heapnode<Item, Key>* search(heapnode<Item, Key> *root, Key k);
    
    	#include "heap.cxx"
    }
    heap.cxx
    Code:
    function declarations for all those template functions in heap.h here
    
    ie:
    
    template <class Process, class Item, class Key>
    void inorder_processing(heapnode<Item, Key> *root, Process f)
    {
    	if(root != NULL) {
    		inorder_processing(root->getLeft(), f);
    		f(root->getItem());
    		inorder_processing(root->getRight(), f);
    	}
    }
    
    ...and so on...
    studentDatabase.h
    Code:
    #include <iostream>  
    #include <cstdlib>  // Provides NULL and size_t
    #include <string>
    #include <vector>
    #include "heap.h"
      
    using namespace std;
    
    //new data type for SID
    typedef unsigned long SID;
    
    namespace assignment5
    {
        class studentRecord
        {
    		//class stuff here
        };
    
    	void add_student(heapnode<studentRecord, int>*& root, const studentRecord& record);
        bool remove_student(heapnode<studentRecord, int>*& root, SID id);
        bool print_record(heapnode<studentRecord, int>* root, SID id);
        void print_in_record(heapnode<studentRecord, int>* root);
        void print_pre_record(heapnode<studentRecord, int>* root);
        void print_post_record(heapnode<studentRecord, int>* root);
        void print_perfect_gpa(heapnode<studentRecord, int>* root);
        bool add_course(heapnode<studentRecord, int>* root, SID id, int c_num, int c_hours, string grade);
        bool change_major(heapnode<studentRecord, int>* root, SID id, string new_major);
        bool change_grade(heapnode<studentRecord, int>* root, SID id, int c_num, string new_grade);
        heapnode<studentRecord, int>* create_database();
    }
    studentDatabase.cxx
    Code:
    #include <iostream>  // Provides cin and cout
    #include <cstdlib>   // Provides EXIT_SUCCESS
    #include "studentDatabase.h"   
    using namespace std;
    
    namespace assignment5
    {
            //FUNCTION DECLARATIONS HERE SUCH AS THE FOLLOWING ->
    	
            void add_student(heapnode<studentRecord, int>*& root, const studentRecord& record)
    	{
    		SID sid = record.get_sid();
    		insert_node(root, sid, record); 
    	}
    
    }
    studentDemo.cxx
    Code:
    #include <iostream>  // Provides cin and cout
    #include <cstdlib>   // Provides EXIT_SUCCESS   
    #include "studentDatabase.h"   
    using namespace std;
    using namespace assignment5;
    
    int main( )
    {
        heapnode<studentRecord, int> *mydb;
        
        mydb = create_database( );
    
        cout << "------------------------------------" << endl;
        cout << "PRINTING STUDENT RECORDS IN IN-ORDER" << endl;
        cout << "------------------------------------" << endl;
        print_in_record(mydb);
        
        cout << "------------------------------------" << endl;
        cout << "PRINTING STUDENT RECORDS IN PRE-ORDER" << endl;
        cout << "------------------------------------" << endl;
        print_pre_record(mydb);
        
        cout << "------------------------------------" << endl;
        cout << "PRINTING STUDENT RECORDS IN POST-ORDER" << endl;
        cout << "------------------------------------" << endl;
        print_post_record(mydb);
        
        
     
        cout << "------------------------------------" << endl;
        cout << "PRINTING RECORD OF A SPECIFIC STUDENT" << endl;
        cout << "------------------------------------" << endl;
        print_record(mydb, 139057);
    
        cout << "------------------------------------" << endl;
        cout << "CHANGE MAJOR OF THE STUDENT" << endl;
        
        change_major(mydb, 139057, "Electrical Engineering");
    
        cout << "------------------------------------" << endl;
        cout << "PRINTING RECORD OF THE STUDENT WITH CHANGED MAJOR" << endl;
        cout << "------------------------------------" << endl;
        print_record(mydb, 139057);
    
        cout << "------------------------------------" << endl;
        cout << "PRINTING RECORD OF A SPECIFIC STUDENT" << endl;
        cout << "------------------------------------" << endl;
        print_record(mydb, 992654);
    
        cout << "------------------------------------" << endl;
        cout << "CHANGE GRADE OF THE STUDENT" << endl;
        cout << "------------------------------------" << endl;
        change_grade(mydb, 992654, 5463, "B+");
    
        cout << "------------------------------------" << endl;
        cout << "PRINTING RECORD OF THE STUDENT WITH CHANGED GRADE" << endl;
        cout << "------------------------------------" << endl;
        print_record(mydb, 992654);
    
        cout << "------------------------------------" << endl;
        cout << "PRINTING RECORD OF A SPECIFIC STUDENT" << endl;
        cout << "------------------------------------" << endl;
        print_record(mydb, 448720);
    
        cout << "------------------------------------" << endl;
        cout << "ADD A COURSE TO THE STUDENT RECORD" << endl;
        cout << "------------------------------------" << endl;
        add_course(mydb, 448720, 2463, 4, "B-");
    
        cout << "------------------------------------" << endl;
        cout << "PRINTING RECORD OF THE STUDENT WITH COURSE ADDED" << endl;
        cout << "------------------------------------" << endl;
        print_record(mydb, 448720);
    
        cout << "------------------------------------" << endl;
        cout << "PRINTING STUDENT ID AND NAMES OF STUDENTS WITH PERFECT GPA"
    	 << endl;
        cout << "------------------------------------" << endl;
        print_perfect_gpa(mydb);
    
        cout << "------------------------------------" << endl;
        cout << "REMOVING A STUDENT RECORD" << endl;
        cout << "------------------------------------" << endl;
        remove_student(mydb, 810001);
    
        cout << "------------------------------------" << endl;
        cout << "PRINTING STUDENT ID AND NAMES OF STUDENTS WITH PERFECT GPA"
    	 << endl;
        cout << "------------------------------------" << endl;
        print_perfect_gpa(mydb);
    
        cout << "------------------------------------" << endl;
        cout << "ADDING A NEW STUDENT RECORD" << endl;
        cout << "------------------------------------" << endl;
    
        /* NOTE: You will have to modify the following, depending on
           your definitions of courseList and studentRecord */
    
        studentRecord s;
        s.set_sid(999999);
        s.set_name("Thomas L. Jackson");
        s.set_major("Computer Science");   
        s.add_course(4567, 4, "B-");
        s.add_course(2220, 3, "A");
        s.add_course(5621, 2, "A-");
        s.add_course(4578, 3, "C+");
        
        add_student(mydb, s);
    
        cout << "------------------------------------" << endl;
        cout << "PRINTING RECORD OF THE NEW STUDENT" << endl;
        cout << "------------------------------------" << endl;
        print_record(mydb, 999999);
    
        cout << "------------------------------------" << endl;
        cout << "PRINTING STUDENT RECORDS IN IN-ORDER" << endl;
        cout << "------------------------------------" << endl;
        print_in_record(mydb);
    
        cout << "------------------------------------" << endl;
        cout << "REMOVING A STUDENT RECORD" << endl;
        cout << "------------------------------------" << endl;
    
        remove_student(mydb, 323251);
    
        cout << "------------------------------------" << endl;
        cout << "PRINTING STUDENT RECORDS IN IN-ORDER" << endl;
        cout << "------------------------------------" << endl;
        print_in_record(mydb);
    
    	return EXIT_SUCCESS;
    }

  2. #2
    Registered User
    Join Date
    May 2007
    Posts
    88
    Try compiling with this command instead:

    Code:
    g++ studentDemo.cxx studentDatabase.cxx -o test

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    40
    nah.... that produces->

    ...or... is that the right way to compile it, and those are all bugs? If so, how do i dereference a pointer to a class and call the member function... like target->getData() ? but that's giving me an error...

    plus, it's not recognizing the heap functions

    Code:
    brooksbp@brooksbp-laptop:~/csci2270/assign5$ g++ studentDemo.cxx studentDatabase.cxx -o test
    studentDatabase.cxx: In function ‘void assignment5::add_student(assignment5::heapnode<assignment5::studentRecord, int>*&, const assignment5::studentRecord&)’:
    studentDatabase.cxx:14: error: passing ‘const assignment5::studentRecord’ as ‘this’ argument of ‘SID assignment5::studentRecord::get_sid()’ discards qualifiers
    studentDatabase.cxx:15: error: no matching function for call to ‘insert_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&, const assignment5::studentRecord&)’
    studentDatabase.cxx: In function ‘bool assignment5::remove_student(assignment5::heapnode<assignment5::studentRecord, int>*&, SID)’:
    studentDatabase.cxx:20: error: no matching function for call to ‘check_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:23: error: no matching function for call to ‘remove_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx: In function ‘bool assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, SID)’:
    studentDatabase.cxx:30: error: no matching function for call to ‘check_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:33: error: no matching function for call to ‘search(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:34: error: ‘class assignment5::heapnode<assignment5::studentRecord, int>’ has no member named ‘get_id’
    studentDatabase.cxx:35: error: ‘class assignment5::heapnode<assignment5::studentRecord, int>’ has no member named ‘get_name’
    studentDatabase.cxx:36: error: ‘class assignment5::heapnode<assignment5::studentRecord, int>’ has no member named ‘get_major’
    studentDatabase.cxx:38: error: ‘class assignment5::heapnode<assignment5::studentRecord, int>’ has no member named ‘get_course_number’
    studentDatabase.cxx:39: error: ‘class assignment5::heapnode<assignment5::studentRecord, int>’ has no member named ‘get_course_credit’
    studentDatabase.cxx:40: error: ‘class assignment5::heapnode<assignment5::studentRecord, int>’ has no member named ‘get_course_grade’
    studentDatabase.cxx: In function ‘bool assignment5::add_course(assignment5::heapnode<assignment5::studentRecord, int>*, SID, int, int, std::string)’:
    studentDatabase.cxx:65: error: no matching function for call to ‘check_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:68: error: no matching function for call to ‘search(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:69: error: ‘class assignment5::heapnode<assignment5::studentRecord, int>’ has no member named ‘add_course’
    studentDatabase.cxx: In function ‘bool assignment5::change_major(assignment5::heapnode<assignment5::studentRecord, int>*, SID, std::string)’:
    studentDatabase.cxx:76: error: no matching function for call to ‘check_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:79: error: no matching function for call to ‘search(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:80: error: ‘class assignment5::heapnode<assignment5::studentRecord, int>’ has no member named ‘set_major’
    studentDatabase.cxx: In function ‘bool assignment5::change_grade(assignment5::heapnode<assignment5::studentRecord, int>*, SID, int, std::string)’:
    studentDatabase.cxx:87: error: no matching function for call to ‘check_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:90: error: no matching function for call to ‘search(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:91: error: ‘class assignment5::heapnode<assignment5::studentRecord, int>’ has no member named ‘set_grade’
    studentDatabase.cxx: In function ‘assignment5::heapnode<assignment5::studentRecord, int>* assignment5::create_database()’:
    studentDatabase.cxx:117: error: ‘class assignment5::studentRecord’ has no member named ‘set_course_count’
    brooksbp@brooksbp-laptop:~/csci2270/assign5$

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    88
    You need to include heap.cxx in the compile command as well, I missed that before. All of your sources (not headers, at least not in this case) need to be included.

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    40
    Still doesn't work. Spits out about 75 more lines of errors

  6. #6
    Registered User
    Join Date
    May 2007
    Posts
    88
    Sorry, you don't have to include heap.cxx in the compile command, I didn't notice before that it was a compiled header (which, BTW, you should consider an extension like .hxx instead...). Maybe post some of the errors if you can't figure them out...

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    40
    I just don't understand why it wont recognize the heap functions even though heap.h is included????

    Code:
    brooksbp@brooksbp-laptop:~/csci2270/assign5$ g++ studentDemo.cxx -o test
    studentDatabase.cxx: In function ‘void assignment5::add_student(assignment5::heapnode<assignment5::studentRecord, int>*&, const assignment5::studentRecord&)’:
    studentDatabase.cxx:14: error: passing ‘const assignment5::studentRecord’ as ‘this’ argument of ‘SID assignment5::studentRecord::get_sid()’ discards qualifiers
    studentDatabase.cxx:15: error: no matching function for call to ‘insert_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&, const assignment5::studentRecord&)’
    studentDatabase.cxx: In function ‘bool assignment5::remove_student(assignment5::heapnode<assignment5::studentRecord, int>*&, SID)’:
    studentDatabase.cxx:20: error: no matching function for call to ‘check_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:23: error: no matching function for call to ‘remove_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx: In function ‘bool assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, SID)’:
    studentDatabase.cxx:30: error: no matching function for call to ‘check_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:33: error: no matching function for call to ‘search(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:37: error: ‘class assignment5::studentRecord’ has no member named ‘get_id’
    studentDatabase.cxx:44: error: conversion from ‘std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >’ to non-scalar type ‘std::vector<int, std::allocator<int> >’ requested
    studentDatabase.cxx: In function ‘bool assignment5::add_course(assignment5::heapnode<assignment5::studentRecord, int>*, SID, int, int, std::string)’:
    studentDatabase.cxx:106: error: no matching function for call to ‘check_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:109: error: no matching function for call to ‘search(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx: In function ‘bool assignment5::change_major(assignment5::heapnode<assignment5::studentRecord, int>*, SID, std::string)’:
    studentDatabase.cxx:118: error: no matching function for call to ‘check_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:121: error: no matching function for call to ‘search(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx: In function ‘bool assignment5::change_grade(assignment5::heapnode<assignment5::studentRecord, int>*, SID, int, std::string)’:
    studentDatabase.cxx:130: error: no matching function for call to ‘check_node(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    studentDatabase.cxx:133: error: no matching function for call to ‘search(assignment5::heapnode<assignment5::studentRecord, int>*&, SID&)’
    brooksbp@brooksbp-laptop:~/csci2270/assign5$

  8. #8
    Registered User
    Join Date
    Oct 2005
    Posts
    271
    Huh?
    Code:
    ....
    	heapnode<Item, Key>* search(heapnode<Item, Key> *root, Key k);
    
    	#include "heap.cxx"
    }
    Shouldn't the include directive be outside the class definition?

    [edit] Whoops, didn't see was inside a namespace.
    Last edited by cunnus88; 05-04-2007 at 12:11 AM. Reason: irrelevant comment

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Why do I get the feeling you wrote a whole mass of code and then tried to compile it?

    I mean, you could have figured out that approach wouldn't work after the first function, not the 20th.

    Compile early and often, then you don't dig these massive holes.

    A development process
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems linking with g++
    By Just in forum Linux Programming
    Replies: 11
    Last Post: 07-24-2006, 01:35 AM
  2. strange linking error -- can not find shared library
    By George2 in forum C Programming
    Replies: 2
    Last Post: 07-10-2006, 10:51 PM
  3. Replies: 8
    Last Post: 04-27-2006, 10:39 AM
  4. Grrr.... SDL Linking Problem
    By 7EVEN in forum Game Programming
    Replies: 5
    Last Post: 08-12-2005, 08:44 PM
  5. Linking error with DirectDrawCreateEx
    By jjj93421 in forum Game Programming
    Replies: 6
    Last Post: 04-06-2004, 03:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21