Cmake Find_library

I am trying to achieve the equivalent of following command by CMake.

Cmake find_library required

Cmake Find_library Example

In Module mode, CMake searches for a file called Find.cmake. The file is first searched in the CMAKEMODULEPATH, then among the Find Modules provided by the CMake installation. If the file is found, it is read and processed by CMake. It is responsible for finding the package, checking the version, and producing any needed messages. This command is used to find a library. A cache entry named by is created to store the result of this command. If the library is found the result is stored in the variable and the search will not be repeated unless the variable is cleared. If nothing is found, the result will be -NOTFOUND. In Module mode, CMake searches for a file called Find.cmake. The file is first searched in the CMAKEMODULEPATH, then among the Find Modules provided by the CMake installation. If the file is found, it is read and processed by CMake. It is responsible for finding the package, checking the version, and producing any needed messages.

gcc -static -O0 -g main.c /usr/lib/x86_64-linux-gnu/libpthread.a

My cmake script successfully built executable file, but gave segmentation fault at run.
Can anybody point me what should I fix ? The command line above built and ran normally, and if I linked libpthtread.so by my cmake script it also terminated without issue.

Cmake Find_library Debug

  • main.c

    #include <pthread.h>
    #include <stdio.h>

    Society of wine educators maps. void work(void parg){
    int val = (int)parg;
    printf(“worker tid=%dn”, *val);
    *val = 100;
    }

    int main (){
    pthread_t handle;
    int data = 0;

    }

  • CMakeLists.txt

    cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
    project(pthread_task)
    add_executable(pthread_task main.c)
    target_link_libraries(pthread_task pthread.a libc.a)
    install(TARGETS pthread_task DESTINATION ${CMAKE_INSTALL_PREFIX})

  • cmake command
    mkdir build
    cd build
    cmake -DCMAKE_BUILD_TYPE=“DEBUG” -DCMAKE_C_FLAGS_DEBUG='-O0 -g -static' …/

  • env
    $ dpkg -l grep cmake
    ii cmake 3.13.4-1 amd64 cross-platform, open-source make system

    $ uname -a
    Linux x250 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2+deb10u1 (2020-06-07) x86_64 GNU/Linux