LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Linking problem with string class (https://www.linuxquestions.org/questions/programming-9/linking-problem-with-string-class-311021/)

live_dont_exist 04-08-2005 06:00 AM

Linking problem with string class
 
Hi Guys,

I am trying to write some code using the string class in C++ . Heres a segment of the code :-
Code:

#include <stdio.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string>

using std::string;
class Checksum
{
 private:
  struct tcphdr *tcp;
  uint16_t temp_short;
  uint32_t temp_long;
  string hex_final;
 public:
  void init_header();
  void decimaltohex();
};

Checksum check;

However when I compile it using gcc I get these errors:-
Code:

[root@localhost project]# gcc -o checksum checksum.cpp
/tmp/ccBQQu6W.o(.gnu.linkonce.t._ZN8ChecksumC1Ev+0x11): In function `Checksum::Checksum[in-charge]()':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string[in-charge]()'
/tmp/ccBQQu6W.o(.gnu.linkonce.t._ZN8ChecksumD1Ev+0x11): In function `Checksum::~Checksum [in-charge]()':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string [in-charge]()'
/tmp/ccBQQu6W.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

I'm guessing these are linking errors ; but havent a clue how to get around them.Any help is appreciated.
Thnx
Arvind

sirclif 04-08-2005 09:03 AM

you need to use g++ to compile c++ code.
g++ will then probably complain about depreciated header files, so you need to use
#include <cstdio>
#include <cstdlib>
instead of stdio.h and cstdlib.h

live_dont_exist 04-08-2005 02:33 PM

thnx a lot...will try this...but these errors started to come up only after I started to use the String class...

sirclif 04-08-2005 03:26 PM

yea, the string class is a c++ header file. the other headers are c header files. I'm not sure, but i don't think the c compiler is aware of any of the c++ header files. anybody else know the details on what directories are in the default path that the compiler looks for header files?

live_dont_exist 04-09-2005 08:07 AM

hey thnx 4 replying ...I got it sorted out ...if you use :-
Code:

using namespace std;
it take away all bad bad errors:)...thnx 4 helpin..
Arvind


All times are GMT -5. The time now is 01:09 PM.