Suddenly probs with C++...

Suddenly probs with C++...

Post by Siegfried Po » Fri, 04 Jul 1997 04:00:00



Hi all,

I used to write stuff in C++ on Linux, that did not cause any problems.
But suddenly I cannot do any file I/O with the C++ stream classes, I
think I did not change anything, what causes the trouble.

This seems to happen with every method, that accesses an opened
file like ifstream::seekp(), ifstream::getline(), ifstream::getc()
and so on. The following prog is just an example.

Does anybody know, what is wrong?

Cu Siggi

____________ the prog _____________________________________
#include<iostream.h>
#include<fstream.h>

void main(int argc, char **argv)
{
   if(argv[1]) {  
      ifstream eingabeDatei(argv[1]);
      if(!eingabeDatei)  {
            cerr << "File pointer is  NULL!" << endl;
            exit(1);
      }
      char testString[128];
        // This line causes the seg fault
      eingabeDatei.getline(testString, 127, '\n');
                 //^^^^^^^
      cout << testString << endl;

   } else {
      cerr << "No filename" << endl;
   }

Quote:} // end of main(...)

___________________________________________________________

The file really exists, what is strange is, that the ifstream
constructor returns some value, but as soon as I do any
operation on that object I get a seg fault ?! 8-(

______ the gdb output _____________________________________
(gdb) run test.txt
Starting program: /home/spohl/C/test1 test.txt
test.txt

Program received signal SIGSEGV, Segmentation fault.
0x400a32e0 in _IO_getline (fp=???, buf=???, n=???, delim=???,
    extract_delim=???)
Current language:  auto; currently c
__________________________________________________________

__________ the s trace output (I left out the beginning)____
open("test.txt", O_RDONLY)              = 3
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(4, 196), ...}) = 0
mmap(0, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40008000
ioctl(1, TCGETS, {B9600 opost isig icanon echo ...}) = 0
write(1, "test.txt\n", 9test.txt
)               = 9
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++
___________________________________________________________

_________ my configuration _____________________________

Linux Kernel           2.0.29
Gnu C++                2.7.2.1
Binutils               2.8.1.0.1
C Library              5.4.33
ld.so                  2.0.4
C++ Library            27.2.1

Pentium 200, 32 Megs (the usual stuff)
_____________________________________________________
--
=====================================================================
Siegfried Pohl                                                      
http://www.in-berlin.de/User/czbbs                                  

 
 
 

Suddenly probs with C++...

Post by Chris Underhil » Sun, 06 Jul 1997 04:00:00


-----BEGIN PGP SIGNED MESSAGE-----

<Snip>

Your program works fine on my machine.

: _________ my configuration _____________________________

: Linux Kernel         2.0.29
: Gnu C++                2.7.2.1
: Binutils               2.8.1.0.1
: C Library              5.4.33
: ld.so                  2.0.4

Duh - why are you using ld.so.2.0.4 ? That is supposed to be used
with stuff compiled with glibc-2 (libc.so.6). The latest version
that operates with libc-5 stuff is version 1.9.2. Try downgrading to
that release (or enjoy the delights that come with upgrading to
libc-6 :-)

Cheers,

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2i

iQCVAwUBM74+bGZVEN0KDxVBAQGCCgP/f50ESZf8tt+XYvbDjHgD19cJBQ4uCfk8
6N5Yl5L2RUj5v0q7KgfKsV1vjiZx7iUDIem+opx3fl5yqreg8Woc+vwgxNMo56zd
1WIM3h4BOUAkpBT//oG89BfnewL9JPcEDg2FxH72EQUkjcgtOcCL4G+Hlhv+dDRt
h6eGBZuF9BE=
=MsYD
-----END PGP SIGNATURE-----

 
 
 

Suddenly probs with C++...

Post by Chris Cradoc » Tue, 08 Jul 1997 04:00:00



> Hi all,

> I used to write stuff in C++ on Linux, that did not cause any problems.
> But suddenly I cannot do any file I/O with the C++ stream classes, I
> think I did not change anything, what causes the trouble.

Did you upgrade your c++ libraries along with glib2? Try linking against
libc5 and see if this works.

Chris Cradock

 
 
 

1. sun specific probs while writing C++ extensions for perl (XS)

I am trying to port some perl extensions (XS) written in C++ to SunOS.
These extensions compile and run w/o problems in DEC UNIX, although
un Sun I get unresolved symbols while loading the library ( perl does a
simple dlopen(2) on the lib):

        prompt$ perl test.pl
        ld.so: Undefined symbol: __ex_table_count

this error occurs independend if us "ld ... -lC .. " or "CC" for linking.
(I have to link against the C++ lib otherwise I get unresolved: _cerr).
The strange thing is that __ex_table_count is defined inside the C++ lib
so I don't understand why it gets not resolved:

        prompt$ nm /usr/local/lang/lib/libC.so.5.0 | grep __ex_table_count
        0001a89c d __ex_table_count

I tried various things: changing the order of the libraries inside the "ld"
statement, adding -lc ( => "ld.so: conflicting usage of dlopen'ed dependents"),
using the options "-d", "-dp" and "-dc" - nothing helped.

I guess that the main problem is that perl is build using "cc" (e.g. plain C)
and in this way does not know about C++ specific features. I't cant be an
general problem with dlopen in combination with C++, because I use dlopen
in normal C++ application w/o problems to load other C++ written libraries.
And as far as I can see there is only one dlopen (e.g. no special implemen-
tation for C++ inside the libC).

Any ideas before I start trying to link perl directly with the C++ lib (maybe
this helps) ?

--

2. IOgear KVM anygood??

3. Is my fetchmail prob. a sendmail prob.?

4. which flavor?

5. Sound card probs, modem probs. Help im cut off!!!!

6. Deeper Secrets?

7. XDM/X no '@' sign, sendmail daemon probs, v1.1.45 probs

8. Gnome Updating Glitches

9. Display Prob (is it a font prob or not?)

10. minicom probs, & repititive config probs

11. mouse prob, MG-mboadr HW prob

12. Solaris 2.6 Fixes year 2K probs; does Linux suffer the same probs

13. For the AIX C++ gurus: creating a C interface to a C++ shard lib