|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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) |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|