title: cmake won't build a Linux c++11 cross-compiled program with pthreads
body: <p>In a nutshell, I can build the program with a direct g++ command line.  It builds then executes successfully on the target.</p>
  
  <p>If, however, I use the simplest cmake script I can think of, the build succeeds, but the program fails to execute on the target.  The failed output of the executable is:</p>
  
  <pre><code>terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not permitted
  Aborted
  </code></pre>
  
  <p>The g++ command line I use for a successful build and execution is:</p>
  
  <pre><code>/opt/criticallink/mityomapl138_20151114/sysroots/i686-clsdk-linux/usr/bin/arm-criticallink-linux-gnueabi/arm-criticallink-linux-gnueabi-g++ -o ThreadTest -std=c++11 -pthread main.cpp ThreadTest.cpp
  </code></pre>
  
  <p>When I run the straight g++ program on the target, I get:</p>
  
  <pre><code>Atomic Success Count: 1000 of 1000.
  
  Mutex Success Count: 1000 of 1000.
  
  Unclean Success Count: 922 of 1000.
  Unclean Failure Count: 78 of 1000.
  </code></pre>
  
  <p>The CMakeLists.txt file I use is:</p>
  
  <pre><code># cmake file for building the ThreadTest executable.  This requires c++11.
  CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
  
  # !!! Set up the compiler to use, first (i.e. before the PROJECT() call.)
  # gcc location.
  SET(CROSS_COMPILE_FULL
     "/opt/criticallink/mityomapl138_20151114/sysroots/i686-clsdk-linux/usr/bin/arm-criticallink-linux-gnueabi/arm-criticallink-linux-gnueabi-")
  # sysroot location
  SET(CROSS_COMPILE_FULL_HOST
     "/opt/criticallink/mityomapl138_20151114/sysroots/arm926ejste-criticallink-linux-gnueabi")
  SET(CMAKE_C_COMPILER "${CROSS_COMPILE_FULL}gcc")
  SET(CMAKE_CXX_COMPILER "${CROSS_COMPILE_FULL}g++")
  SET(CMAKE_FIND_ROOT_PATH "${CROSS_COMPILE_FULL_HOST}")
  SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  
  # The project will use the compiler specified above (or the default compiler for Windows.)
  PROJECT(CommonSDK)
  
  SET(MY_TEST_HOME "$ENV{TEST_HOME}")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
  
  SET(CUR_PROJECT_NAME ThreadTest)
  SET(PROJECT_HOME_DIR "${MY_TEST_HOME}/${CUR_PROJECT_NAME}")
  SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$ENV{TEST_EXEC_HOME}")
  
  FILE(GLOB CUR_PROJECT_FILES "${PROJECT_HOME_DIR}/*.cpp" "${PROJECT_HOME_DIR}/*.h")
  
  FIND_PACKAGE(Threads REQUIRED)
  ADD_EXECUTABLE(${CUR_PROJECT_NAME} ${CUR_PROJECT_FILES})
  TARGET_LINK_LIBRARIES(${CUR_PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
  </code></pre>
  
  <p>I invoke cmake with:</p>
  
  <pre><code>mkdir build
  cd build
  cmake ..
  </code></pre>
  
  <p>And the cmake output is:</p>
  
  <pre><code>-- The C compiler identification is GNU 4.8.3
  -- The CXX compiler identification is GNU 4.8.3
  -- Check for working C compiler: /opt/criticallink/mityomapl138_20151114/sysroots/i686-clsdk-linux/usr/bin/arm-criticallink-linux-gnueabi/arm-criticallink-linux-gnueabi-gcc
  -- Check for working C compiler: /opt/criticallink/mityomapl138_20151114/sysroots/i686-clsdk-linux/usr/bin/arm-criticallink-linux-gnueabi/arm-criticallink-linux-gnueabi-gcc -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working CXX compiler: /opt/criticallink/mityomapl138_20151114/sysroots/i686-clsdk-linux/usr/bin/arm-criticallink-linux-gnueabi/arm-criticallink-linux-gnueabi-g++
  -- Check for working CXX compiler: /opt/criticallink/mityomapl138_20151114/sysroots/i686-clsdk-linux/usr/bin/arm-criticallink-linux-gnueabi/arm-criticallink-linux-gnueabi-g++ -- works
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Looking for include file pthread.h
  -- Looking for include file pthread.h - found
  -- Looking for pthread_create
  -- Looking for pthread_create - not found
  -- Looking for pthread_create in pthreads
  -- Looking for pthread_create in pthreads - not found
  -- Looking for pthread_create in pthread
  -- Looking for pthread_create in pthread - found
  -- Found Threads: TRUE  
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build
  </code></pre>
  
  <p>Here is the VERBOSE output from the make:</p>
  
  <pre><code>make VERBOSE=1
  
  /usr/bin/cmake -H/home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest -B/home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build --check-build-system CMakeFiles/Makefile.cmake 0
  /usr/bin/cmake -E cmake_progress_start /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build/CMakeFiles /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build/CMakeFiles/progress.marks
  make -f CMakeFiles/Makefile2 all
  make[1]: Entering directory `/home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build'
  make -f CMakeFiles/ThreadTest.dir/build.make CMakeFiles/ThreadTest.dir/depend
  make[2]: Entering directory `/home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build'
  cd /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build &amp;&amp; /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build/CMakeFiles/ThreadTest.dir/DependInfo.cmake --color=
  Dependee "/home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build/CMakeFiles/ThreadTest.dir/DependInfo.cmake" is newer than depender "/home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build/CMakeFiles/ThreadTest.dir/depend.internal".
  Dependee "/home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build/CMakeFiles/ThreadTest.dir/depend.internal".
  Scanning dependencies of target ThreadTest
  make[2]: Leaving directory `/home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build'
  make -f CMakeFiles/ThreadTest.dir/build.make CMakeFiles/ThreadTest.dir/build
  make[2]: Entering directory `/home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build'
  /usr/bin/cmake -E cmake_progress_report /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build/CMakeFiles 1
  [ 50%] Building CXX object CMakeFiles/ThreadTest.dir/main.cpp.o
  /opt/criticallink/mityomapl138_20151114/sysroots/i686-clsdk-linux/usr/bin/arm-criticallink-linux-gnueabi/arm-criticallink-linux-gnueabi-g++    -O2 -pipe -g -feliminate-unused-debug-types  -std=c++11 -pthread   -o CMakeFiles/ThreadTest.dir/main.cpp.o -c /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/main.cpp
  /usr/bin/cmake -E cmake_progress_report /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build/CMakeFiles 2
  [100%] Building CXX object CMakeFiles/ThreadTest.dir/ThreadTest.cpp.o
  /opt/criticallink/mityomapl138_20151114/sysroots/i686-clsdk-linux/usr/bin/arm-criticallink-linux-gnueabi/arm-criticallink-linux-gnueabi-g++    -O2 -pipe -g -feliminate-unused-debug-types  -std=c++11 -pthread   -o CMakeFiles/ThreadTest.dir/ThreadTest.cpp.o -c /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/ThreadTest.cpp
  Linking CXX executable /home/mitydsp/Code/CommonSDK/OutputTest/DbricHost/ThreadTest
  /usr/bin/cmake -E cmake_link_script CMakeFiles/ThreadTest.dir/link.txt --verbose=1
  /opt/criticallink/mityomapl138_20151114/sysroots/i686-clsdk-linux/usr/bin/arm-criticallink-linux-gnueabi/arm-criticallink-linux-gnueabi-g++    -O2 -pipe -g -feliminate-unused-debug-types  -std=c++11 -pthread   -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed CMakeFiles/ThreadTest.dir/main.cpp.o CMakeFiles/ThreadTest.dir/ThreadTest.cpp.o  -o /home/mitydsp/Code/CommonSDK/OutputTest/DbricHost/ThreadTest -rdynamic -lpthread 
  make[2]: Leaving directory `/home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build'
  /usr/bin/cmake -E cmake_progress_report /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build/CMakeFiles  1 2
  [100%] Built target ThreadTest
  make[1]: Leaving directory `/home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build'
  /usr/bin/cmake -E cmake_progress_start /home/mitydsp/Code/CommonSDK/source/Tests/ThreadTest/build/CMakeFiles 0
  </code></pre>
  
  <p>I've exhaustively looked in StackOverflow, Google, etc. -- and the suggestions I've come across are incorporated in the CMakeLists.txt, above.  But I still can't get the cmake executable to run properly on the target.</p>
  
  <p>Any help would be appreciated!</p>