I am trying to write a simple C++ program on an AIX Box. The program is given below:
# include <iostream>
# include <fstream>
using namespace std ;
int main()
{
ofstream of ;
of.open("license.txt") ;
of<<"hello"<<endl ;
of.close() ;
}
My LDFLAGS has is set as following:
-maix64 -L/disk3/TOOLS/GCCTools/gcc-4.5.1/lib/ppc64 \
-L/disk3/TOOLS/GCCTools/gcc-4.5.1/lib/gcc/powerpc-ibm-aix6.1.0.0/4.5.1/ppc64 \
-L/disk3/TOOLS/GCCTools/gcc-4.5.1/lib/gcc/powerpc-ibm-aix6.1.0.0/4.5.1 \
-L/disk3/TOOLS/OPENSSL/lib
CFLAGS is:
-O2 -maix64 -I/disk3/TOOLS/OPENSSL/include -D_ALL_SOURCE -D_XOPEN_SOURCE \
-D_XOPEN_SOURCE_EXTENDED -DSS_64BIT_SERVER -D_POSIX_SOURCE -D__64BIT__ \
-I/disk3/TOOLS/OPENSSL/include -I/usr/include \
-I/disk3/TOOLS/GCCTools/gcc-4.5.1/lib/gcc/powerpc-ibm-aix6.1.0.0/4.5.1/include
The program compiles fine. But when I try to run the same, the program comes out with a segmentation fault. I ran the same with gdb and found the following issue when I use ofstream:
Program received signal SIGSEGV, Segmentation fault.
0x09000000036107c4 in std::locale::operator=(std::locale const&) (this=
findvar.c:706: internal-error: value_from_register: Value not stored anywhere!
Any idea on why this is happening? Any help is appreciated :)
Note: fstream in itself works...
I meet the same error. The key points to repro the error are: 1 use std::stream(such as std::ofstream) in share libary; 2 use pthread function (such as pthread_self) in share library; 3 use "-O2" to optimize code. Then it shows "Segmentation fault (core dumped)".
AIX provides 2 versions(64bit) of libstdc++.a. (see http://www.perzl.org/aix/index.php?n=Main.GCCBinariesVersionNeutral)
64-bit compilation, non-thread-safe (<prefix>/ppc64
)
64-bit compilation, thread-safe (<prefix>/pthread/ppc64)
My solution is:
change LIBPATH to use "<prefix>/pthread/ppc64"
version.
such as set LIBPATH as "/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.6.1/pthread/ppc64/"
It works well in my machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With