Undefined symbols error for barebones OO attempt

Discussion in 'C++' started by prlawrence, Feb 26, 2008.

  1. prlawrence

    prlawrence Guest

    Hello, new C++ programmer here.

    I am receiving an "Undefined symbols" error. The stubbed out code
    below produces the error.

    Perhaps I have misunderstood the correct syntax for creating my
    OcciDml object? Or do I need to pass more arguments to g++?

    Thank you for any hints,
    Phil Lawrence

    $ ls
    OcciDml.cpp OcciDml.h occi_dump.cpp

    $ g++ occi_dump.cpp
    Undefined symbols:
    "OcciDml::displayAllRows(std::basic_string<char,
    std::char_traits<char>, std::allocator<char> > const&,
    std::basic_string<char, std::char_traits<char>, std::allocator<char> >
    const&)", referenced from:
    _main in cc0Rv5BL.o
    "OcciDml::OcciDml(std::basic_string<char, std::char_traits<char>,
    std::allocator<char> > const&)", referenced from:
    _main in cc0Rv5BL.o
    "OcciDml::~OcciDml()", referenced from:
    _main in cc0Rv5BL.o
    _main in cc0Rv5BL.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    $ cat occi_dump.cpp
    #include <cstdlib>
    #include "OcciDml.h"

    using namespace std;

    int
    main ()
    {
    string ConnStr = "foo/bar@baz";
    OcciDml dbh ( ConnStr );

    string Sql = "SELECT 1 FROM DUAL";
    string Delimiter = ",";
    dbh.displayAllRows(Sql,Delimiter);

    return EXIT_SUCCESS;
    }

    $ cat OcciDml.h
    #ifndef OCCIDML_H
    #define OCCIDML_H

    #include <string>

    class OcciDml
    {
    public:
    // Constructor
    OcciDml (const std::string& rConnStr);

    // Destructor
    ~OcciDml ();

    // Display all rows
    void
    displayAllRows (const std::string& rSql
    ,const std::string& rDelimiter);

    private:
    struct _sConnection
    {
    std::string Db; // database
    std::string Passwd; // password
    std::string User; // user
    };

    // Function to parse a Connection string
    void
    _parseConnection (struct _sConnection* _Connection
    ,const std::string& rConnStr);

    }; // ----- end of class OcciDml -----

    #endif // OCCIDML_H

    $ cat OcciDml.cpp
    #include <cstdlib>
    #include "OcciDml.h"

    // Constructor
    OcciDml::OcciDml ( const std::string& rConnStr )
    {
    // stub
    }

    // Destructor
    OcciDml::~OcciDml ()
    {
    }

    // Display all rows
    void
    OcciDml::displayAllRows (const std::string& rSql
    ,const std::string& rDelimiter)
    {
    // stub
    }

    // Private function to parse a Connection string
    void
    OcciDml::_parseConnection (struct _sConnection* _Connection
    ,const std::string& rConnStr)
    {
    // stub
    }

    $ g++ -v
    Using built-in specs.
    Target: i686-apple-darwin9
    Configured with: /var/tmp/gcc/gcc-5465~16/src/configure --disable-
    checking -enable-werror --prefix=/usr --mandir=/share/man --enable-
    languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/
    $/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/
    lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --
    host=i686-apple-darwin9 --target=i686-apple-darwin9
    Thread model: posix
    gcc version 4.0.1 (Apple Inc. build 5465)
    prlawrence, Feb 26, 2008
    #1
    1. Advertising

  2. prlawrence

    red floyd Guest

    prlawrence wrote:
    > Hello, new C++ programmer here.
    >
    > I am receiving an "Undefined symbols" error. The stubbed out code
    > below produces the error.
    >
    > Perhaps I have misunderstood the correct syntax for creating my
    > OcciDml object? Or do I need to pass more arguments to g++?
    >
    > Thank you for any hints,
    > Phil Lawrence
    >
    > $ ls
    > OcciDml.cpp OcciDml.h occi_dump.cpp
    >
    > $ g++ occi_dump.cpp
    > Undefined symbols:
    > "OcciDml::displayAllRows(std::basic_string<char,
    > std::char_traits<char>, std::allocator<char> > const&,
    > std::basic_string<char, std::char_traits<char>, std::allocator<char> >
    > const&)", referenced from:
    > _main in cc0Rv5BL.o
    > "OcciDml::OcciDml(std::basic_string<char, std::char_traits<char>,
    > std::allocator<char> > const&)", referenced from:
    > _main in cc0Rv5BL.o
    > "OcciDml::~OcciDml()", referenced from:
    > _main in cc0Rv5BL.o
    > _main in cc0Rv5BL.o
    > ld: symbol(s) not found
    > collect2: ld returned 1 exit status
    >
    > [redacted]


    While this properly belongs in gnu.g++.help, I'm in a generous mood
    today. You didn't compile OcciDml.cpp with occi_dump.cpp, so of course
    the symbols defined there aren't found.
    red floyd, Feb 26, 2008
    #2
    1. Advertising

  3. prlawrence

    Christopher Guest

    On Feb 26, 11:19 am, prlawrence <> wrote:
    [snip]
    > Perhaps I have misunderstood the correct syntax for creating my
    > OcciDml object? Or do I need to pass more arguments to g++?

    [snip]
    > $ ls
    > OcciDml.cpp OcciDml.h occi_dump.cpp
    >
    > $ g++ occi_dump.cpp

    [snip]

    You did not compile Occi_Dml.cpp
    read up on using g++ or using a makefile.
    Christopher, Feb 26, 2008
    #3
  4. prlawrence

    prlawrence Guest

    Christopher wrote:
    > [snip]
    > You did not compile Occi_Dml.cpp
    > read up on using g++ or using a makefile.


    and red floyd wrote:
    > [snip]
    > You didn't compile OcciDml.cpp with occi_dump.cpp, so of
    > course the symbols defined there aren't found.


    Thanks to you both, I wrote a makefile which seems to correctly
    compile and link:

    $ make
    g++ -Wall -c occi_dump.cpp
    g++ -Wall -c OcciDml.cpp
    g++ -Wall -o occi_dump occi_dump.o OcciDml.o

    $ cat Makefile
    CC = g++
    CFLAGS = -Wall
    OBJECTS = occi_dump.o OcciDml.o

    occi_dump : $(OBJECTS)
    $(CC) $(CFLAGS) -o $@ $(OBJECTS)

    %.o : %.cpp
    $(CC) $(CFLAGS) -c $<

    clean:
    rm -rf *.o occi_dump
    prlawrence, Feb 26, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miguel Farah
    Replies:
    3
    Views:
    382
    Chris Uppal
    Aug 24, 2004
  2. Stu
    Replies:
    1
    Views:
    1,271
  3. r
    Replies:
    2
    Views:
    700
    Rob Williscroft
    Aug 2, 2003
  4. koranthala
    Replies:
    1
    Views:
    452
    koranthala
    Aug 5, 2009
  5. GMI
    Replies:
    3
    Views:
    500
    Tad McClellan
    Jun 19, 2005
Loading...

Share This Page