enabling pthreads on AIX fails
I minimized my problem to the simplest reproducible project: https://github.com/apollo13/cmake_aix_bug
The issue is as follows:
- GCC on AIX (at least in my variant), comes with multiple stdlibs: http://www.perzl.org/aix/index.php%3Fn%3DMain.GCCBinariesVersionNeutral
- Enabling -pthread via CMake results in a executable that links against the wrong stdlib (namely the one without pthread).
- exporting LIBPATH to the pthread variant makes the program work again.
See the following examples:
Compile with pthread:
/usr/bin/c++ -v -Wl,-bnoipath -Wl,-brtl CMakeFiles/Test.dir/main.cpp.o CMakeFiles/Test.dir/easylogging++.cpp.o -o Test -pthread
Using built-in specs.
COLLECT_GCC=/usr/bin/c++
COLLECT_LTO_WRAPPER=/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/lto-wrapper
Target: powerpc-ibm-aix6.1.0.0
Configured with: ../gcc-4.8.5/configure --with-as=/usr/bin/as --with-ld=/usr/bin/ld --enable-languages=c,c++,fortran --prefix=/opt/freeware --mandir=/opt/freeware/man --infodir=/opt/freeware/info --enable-version-specific-runtime-libs --disable-nls --enable-decimal-float=dpd --with-cloog=no --with-ppl=no --disable-libstdcxx-pch --enable-__cxa_atexit --host=powerpc-ibm-aix6.1.0.0
Thread model: aix
gcc version 4.8.5 (GCC)
COMPILER_PATH=/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/:/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/:/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/
LIBRARY_PATH=/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/pthread/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/../../../pthread/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'Test' '-pthread' '-shared-libgcc'
/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/collect2 -bpT:0x10000000 -bpD:0x20000000 -btextro -bnodelcsect -o Test /lib/crt0_r.o /opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/pthread/crtcxa.o -L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/pthread -L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/../../../pthread -L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5 -L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/../../.. -bnoipath -brtl CMakeFiles/Test.dir/main.cpp.o CMakeFiles/Test.dir/easylogging++.cpp.o -lstdc++ -lm -lgcc_s /opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/pthread/libgcc.a -lpthreads -lc -lgcc_s /opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/pthread/libgcc.a
Compile without pthread:
a700tj05*therhall*>/usr/bin/c++ -v -Wl,-bnoipath -Wl,-brtl CMakeFiles/Test.dir/main.cpp.o CMakeFiles/Test.dir/easylogging++.cpp.o -o Test
Using built-in specs.
COLLECT_GCC=/usr/bin/c++
COLLECT_LTO_WRAPPER=/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/lto-wrapper
Target: powerpc-ibm-aix6.1.0.0
Configured with: ../gcc-4.8.5/configure --with-as=/usr/bin/as --with-ld=/usr/bin/ld --enable-languages=c,c++,fortran --prefix=/opt/freeware --mandir=/opt/freeware/man --infodir=/opt/freeware/info --enable-version-specific-runtime-libs --disable-nls --enable-decimal-float=dpd --with-cloog=no --with-ppl=no --disable-libstdcxx-pch --enable-__cxa_atexit --host=powerpc-ibm-aix6.1.0.0
Thread model: aix
gcc version 4.8.5 (GCC)
COMPILER_PATH=/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/:/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/:/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/
LIBRARY_PATH=/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'Test' '-shared-libgcc'
/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/collect2 -bpT:0x10000000 -bpD:0x20000000 -btextro -bnodelcsect -o Test /lib/crt0.o /opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/crtcxa.o -L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5 -L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/../../.. -bnoipath -brtl CMakeFiles/Test.dir/main.cpp.o CMakeFiles/Test.dir/easylogging++.cpp.o -lstdc++ -lm -lgcc_s /opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/libgcc.a -lc -lgcc_s /opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/libgcc.a
As you can see, LIBRARY_PATH is different depending on whether pthread is used or not. If I am using cmake to compile the project I get:
c++ -v -Wl,-bnoipath -Wl,-brtl CMakeFiles/Test.dir/main.cpp.o CMakeFiles/Test.dir/easylogging++.cpp.o -o Test -Wl,-blibpath:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5:/opt/freeware/lib:/usr/lib:/lib -pthread
Using built-in specs.
COLLECT_GCC=c++
COLLECT_LTO_WRAPPER=/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/lto-wrapper
Target: powerpc-ibm-aix6.1.0.0
Configured with: ../gcc-4.8.5/configure --with-as=/usr/bin/as --with-ld=/usr/bin/ld --enable-languages=c,c++,fortran --prefix=/opt/freeware --mandir=/opt/freeware/man --infodir=/opt/freeware/info --enable-version-specific-runtime-libs --disable-nls --enable-decimal-float=dpd --with-cloog=no --with-ppl=no --disable-libstdcxx-pch --enable-__cxa_atexit --host=powerpc-ibm-aix6.1.0.0
Thread model: aix
gcc version 4.8.5 (GCC)
COMPILER_PATH=/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/:/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/:/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/
LIBRARY_PATH=/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/pthread/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/../../../pthread/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'Test' '-pthread' '-shared-libgcc'
/opt/freeware/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/collect2 -bpT:0x10000000 -bpD:0x20000000 -btextro -bnodelcsect -o Test /lib/crt0_r.o /opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/pthread/crtcxa.o -L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/pthread -L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/../../../pthread -L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5 -L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/../../.. -bnoipath -brtl CMakeFiles/Test.dir/main.cpp.o CMakeFiles/Test.dir/easylogging++.cpp.o -blibpath:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5:/opt/freeware/lib:/usr/lib:/lib -lstdc++ -lm -lgcc_s /opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/pthread/libgcc.a -lpthreads -lc -lgcc_s /opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5/pthread/libgcc.a
This means by adding -Wl,-blibpath:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5:/opt/freeware/lib:/usr/lib:/lib (which is done by CMake) my program has the wrong stdlib.
The only solution I could come up with is:
set(CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "")
set(CMAKE_CXX_USE_IMPLICIT_LINK_DIRECTORIES_IN_RUNTIME_PATH 0)
Is there any way to specify pthread in a way so that it affects compiler identifactions?
/cc @chuck.atkins - Do you have any ideas on that?