Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8449583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:44:59+00:00 2026-06-10T10:44:59+00:00

For few days I’m trying to compile one project written in C++ using Code::Blocks

  • 0

For few days I’m trying to compile one project written in C++ using Code::Blocks IDE (on Linux, Ubuntu 64-bit). Code is valid but there are some linker errors. I noticed that I get errors ‘undefined reference’ for functions which are not inline defined in classes and are in other files (class is i *.h file and definitions on these functions are in *.cpp). I tried to write my own Makefile but it didn’t help.

Makefile:

all: project

project: main.o DList.o Person.o
    g++ main.o DList.o Person.o -o project

main.o: main.cpp
    g++ -c main.cpp

DList.o: include/DList.cpp
    g++ -c include/DList.cpp

Person.o: include/Person.cpp
    g++ -c include/Person.cpp

clean:
    rm -rf *.o

I don’t know what should I do although I read some about these errors on the net.

// EDIT
I changed Object.cpp and Object.h to Person.cpp and Person.h, moved *.cpp files to main directory and changed #include paths in *.cpp files.

Errors:

obj/Debug/main.o||In function `main':|
...main.cpp|19|undefined reference to `DListIterator<Person>::go(int)'|
...main.cpp|20|undefined reference to `std::basic_ostream<char, std::char_traits<char> >& operator<< <Person>(std::basic_ostream<char, std::char_traits<char> >&, DList<Person>&)'|
...main.cpp|21|undefined reference to `DList<Person>::~DList()'|
...main.cpp|21|undefined reference to `DList<Person>::~DList()'|
obj/Debug/main.o||In function `DList<Person>::insert(Person&)':|
...include/DList.h|45|undefined reference to `DList<Person>::insert(Person&, DListIterator<Person>&)'|
||=== Build finished: 5 errors, 0 warnings ===|

It makes no difference if I build starting make in command line or using Build function in Code::Blocks.

When I copied all code from *.cpp files to *.h files, compiler returned no errors, so I think that it’s only linker problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:45:00+00:00Added an answer on June 10, 2026 at 10:45 am

    It looks like you are attempting to separately compile a template. This is not possible in general, as a template will only be instantiated when it is used, and it is never used in the DList.cpp file. Try one of two things:

    • Move the definitions of the functions in DList into the header file (this is the normal way of doing things).
    • Put some explicit instantiations of DList in to the DList.cpp file. (Example: template class DList<Person>;)

    Full example of the problem: Currently you have:

    //DList.h
    template<typename T>
    class DList {
        void insert(T& newPerson);
        //etc
    };
    
    //DList.cpp
    #include "DList.h"
    //The when this is being compiled, 
    //the compiler does not know about Person,
    //so it cannot instantiate this function.
    template<typename T>
    void DList<T>::insert(T& newPerson) {
        //implementation
    }
    //etc
    
    //main.cpp
    #include "DList.h"
    #include "Person.h"
    int main() {
        //When this is being compiled, it does not know the
        //definition of the out-of-line functions in `DList`,
        //so it cannot instantiate them.
        DList<Person> people;
        people.insert(Person("Joe"));
    }
    

    One possible fix is to remove DList.cpp and put the definitions in “DList.hpp”:

    //DList.hpp
    template<typename T>
    class DList {
        void insert(T& newPerson) {
            //implementation
        }
        ~DList();
        //etc
    };
    //the implementations can alternatively be
    //placed outside the class, but in the header:
    template<typename T>
    DList<T>::~DList() {
        //implementation
    }
    

    The other fix is to explicitly instantiate DList (in a compilation unit where the definitions are available):

    //DList.cpp
    #include "DList.h"
    #include "Person.h"
    template<typename T>
    void DList<T>::insert(T& newPerson) {
        //implementation
    }
    //Explicit instantiation:
    template class DList<Person>;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Over the past few days I have been trying to create/run a project in
Few days ago I had to reinstall all my Linux system, and I also
A few days back, I started using new OpenCV-Python interface, cv2 . My question
A few days ago I started with Ubuntu for the first time. I want
Few days back, in an interview one question was asked to me as, Are
few days ago, when I was debugging an Android project under eclipse I've found
A few days ago I posted some code like this: StreamWriter writer = new
Last few days I'm trying to start with farseer library, however i just can't
For few days now I'm trying to solve this problem. I have table group_user,
Over the past few days, I have been trying to find an answer to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.