目标'CMakeFiles / ex123.dir / all'的配方失败

时间:2019-05-10 06:03:41

标签: c compiler-errors

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

/* this function is run by the second thread */
void *inc_x(void *x_void_ptr)
{

/* increment x to 100 */
    int *x_ptr = (int *)x_void_ptr;
    while(++(*x_ptr) < 100);

    printf("x increment finished\n");

/* the function must return something - NULL will do */
    return NULL;

}

int main()
{

    int x = 0, y = 0;

/* show the initial values of x and y */
    printf("x: %d, y: %d\n", x, y);

/* this variable is our reference to the second thread */
    pthread_t inc_x_thread;

/* create a second thread which executes inc_x(&x) */
    if(pthread_create(&inc_x_thread, NULL, inc_x, &x)) {

        fprintf(stderr, "Error creating thread\n");
        return 1;

    }
/* increment y to 100 in the first thread */
    while(++y < 100);

    printf("y increment finished\n");

/* wait for the second thread to finish */
    if(pthread_join(inc_x_thread, NULL)) {

        fprintf(stderr, "Error joining thread\n");
        return 2;

    }

/* show the results - x is now 100 thanks to the second thread */
    printf("x: %d, y: %d\n", x, y);

    return 0;

}##
  

Blockquote

collect2:错误:ld返回1退出状态 CMakeFiles / ex123.dir / build.make:83:目标'ex123'的配方失败 make [3]: * [ex123]错误1 CMakeFiles / Makefile2:72:目标'CMakeFiles / ex123.dir / all'的配方失败 make [2]: [CMakeFiles / ex123.dir / all]错误2 CMakeFiles / Makefile2:84:目标'CMakeFiles / ex123.dir / rule'的配方失败 make [1]: [CMakeFiles / ex123.dir / rule]错误2 Makefile:118:目标“ ex123”的配方失败 make:* [ex123]错误2

0 个答案:

没有答案