PDA

View Full Version : C++ Segmentation Fault



samssc
05-31-2010, 03:04 PM
I'm planning to use C++ for some CGI functions. So just to make sure the basics worked after installing GCC, I wrote a simple Hello World, just a one-liner to write to cout. Got a seg fault!

I backed down all the way to simple C, stdio.h, and printf() -- works fine.

The seg fault happens if I take that very simple program and add one line:
#include <iostream>

Weird.

Anyone else out there using C++? Any hints on how to include iostream header and make it work?

Thanks,

Sam

samssc
05-31-2010, 10:01 PM
Problem solved. I had to use static linking, as in:

g++ -static -o simple1 simple1.cpp

Now, if anyone knows how to get shared libraries to work, that's my next question! I did try setting LD_LIBRARY_PATH=/usr/lib but that didn't help.

wildjokerdesign
06-01-2010, 06:57 AM
Would adding /usr/lib to your /etc/ld.so.conf file do anything. I really have very little knowledge in this area but I do know when I install something in a non traditional location, that I add the path there to get it to link up correctly.

I can't follow everything on this page but it sounds like you have more experience in this area so it might give you more insight in what you need for your particular project. http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

samssc
06-01-2010, 07:49 PM
Thanks. Just checked /etc/ld.so.conf, and /usr/lib is already there, along with several other standard lib directories.

So, linking shared lib is still a mystery.... Guess I'll get by with static link for now.