The following code (a general case) generates a segmentation fault when compiled with the -m32 and -fopenmp switch in gcc 4.2.1. With the -m32 switch removed, the program executes correctly. #include <iostream> int main() { int x; #pragma omp parallel for for (x = 0; x < 100; x++) { std::cout << x << std::endl; } return 0; } compile command line: /usr/local/gcc-4.2.1/bin/g++ --static -fopenmp -m32 -o openMPTestProgram openMPTest.cpp System: SUSE 10 x64 linux distribution, (Dual-core Intel(R) Pentium(R) D CPU 2.80GHz system), 4GB ram GCC configuration option: ../gcc-4.2.1/configure --prefix=/usr/local/gcc-4.2.1
to clarify; the resultant executable of the test case above generates the segmentation fault, not the compiler during compilation.
-static is not really supported for glibc and pthreads/openmp.
What happens if you don't use -static?
(In reply to comment #3) > What happens if you don't use -static? if static is not used (and the LD_LIBRARY_PATH points to the correct location ;) the program seems to execute correctly.
(In reply to comment #4) > (In reply to comment #3) > > What happens if you don't use -static? > if static is not used (and the LD_LIBRARY_PATH points to the correct location > ;) > the program seems to execute correctly. I didn't think that -static was causing the problem since the application seems to execute correctly with the -m32 option removed, and with the -static remaining.
(In reply to comment #5) > I didn't think that -static was causing the problem since the application seems > to execute correctly with the -m32 option removed, and with the -static > remaining. glibc is slightly different between the 32bit version and the 64bit version.
Using -static for threaded programs is highly discouraged in glibc, for many reasons. If you want to do it anyway for whatever weird reason, you usually need to use -Wl,--whole-archive -lnptl -Wl,--no-whole-archive.