Undefined reference to
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Undefined reference to

  1. #1
    Join Date
    Apr 2013
    Posts
    16

    Question Undefined reference to

    When building the program I get the following error: undefined reference to `Atom:: DoBCC(float, int, int, int)'. What am I doing wrong? Thanks in advance.

    main.cpp
    Code:
    #include <iostream>
    #include "Atom.h"
     
    using std::cout;
    using std::cin;
    using std::endl;
     
    int main ()
    {
        int latticeType;
        int dimX, dimY, dimZ; // number of translated lattices along each axis
        float d; // lattice parameter
        Atom myAtom; // object of class Atom
     
        cout << "Please choose the crystal lattice." << endl;
        cout << "Type 1 for BCC, 2 for FCC, and 3 for HCP:" << endl;
        cin >> latticeType; // read lattice type
        cout << "Please enter lattice parameter:" << endl;
        cin >> d;
        cout << "Please enter the number of translated lattices along X axis:" << endl;
        cin >> dimX;
        cout << "Please enter the number of translated lattices along Y axis:" << endl;
        cin >> dimY;
        cout << "Please enter the number of translated lattices along Z axis:" << endl;
        cin >> dimZ;
     
        if (latticeType==1) myAtom.DoBCC ( d, dimX, dimY, dimZ ); // if 1, create BCC lattice
        else
        {
            cout << "Invalid value" << endl;
            return 0;
        }
     
        return 0;
    }
    Atom.h
    Code:
    class Atom
    {
        public:
            void DoBCC ( float, int, int, int );
        private:
            float x, y, z;
    };

    Atom.cpp
    Code:
    #include <iostream>
    #include "Atom.h"
     
    using std::cout;
    using std::cin;
    using std::endl;
     
    typedef class Atom AtomType;
     
    void Atom::DoBCC ( float d, int dimX, int dimY, int dimZ ) // beginning of the DoBCC function
    {
        float a = d; // lattice parameter
        int Lx = dimX;
        int Ly = dimY;
        int Lz = dimZ; // number of translated lattices along each axis
     
       // from now on I work with a, Lx, Ly, Lz variables
     
    } // end of the DoBCC function

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,107

    Re: Undefined reference to

    Builds cleanly for me.

  3. #3
    Join Date
    Apr 2013
    Posts
    16

    Re: Undefined reference to

    Online compiler also builds. But Code::Blocks 12.11 keeps yelling:
    Build messages:
    Code:
    C:\Users\oniltech\Dropbox\CMS\Molecular Dynamics\Assignment 1\revision 1\BCC_FCC_HCP.o:BCC_FCC_HCP.cpp|| undefined reference to `Atom:: DoBCC(float, int, int, int)'|
    ||=== Build finished: 1 errors, 0 warnings (0 minutes, 7 seconds) ===|
    Build log:
    Code:
    mingw32-g++.exe -march=athlon64 -Wall    -c "C:\Users\oniltech\Dropbox\CMS\Molecular Dynamics\Assignment 1\revision 1\BCC_FCC_HCP.cpp" -o "C:\Users\oniltech\Dropbox\CMS\Molecular Dynamics\Assignment 1\revision 1\BCC_FCC_HCP.o"
    mingw32-g++.exe  -o "C:\Users\oniltech\Dropbox\CMS\Molecular Dynamics\Assignment 1\revision 1\BCC_FCC_HCP.exe" "C:\Users\oniltech\Dropbox\CMS\Molecular Dynamics\Assignment 1\revision 1\BCC_FCC_HCP.o"   
    C:\Users\oniltech\Dropbox\CMS\Molecular Dynamics\Assignment 1\revision 1\BCC_FCC_HCP.o:BCC_FCC_HCP.cpp:(.text+0x1b2): undefined reference to `Atom::DoBCC(float, int, int, int)'
    collect2.exe: error: ld returned 1 exit status
    Process terminated with status 1 (0 minutes, 7 seconds)
    1 errors, 0 warnings (0 minutes, 7 seconds)
    What might be done to fix this?
    Last edited by ted_kingdom; April 18th, 2013 at 01:47 AM.

  4. #4
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,013

    Re: Undefined reference to

    Did you include Atom.cpp in your project/makefile?
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  5. #5
    Join Date
    Apr 2013
    Posts
    16

    Re: Undefined reference to

    Quote Originally Posted by D_Drmmr View Post
    Did you include Atom.cpp in your project/makefile?
    No, thank you. Initially I did not create a project at all. Now it works fine. Thanks a million!

    Please put tags around your code to preserve indentation and make it more readable.
    Done.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center