PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Undefined symbols error for barebones OO attempt
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Undefined symbols error for barebones OO attempt

Réponse
 
LinkBack Outils de la discussion
Vieux 26/02/2008, 17h19   #1
prlawrence
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Undefined symbols error for barebones OO attempt

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<cha r,
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)

  Réponse avec citation
Vieux 26/02/2008, 17h55   #2
red floyd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Undefined symbols error for barebones OO attempt

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<cha r,
> 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++., 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.
  Réponse avec citation
Vieux 26/02/2008, 17h55   #3
Christopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Undefined symbols error for barebones OO attempt

On Feb 26, 11:19 am, prlawrence <prlawre...@gmail.com> 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.

  Réponse avec citation
Vieux 26/02/2008, 19h59   #4
prlawrence
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Undefined symbols error for barebones OO attempt


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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h43.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11904 seconds with 12 queries