Undefined symbols error for barebones OO attempt


P

prlawrence

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/[email protected]";
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)
 
Ad

Advertisements

R

red floyd

prlawrence said:
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.
 
C

Christopher

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.
 
Ad

Advertisements

P

prlawrence

Christopher said:
[snip]
You did not compile Occi_Dml.cpp
read up on using g++ or using a makefile.
[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 [email protected] $(OBJECTS)

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

clean:
rm -rf *.o occi_dump
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top