Thread: Compilation problem

  1. #1
    Registered User
    Join Date
    Jul 2002

    Compilation problem

    I'm having this problem weird compilation problem:
    I try to compile the below sources, but it won't work. It says I haven't implemented the functions declared in linkedlist.h, but they're all in It's like it doesn't read linkedlist.o at all.

    Here's the source:

    --- Code for linkedlist.h ---

    #ifndef LINKEDLIST_H
    #define LINKEDLIST_H

    template <class Data>
    class Node {
    Node(Data, Node *);
    Node *next;
    Data data;

    template <class Data>
    class LinkedList {
    void insert(Data);
    Data get(int);
    void erase(int);
    Node <Data> *head;

    #endif /* ! LINKEDLIST_H */

    --- Code for ---

    #include "linkedlist.h"

    template <class Data>
    Node<Data>::Node(Data ndata, Node *nnext) : next(nnext) {

    data = ndata;


    template <class Data>
    Node<Data>::~Node(void) {


    template <class Data>
    LinkedList<Data>::LinkedList(void) {

    head = 0;


    template <class Data>
    LinkedList<Data>::~LinkedList(void) {


    template <class Data>
    void LinkedList<Data>::insert(Data data) {

    head = new Node<Data>(data, head);


    template <class Data>
    Data LinkedList<Data>::get(int i) {

    Data data;
    Node <Data> node;

    for (int a = 0; a < i; a++) {
    if (head == NULL)
    return NULL;
    head = head->next;

    data = head->data;

    return data;


    template <class Data>
    void LinkedList<Data>::erase(int i) {

    bool b = 0;
    Node <Data> node;

    for (int a = 0; head != NULL; a++) {
    if (a == i)
    b = 1;
    head = head->next;
    if (b)
    head = head->next;


    --- Code for ---

    #include "linkedlist.h"

    int main(void) {

    LinkedList <int> hans;


    return 0;


    --- Code for Makefile ---

    CFLAGS =

    DEST = .


    HDRS = linkedlist.h

    INSTALL = cp

    LD = $(CC)


    LIBS =

    MAKEFILE = Makefile

    OBJS = linkedlist.o \

    PRINT = pr

    PROGRAM = a.out

    SHELL = /bin/sh

    SRCS = \


    all: $(PROGRAM)

    $(PROGRAM): $(OBJS) $(LIBS)
    @echo "Linking $(PROGRAM) ..."
    @$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o $(PROGRAM)
    @echo "done"

    clean:; @rm -f $(OBJS) core

    clobber:; @rm -f $(OBJS) $(PROGRAM) core tags

    depend:; @mkmf -f $(MAKEFILE)

    echo:; @echo $(HDRS) $(SRCS)

    index:; @ctags -wx $(HDRS) $(SRCS)

    install: $(PROGRAM)
    @echo Installing $(PROGRAM) in $(DEST)
    @-strip $(PROGRAM)
    @if [ $(DEST) != . ]; then \
    (rm -f $(DEST)/$(PROGRAM); $(INSTALL) $(PROGRAM) $(DEST)); fi

    print:; @$(PRINT) $(HDRS) $(SRCS)

    tags: $(HDRS) $(SRCS); @ctags $(HDRS) $(SRCS)
    linkedlist.o: linkedlist.h
    main.o: linkedlist.h
    I like traffic lights. I like traffic lights. I like traffic lights, but only when they're green.

  2. #2
    Registered User
    Join Date
    Aug 2002
    Hermosa Beach, CA
    I have found that under Visual Studio you must #include the .cpp file, or you must make all the member functions inline in the header (when using templates). Since this is a linux board, I imagine you are using gcc. But you might want to try these things out anyway.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Seems like a silly question to ask, but have you actualy compiled your soundcode into the linkedlist.o and main.o files?
    It apears as though the Makefile does not do this for you, instead it just does the linking of the objects. ( I am not an expert on makefiles, so do not take my word for this. )

    what I would do to get this program compiled is
    g++ -o ProgramName

    This will be a lot easier than fiddling around with a makefile.


  4. #4
    Registered User
    Join Date
    Jul 2002
    Well, there's more to the project than what I posted here, but the rest of the code is irrelevant. So that's why I use a Makefile.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  2. Compilation problem
    By OSDever in forum C++ Programming
    Replies: 10
    Last Post: 09-08-2005, 06:42 AM
  3. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  4. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM