LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-08-2005, 06:00 AM   #1
live_dont_exist
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat 9.0,FC3,FC5,FC10
Posts: 257

Rep: Reputation: 30
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
 
Old 04-08-2005, 09:03 AM   #2
sirclif
Member
 
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192

Rep: Reputation: 30
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
 
Old 04-08-2005, 02:33 PM   #3
live_dont_exist
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat 9.0,FC3,FC5,FC10
Posts: 257

Original Poster
Rep: Reputation: 30
thnx a lot...will try this...but these errors started to come up only after I started to use the String class...
 
Old 04-08-2005, 03:26 PM   #4
sirclif
Member
 
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192

Rep: Reputation: 30
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?
 
Old 04-09-2005, 08:07 AM   #5
live_dont_exist
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat 9.0,FC3,FC5,FC10
Posts: 257

Original Poster
Rep: Reputation: 30
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Questions about custom C++ string class. lowpro2k3 Programming 1 08-23-2005 12:06 PM
is there a c++ binary safe string class? Thinking Programming 3 08-11-2005 06:18 PM
(linking?) problem compiling very simple array class btb Programming 3 08-02-2005 03:16 PM
std string class and printf The_Nerd Programming 3 06-28-2004 10:46 PM
BlackBox.class & VerifierBug.class virus ??? dalek Linux - Security 4 02-29-2004 08:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration