04-04-2008
3,
0
Join Date: Apr 2008
Last Activity: 27 March 2009, 8:21 AM EDT
Posts: 3
Thanks Given: 0
Thanked 0 Times in 0 Posts
C++ Segmentation Fault on exit of main
Hi,
I have 2 problems with a simple C++ app which i feel may be related.
1/ my app throws a Segmentaion Fault when my code exists from main(). I have stripped it to it's simplest form with no code in main and it still generates a segmentation fault.
I'm not sure what is causing this, possibly i'm missing a compiler switch in my build?
see code sample below.
2/ if i debug my test code in dbx i notice that argc is set to 0 and argv is nil. on further testing i find argc and argv are always 0 no matter what command line arguments i pass to the app (tested with a modifed veriosn that prints the output of argc and argv)
Has anyone got any ideas what could be causing these problems? I tried the same code on a solaris10 box and got the same result so i'm assuming it's something i'm doing wrong with my compile and link settings.
would appreciate any input ..
ta,
SOP
First off .. my enviornment.
OS: SunOS devsun02 5.8 Generic_108528-29 sun4u sparc SUNW,Ultra-4
64-bit sparcv9 kernel modules
I also verified i get the same reults when i try my code on a Solaris10 box
C++ compiler: CC: Sun WorkShop 6 update 1 C++ 5.2 2000/09/11
Problem: When my program exists main it throws a Segmentaion Fault.
my code is as follows
Testharness.cpp:
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "argc="<<argc<<" argv="<<argv<<std::endl;
return 0;
}
my copile and link:
CC -xarch=v9 -c -o src/TestHarness.o src/TestHarness.cpp
OS version : 5.8
Library Path : -L/opt/SUNWspro/lib/v9 -L/usr/lib/sparcv9 -L/opt/sunstudio9/SUNWspro/lib/v9 -L/usr/ucblib/sparcv9/
ld -o Testharness src/TestHarness.o -64 -L/opt/SUNWspro/lib/v9 -L/usr/lib/sparcv9 -L/opt/sunstudio9/SUNWspro/lib/v9 -L/usr/ucblib/sparcv9/ -lCrun -lCstd -lc
when I run:
>./Testharness
argc=0 argv=0
Segmentation Fault
the libraries Testharness is linking to:
ldd Testharness
libCrun.so.1 => /usr/lib/64/libCrun.so.1
libCstd.so.1 => /usr/lib/64/libCstd.so.1
libc.so.1 => /usr/lib/64/libc.so.1
libucb.so.1 => /usr/ucblib/sparcv9//libucb.so.1
libresolv.so.2 => /usr/lib/64/libresolv.so.2
libsocket.so.1 => /usr/lib/64/libsocket.so.1
libnsl.so.1 => /usr/lib/64/libnsl.so.1
libelf.so.1 => /usr/lib/64/libelf.so.1
libdl.so.1 => /usr/lib/64/libdl.so.1
libmp.so.2 => /usr/lib/64/libmp.so.2
/usr/platform/SUNW,Ultra-4/lib/sparcv9/libc_psr.so.1
I set dbx to check access and memuse and i get no further information.
output from dbx
(process id 13308)
argc=0 argv=0
signal SEGV (no mapping at the fault address) in (unknown) at 0x8
0x0000000000000008: <bad address 0x8>
any help would be most appreciated. .
Last edited by SonOfPerdition; 04-04-2008 at 08:18 AM..
Reason: cleaned up code sample