[CA-2]pthread详细介绍

这篇博客详细介绍了pthread在C语言中的使用,包括pthread_create、pthread_join和pthread_detach函数。通过示例展示了如何创建、等待和分离线程。文章还提供了加速哈希计算的代码,利用pthread进行多线程挖矿,通过加锁避免资源竞争,提高计算效率。

前言

与OpenMP不同,pthread可以进行一些更精细的操作,比如中途退出线程等等

pthread_create

顾名思义,这个函数就是创建一个线程,其FORMAT为

#define _OPEN_THREADS
#include <pthread.h>

int pthread_create(pthread_t *thread, pthread_attr_t *attr,
                   void *(*start_routine) (void *arg), void *arg);

attr可以是一个struct的指针,里面包含有所有你需要赋给这个线程的参数,如果attr为NULL,那么使用默认值
如果创建成功,函数返回0,否则返回-1,并且返回报错类型
EAGAIN:线程资源不足,不能创建下一个线程
EINVAL:第一个参数即thread为null
ELEMULTITHREADFORK:
pthread_create() was invoked from a child process created by calling fork() from a multi-threaded process. This child process is restricted from becoming multi-threaded.
ENOMEM:内存不够创建线程
例子(来自官方文档):

/* CELEBP27 */
#define _OPEN_THREADS
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
void *thread(void *arg) {
  char *ret;
  printf("thread() entered with argument '%s'\n", arg);
  if ((ret = (char*) malloc(20)) == NULL) {
    perror("malloc() error");
    exit(2);
  }
  strcpy(ret, "This is a test");
  pthread_exit(ret);
}

main() {
  pthread_t thid;
  void *ret;

  if (pthread_create(&thid, NULL, thread, "thread 1") != 0) {
    perror("pthread_create() error");
    exit(1);
  }

  if (pthread_join(thid, &ret) != 0) {
    perror("pthread_create() error");
    exit(3);
  }

  printf("thread exited with '%s'\n", ret);
}

输出:

thread() entered with argument 'thread 1'
thread exited with 'This is a test'

pthread_join

这个函数的作用是等待一个线程的结束,其FORMAT为

#define _OPEN_THREADS
#include <pthread.h>

int pthread_join(pthread_t thread, void **status);

pthread_t这种参数类型是为了识别线程号的,每个线程在创建时都有唯一的线程号,有了这个就可以选中特定的线程
status contains a pointer to the status argument passed by the ending thread as part of pthread_exit(). If the ending thread terminated with a return, status contains a pointer to the return value. If the thread was canceled, status can be set to -1.
如果线程结束成功,返回0,否则返回-1并且返回报错信息
EDEADLK:目标直接或间接地加入到了线程中
EINVAL:thread的值不合法
ESRCH:thread并不是一个非分离的线程

pthread_detach

#define _OPEN_THREADS
#include <pthread.h>

int pthread_detach(pthread_t *thread);

起作用是允许存储其线程 ID 位于位置线程中的线程,以便在该线程结束时进行回收。无论螺纹是否分离,此存储都是在进程退出时回收的,并且可能包括用于线程返回值的存储。如果线程尚未结束,pthread_detach()不会导致其结束。
就不需要最后join了
如果线程结束成功,返回0,否则返回-1并且返回报错信息
EINVAL:thread的值不合法
ESRCH:thread是一个已经分离的线程

Makefile

# Specify the compiler and flags that will be used.
CC=gcc
CFLAGS=-Wpedantic -Wall -Wextra -Werror 

# Simplify the target list below.

SHA256_HEADER=hash_functions/sha256.h
BLOCKCHAIN_HEADER=blockchain.h hash_function.h bool.h

SHA256_IMPL=hash_functions/sha256.c
BLOCKCHAIN_IMPL=blockchain.c hash_function.c

SHA256_TEST=hash_functions/sha256_test.c
BLOCKCHAIN_TEST=test.c

SHA256_TARGET=test-sha256.out
BLOCKCHAIN_TARGET=blockchain.out

SUBMISSION_IMPL=Makefile blockchain.c
SUBMISSION_TARGET=hw5.tar

# Target for the blockchain implementation that will test your implementation.
# Trigger this target by `make` or `make blockchain.out`.
$(BLOCKCHAIN_TARGET): Makefile $(SHA256_HEADER) $(BLOCKCHAIN_HEADER) $(SHA256_IMPL) $(BLOCKCHAIN_IMPL) $(BLOCKCHAIN_TEST)
    ${CC} ${CFLAGS} $(BLOCKCHAIN_IMPL) $(SHA256_IMPL) $(BLOCKCHAIN_TEST) -lpthread -o $(BLOCKCHAIN_TARGET)

# Target for testing if the SHA256 implementation works on your computer.
# Trigger this target by `make test-sha256.out`.
$(SHA256_TARGET): Makefile $(SHA256_TEST) $(SHA256_IMPL) $(SHA256_HEADER)
    ${CC} ${CFLAGS} $(SHA256_IMPL) $(SHA256_TEST) -lpthread -o $(SHA256_TARGET)

# Target for creating the tarball for submission.
# Trigger this target by `make submission`.
.PHONY: submission
submission:
    tar -cvpf $(SUBMISSION_TARGET) $(SUBMISSION_IMPL)
    
# Target for cleanup your workspace - deleting all files created by your compiler.
# Trigger this target by `make clean`.
.PHONY: clean
clean:
    rm -rf $(BLOCKCHAIN_TARGET) $(SHA256_TARGET) $(SUBMISSION_TARGET) *.dSYM

头文件

#ifndef _BLOCKCHAIN_H
#define _BLOCKCHAIN_H

#include "bool.h"
#include "hash_function.h"
#include <stddef.h>
#include <stdint.h>

struct blockchain_node_header {
  uint32_t index;
  uint32_t timestamp;
  unsigned char prev_hash[HASH_BLOCK_SIZE];
  unsigned char data[256];
  uint64_t nonce;
} __attribute__((__packed__));

typedef struct blockchain_node_header blkh_t;

struct blockchain_node {
  blkh_t header;
  unsigned char hash[HASH_BLOCK_SIZE];
} __attribute__((__packed__));

typedef struct blockchain_node blk_t;

/*
  Initalize your block with index, timestamp, hash from previous block and a set
  of custom data.

  You are not supposed to calcutale hash nonce (i.e., mining) in this function.
  if the data is less than 256 bytes long, padding all the rest bytes with 0. If
  it is more than 256 bytes long, truncate it to 256 bytes.
 */
void blockchain_node_init(blk_t *node, uint32_t index, uint32_t timestamp,
                          unsigned char prev_hash[HASH_BLOCK_SIZE],
                          unsigned char *data, size_t data_size);

/*
  Calculate hash from header of the node (which could be done with smart use of
  `struct blockchain_node_header`), store the hash to the `hash_buf` argument.
*/
void blockchain_node_hash(blk_t *node, unsigned char hash_buf[HASH_BLOCK_SIZE],
                          hash_func func);

/*
  Verify if `node` is legitimate (i.e., have vaild hash) and if `node`'s
  previous node is `prev_node`.
*/
BOOL blockchain_node_verify(blk_t *node, blk_t *prev_node, hash_func func);

/*
  Do mining. The first 'diff' bits of hash should be 0. Only the execution of
  the function will be counted to the mining time of your program
*/
void blockchain_node_mine(blk_t *node, unsigned char hash_buf[HASH_BLOCK_SIZE],
                          size_t diff, hash_func func);

#endif /* blockchain.h */

原文件(为使用pthread加速的文件)

#include "blockchain.h"
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#define THREAD_NUM 5




void blockchain_node_init(blk_t *node, uint32_t index, uint32_t timestamp,
                          unsigned char prev_hash[32], unsigned char *data,
                          size_t data_size) {
    if (!node || !data || !prev_hash) // node data prev_hash valid 
    return;

  node->header.index = index;
  node->header.timestamp = timestamp;
  node->header.nonce = -1;

  memset(node->header.data, 0, sizeof(unsigned char) * 256);
  memcpy(node->header.prev_hash, prev_hash, HASH_BLOCK_SIZE);
  memcpy(node->header.data, data,
         sizeof(unsigned char) * ((data_size < 256) ? data_size : 256));
}

void blockchain_node_hash(blk_t *node, unsigned char hash_buf[HASH_BLOCK_SIZE],
                          hash_func func) {
  if (node)
    func((unsigned char *)node, sizeof(blkh_t), (unsigned char *)hash_buf);
}

BOOL blockchain_node_verify(blk_t *node, blk_t *prev_node, hash_func func) {
  unsigned char hash_buf[HASH_BLOCK_SIZE];

  if (!node || !prev_node)
    return False;

  blockchain_node_hash(node, hash_buf, func);
  if (memcmp(node->hash, hash_buf, sizeof(unsigned char) * HASH_BLOCK_SIZE))
    return False;

  blockchain_node_hash(prev_node, hash_buf, func);
  if (memcmp(node->header.prev_hash, hash_buf,
             sizeof(unsigned char) * HASH_BLOCK_SIZE))
    return False;

  return True;
}

/* The sequiental implementation of mining implemented for you. */
void blockchain_node_mine(blk_t *node, unsigned char hash_buf[HASH_BLOCK_SIZE],
                          size_t diff, hash_func func) {
  unsigned char one_diff[HASH_BLOCK_SIZE];
  size_t diff_q, diff_m;
  diff_q = diff / 8;
  diff_m = diff % 8;
  memset(one_diff, 0xFF, sizeof(unsigned char) * HASH_BLOCK_SIZE);
  memset(one_diff, 0, sizeof(unsigned char) * diff_q);
  one_diff[diff_q] = ((uint8_t)0xFF) >> diff_m;
  
}

加速后的文件

#include "blockchain.h"
#include <stdlib.h>
#include <string.h>
#include  <pthread.h>

#define THREAD_NUM 20
int nounce = 0;

void blockchain_node_init(blk_t *node, uint32_t index, uint32_t timestamp,
                          unsigned char prev_hash[32], unsigned char *data,
                          size_t data_size) {
    if (!node || !data || !prev_hash)
        return;

    node->header.index = index;
    node->header.timestamp = timestamp;
    node->header.nonce = -1;

    memset(node->header.data, 0, sizeof(unsigned char) * 256);
    memcpy(node->header.prev_hash, prev_hash, HASH_BLOCK_SIZE);
    memcpy(node->header.data, data,
           sizeof(unsigned char) * ((data_size < 256) ? data_size : 256));
}

void blockchain_node_hash(blk_t *node, unsigned char hash_buf[HASH_BLOCK_SIZE],
                          hash_func func) {
    if (node)
        func((unsigned char *) node, sizeof(blkh_t), (unsigned char *) hash_buf);
}

BOOL blockchain_node_verify(blk_t *node, blk_t *prev_node, hash_func func) {
    unsigned char hash_buf[HASH_BLOCK_SIZE];

    if (!node || !prev_node)
        return False;

    blockchain_node_hash(node, hash_buf, func);
    if (memcmp(node->hash, hash_buf, sizeof(unsigned char) * HASH_BLOCK_SIZE))
        return False;

    blockchain_node_hash(prev_node, hash_buf, func);
    if (memcmp(node->header.prev_hash, hash_buf,
               sizeof(unsigned char) * HASH_BLOCK_SIZE))
        return False;

    return True;
}

struct mydata {
    blk_t *node;
    hash_func *func;
    unsigned char *hash_buf;
    unsigned char *one_diff;
    size_t diff_q;
    uint64_t nonce;
    pthread_mutex_t mutex;
    int *ops;
    int flag;
};

void *thread_in_while(void *mydata) {
    struct mydata *my_data = (struct mydata *) mydata;
    size_t diff_q;
    int j;
    blk_t temp_node;
    unsigned char hash_buf[HASH_BLOCK_SIZE];
    unsigned char *one_diff;
    uint64_t buffer_1;
    uint64_t buffer_2;
    unsigned char *str1;
    unsigned char *str2;

    memcpy(hash_buf, my_data->hash_buf, sizeof(unsigned char) * HASH_BLOCK_SIZE);
    memcpy(&temp_node, my_data->node, sizeof(blk_t));
    diff_q = my_data->diff_q ;
    buffer_1 = sizeof(unsigned char) * (HASH_BLOCK_SIZE - diff_q);
    buffer_2 = sizeof(unsigned char) * diff_q;
    one_diff = my_data->one_diff;
    str1 = &(hash_buf[diff_q]);
    str2 = &(one_diff[diff_q]);

    pthread_mutex_lock(&my_data->mutex);//
    for (j = 0; j < 20; j++) {
        if (my_data->ops[j] == 0) {
            my_data->ops[j] = 1;
            break;
        }
    }
    pthread_mutex_unlock(&my_data->mutex);
    temp_node.header.nonce += j;

    while (my_data->flag){ 
        blockchain_node_hash(&temp_node, hash_buf, my_data->func);
        if ((!memcmp(hash_buf, one_diff, buffer_2)) && memcmp(str1, str2, buffer_1) <= 0) {

            pthread_mutex_lock(&my_data->mutex);
            if (!my_data->flag)
                pthread_exit(NULL);
            my_data->flag = 0;
            nounce = temp_node.header.nonce;

            pthread_mutex_unlock(&my_data->mutex);
            memcpy(my_data->node->hash, hash_buf, sizeof(unsigned char) * HASH_BLOCK_SIZE);
            memcpy(my_data->hash_buf, hash_buf, sizeof(unsigned char) * HASH_BLOCK_SIZE);
            pthread_exit(NULL);
        }
        temp_node.header.nonce += THREAD_NUM;
        
    }
    return NULL;
}

/* The sequiental implementation of mining implemented for you. */
void blockchain_node_mine(blk_t *node, unsigned char hash_buf[HASH_BLOCK_SIZE],
                          size_t diff, hash_func func) {
    unsigned char one_diff[HASH_BLOCK_SIZE];
    size_t diff_q, diff_m;
    pthread_mutex_t mutex;
    int ops[THREAD_NUM] = {0};
    diff_q = diff / 8;
    diff_m = diff % 8;
    pthread_t thread[THREAD_NUM];
    int flag = 1;
    int i;

    memset(one_diff, 0xFF, sizeof(unsigned char) * HASH_BLOCK_SIZE);
    memset(one_diff, 0, sizeof(unsigned char) * diff_q);
    one_diff[diff_q] = ((uint8_t) 0xFF) >> diff_m;
    pthread_mutex_init(&mutex, NULL);

    struct mydata my_data;
    my_data.node = node;
    my_data.hash_buf = hash_buf;
    my_data.one_diff = one_diff;
    my_data.diff_q = diff_q;
    my_data.func = func;
    my_data.mutex = mutex;
    my_data.ops = ops;
    my_data.nonce = -1;
    my_data.flag = flag;
    for (i = 0; i < THREAD_NUM; i++) {
        pthread_create(&thread[i], NULL, thread_in_while, &my_data);
    }
    for (i = 0; i < THREAD_NUM; i++) {
        pthread_join(thread[i], NULL);
    }
    node->header.nonce = nounce;
}
}


解析

因为我为了节省空间所以将这些线程共用了资源,但是这样会导致一些问题,所以我加了线程锁,并且在哈希出的值符合时直接退出,节省了时间
在这里插入图片描述
pthread_mutex_lock与pthread_mutex_unlock合用有点像OpenMP的#pragema critical,只不过我们这里是访问元素的时候只能一个一个来,而OpenMP是执行那段代码的时候只能一个一个来

make[2]: Entering directory ‘/home/bba/work/BBA1_5/MBB_Platform/apps/public/openssl-1.1.1f’ /usr/bin/perl apps/progs.pl apps/openssl > apps/progs.h mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/asn1pars.d.tmp -MT apps/asn1pars.o -c -o apps/asn1pars.o apps/asn1pars.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/ca.d.tmp -MT apps/ca.o -c -o apps/ca.o apps/ca.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/ciphers.d.tmp -MT apps/ciphers.o -c -o apps/ciphers.o apps/ciphers.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/cms.d.tmp -MT apps/cms.o -c -o apps/cms.o apps/cms.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/crl.d.tmp -MT apps/crl.o -c -o apps/crl.o apps/crl.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/crl2p7.d.tmp -MT apps/crl2p7.o -c -o apps/crl2p7.o apps/crl2p7.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/dgst.d.tmp -MT apps/dgst.o -c -o apps/dgst.o apps/dgst.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/dhparam.d.tmp -MT apps/dhparam.o -c -o apps/dhparam.o apps/dhparam.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/dsa.d.tmp -MT apps/dsa.o -c -o apps/dsa.o apps/dsa.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/dsaparam.d.tmp -MT apps/dsaparam.o -c -o apps/dsaparam.o apps/dsaparam.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/ec.d.tmp -MT apps/ec.o -c -o apps/ec.o apps/ec.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/ecparam.d.tmp -MT apps/ecparam.o -c -o apps/ecparam.o apps/ecparam.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/enc.d.tmp -MT apps/enc.o -c -o apps/enc.o apps/enc.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/engine.d.tmp -MT apps/engine.o -c -o apps/engine.o apps/engine.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/errstr.d.tmp -MT apps/errstr.o -c -o apps/errstr.o apps/errstr.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/gendsa.d.tmp -MT apps/gendsa.o -c -o apps/gendsa.o apps/gendsa.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/genpkey.d.tmp -MT apps/genpkey.o -c -o apps/genpkey.o apps/genpkey.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/genrsa.d.tmp -MT apps/genrsa.o -c -o apps/genrsa.o apps/genrsa.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/nseq.d.tmp -MT apps/nseq.o -c -o apps/nseq.o apps/nseq.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/ocsp.d.tmp -MT apps/ocsp.o -c -o apps/ocsp.o apps/ocsp.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/openssl.d.tmp -MT apps/openssl.o -c -o apps/openssl.o apps/openssl.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/passwd.d.tmp -MT apps/passwd.o -c -o apps/passwd.o apps/passwd.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/pkcs12.d.tmp -MT apps/pkcs12.o -c -o apps/pkcs12.o apps/pkcs12.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/pkcs7.d.tmp -MT apps/pkcs7.o -c -o apps/pkcs7.o apps/pkcs7.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/pkcs8.d.tmp -MT apps/pkcs8.o -c -o apps/pkcs8.o apps/pkcs8.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/pkey.d.tmp -MT apps/pkey.o -c -o apps/pkey.o apps/pkey.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/pkeyparam.d.tmp -MT apps/pkeyparam.o -c -o apps/pkeyparam.o apps/pkeyparam.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/pkeyutl.d.tmp -MT apps/pkeyutl.o -c -o apps/pkeyutl.o apps/pkeyutl.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/prime.d.tmp -MT apps/prime.o -c -o apps/prime.o apps/prime.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/rand.d.tmp -MT apps/rand.o -c -o apps/rand.o apps/rand.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/rehash.d.tmp -MT apps/rehash.o -c -o apps/rehash.o apps/rehash.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/req.d.tmp -MT apps/req.o -c -o apps/req.o apps/req.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/rsa.d.tmp -MT apps/rsa.o -c -o apps/rsa.o apps/rsa.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/rsautl.d.tmp -MT apps/rsautl.o -c -o apps/rsautl.o apps/rsautl.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/s_client.d.tmp -MT apps/s_client.o -c -o apps/s_client.o apps/s_client.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/s_server.d.tmp -MT apps/s_server.o -c -o apps/s_server.o apps/s_server.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/s_time.d.tmp -MT apps/s_time.o -c -o apps/s_time.o apps/s_time.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/sess_id.d.tmp -MT apps/sess_id.o -c -o apps/sess_id.o apps/sess_id.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/smime.d.tmp -MT apps/smime.o -c -o apps/smime.o apps/smime.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/speed.d.tmp -MT apps/speed.o -c -o apps/speed.o apps/speed.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/spkac.d.tmp -MT apps/spkac.o -c -o apps/spkac.o apps/spkac.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/srp.d.tmp -MT apps/srp.o -c -o apps/srp.o apps/srp.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/storeutl.d.tmp -MT apps/storeutl.o -c -o apps/storeutl.o apps/storeutl.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/ts.d.tmp -MT apps/ts.o -c -o apps/ts.o apps/ts.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/verify.d.tmp -MT apps/verify.o -c -o apps/verify.o apps/verify.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/version.d.tmp -MT apps/version.o -c -o apps/version.o apps/version.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/x509.d.tmp -MT apps/x509.o -c -o apps/x509.o apps/x509.c rm -f apps/openssl ${LDCMD:-mipsel-linux-gcc} -pthread -Wall -Os -DGNU -L. -o apps/openssl apps/asn1pars.o apps/ca.o apps/ciphers.o apps/cms.o apps/crl.o apps/crl2p7.o apps/dgst.o apps/dhparam.o apps/dsa.o apps/dsaparam.o apps/ec.o apps/ecparam.o apps/enc.o apps/engine.o apps/errstr.o apps/gendsa.o apps/genpkey.o apps/genrsa.o apps/nseq.o apps/ocsp.o apps/openssl.o apps/passwd.o apps/pkcs12.o apps/pkcs7.o apps/pkcs8.o apps/pkey.o apps/pkeyparam.o apps/pkeyutl.o apps/prime.o apps/rand.o apps/rehash.o apps/req.o apps/rsa.o apps/rsautl.o apps/s_client.o apps/s_server.o apps/s_time.o apps/sess_id.o apps/smime.o apps/speed.o apps/spkac.o apps/srp.o apps/storeutl.o apps/ts.o apps/verify.o apps/version.o apps/x509.o apps/libapps.a -lssl -lcrypto -ldl -pthread ./libcrypto.so: warning: gethostbyname is obsolescent, use getnameinfo() instead. ./libcrypto.so: undefined reference to getcontext' ./libcrypto.so: undefined reference to setcontext’ ./libcrypto.so: undefined reference to `makecontext’ collect2: ld returned 1 exit status Makefile:6187: recipe for target ‘apps/openssl’ failed make[2]: *** [apps/openssl] Error 1 make[2]: Leaving directory ‘/home/bba/work/BBA1_5/MBB_Platform/apps/public/openssl-1.1.1f’ Makefile:183: recipe for target ‘build_programs’ failed make[1]: *** [build_programs] Error 2 make[1]: Leaving directory ‘/home/bba/work/BBA1_5/MBB_Platform/apps/public/openssl-1.1.1f’ make/apps/pubapps/openssl.mk:3: recipe for target ‘openssl’ failed make: *** [openssl] Error 2
09-23
make "make -C modules/arp_scanner MODULE_NAME=arp_scanner" make[4]: Entering directory '/home/fuyu1/code/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/modules/arp_scanner' arm-ca9-linux-uclibcgnueabihf-gcc -O2 -pipe -fgnu89-inline -march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard -ftree-vectorize -fno-builtin -fno-common -g -Wno-stringop-truncation -Wno-format-truncation -Wno-sizeof-pointer-div -Wno-stringop-overflow -Wno-format-overflow -Wno-sizeof-pointer-memaccess -I/home/fuyu1/code/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/lib/libiconv-full/include -I/home/fuyu1/code/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/lib/libintl-full/include -DCONFIG_STATISTIC_REPORT_DOMAIN=n-da.tplinkcloud.com.cn -Wno-sizeof-pointer-div -Wno-restrict -Wno-format-truncation -Wno-format-overflow -Wno-stringop-truncation -DSUPPORT_PLUGIN -DCONFIG_MSG_PUSH_POST_URL=/surveillance/v1/reportMsg -DCONFIG_NTP_HOSTNAME=n-tss.tplinkcloud.com.cn -DUP_FIRMWARE_LIMIT_SIZE=16777216 -DSENSITIVITY_INT -DMAKEROOM_BEFORE_UPGRADE -DAUDIO_ENABLE -DCONFIG_TP_TAPO_MAP_ROOTFS -DTP_VIGI -I/home/fuyu1/code/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/include -I/home/fuyu1/code/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/include -I/home/fuyu1/code/Platform_NVMP/nvmp/../sdk/soc/nvt9856x/uclibc-toolchain-1.0.32/arm-ca9-linux-uclibcgnueabihf-8.4.01/arm-ca9-linux-uclibcgnueabihf/sysroot/usr/include -I/home/fuyu1/code/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/lib/libiconv-full/include -I/home/fuyu1/code/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/lib/libintl-full/include -Wall -Werror -ffunction-sections -fdata-sections -DMODULE_LIST="\"tdpd tmpd mactool nifc ipcd dhcpc diagnose httpd tpntp system upgrade arp_scanner\"" -I/home/fuyu1/code/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/include -I/home/fuyu1/code/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/common -I/home/fuyu1/code/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/common/ds -I/home/fuyu1/code/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/modules/mactool -I./libXml -I./libutils -I./libmediautil -I../../include -c -o arp_scan.o arp_scan.c arp_scan.c:7:18: error: 'g_arp_send_pt' initialized and declared 'extern' [-Werror] extern pthread_t g_arp_send_pt = 0; ^~~~~~~~~~~~~ arp_scan.c:8:18: error: 'g_arp_recv_pt' initialized and declared 'extern' [-Werror] extern pthread_t g_arp_recv_pt = 0; ^~~~~~~~~~~~~ arp_scan.c:9:12: error: 'g_arp_send_thread_flag' initialized and declared 'extern' [-Werror] extern int g_arp_send_thread_flag = 0; ^~~~~~~~~~~~~~~~~~~~~~ arp_scan.c:10:12: error: 'g_arp_recv_thread_flag' initialized and declared 'extern' [-Werror] extern int g_arp_recv_thread_flag = 0; ^~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors <builtin>: recipe for target 'arp_scan.o' failed make[4]: *** [arp_scan.o] Error 1
09-02
make "make -C modules/arp MODULE_NAME=arp" make[4]: Entering directory '/home/user/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/modules/arp' arm-ca9-linux-uclibcgnueabihf-gcc -O2 -pipe -fgnu89-inline -march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard -ftree-vectorize -fno-builtin -fno-common -g -Wno-stringop-truncation -Wno-format-truncation -Wno-sizeof-pointer-div -Wno-stringop-overflow -Wno-format-overflow -Wno-sizeof-pointer-memaccess -I/home/user/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/lib/libiconv-full/include -I/home/user/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/lib/libintl-full/include -DCONFIG_STATISTIC_REPORT_DOMAIN=n-da.tplinkcloud.com.cn -Wno-sizeof-pointer-div -Wno-restrict -Wno-format-truncation -Wno-format-overflow -Wno-stringop-truncation -DSUPPORT_PLUGIN -DCONFIG_MSG_PUSH_POST_URL=/surveillance/v1/reportMsg -DCONFIG_NTP_HOSTNAME=n-tss.tplinkcloud.com.cn -DUP_FIRMWARE_LIMIT_SIZE=16777216 -DSENSITIVITY_INT -DMAKEROOM_BEFORE_UPGRADE -DAUDIO_ENABLE -DCONFIG_TP_TAPO_MAP_ROOTFS -DTP_VIGI -I/home/user/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/include -I/home/user/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/include -I/home/user/Platform_NVMP/nvmp/../sdk/soc/nvt9856x/uclibc-toolchain-1.0.32/arm-ca9-linux-uclibcgnueabihf-8.4.01/arm-ca9-linux-uclibcgnueabihf/sysroot/usr/include -I/home/user/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/lib/libiconv-full/include -I/home/user/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/lib/libintl-full/include -Wall -Werror -ffunction-sections -fdata-sections -DMODULE_LIST="\"tdpd tmpd mactool nifc ipcd dhcpc diagnose httpd tpntp system upgrade exception_handling arp\"" -I/home/user/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/include -I/home/user/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/common -I/home/user/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/common/ds -I/home/user/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/modules/mactool -I./libXml -I./libutils -I../../include -c -o arp_data_modal.o arp_data_modal.c arm-ca9-linux-uclibcgnueabihf-gcc -O2 -pipe -fgnu89-inline -march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard -ftree-vectorize -fno-builtin -fno-common -g -Wno-stringop-truncation -Wno-format-truncation -Wno-sizeof-pointer-div -Wno-stringop-overflow -Wno-format-overflow -Wno-sizeof-pointer-memaccess -I/home/user/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/lib/libiconv-full/include -I/home/user/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/lib/libintl-full/include -DCONFIG_STATISTIC_REPORT_DOMAIN=n-da.tplinkcloud.com.cn -Wno-sizeof-pointer-div -Wno-restrict -Wno-format-truncation -Wno-format-overflow -Wno-stringop-truncation -DSUPPORT_PLUGIN -DCONFIG_MSG_PUSH_POST_URL=/surveillance/v1/reportMsg -DCONFIG_NTP_HOSTNAME=n-tss.tplinkcloud.com.cn -DUP_FIRMWARE_LIMIT_SIZE=16777216 -DSENSITIVITY_INT -DMAKEROOM_BEFORE_UPGRADE -DAUDIO_ENABLE -DCONFIG_TP_TAPO_MAP_ROOTFS -DTP_VIGI -I/home/user/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/include -I/home/user/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/include -I/home/user/Platform_NVMP/nvmp/../sdk/soc/nvt9856x/uclibc-toolchain-1.0.32/arm-ca9-linux-uclibcgnueabihf-8.4.01/arm-ca9-linux-uclibcgnueabihf/sysroot/usr/include -I/home/user/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/lib/libiconv-full/include -I/home/user/Platform_NVMP/nvmp/staging_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/usr/lib/libintl-full/include -Wall -Werror -ffunction-sections -fdata-sections -DMODULE_LIST="\"tdpd tmpd mactool nifc ipcd dhcpc diagnose httpd tpntp system upgrade exception_handling arp\"" -I/home/user/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/include -I/home/user/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/common -I/home/user/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/common/ds -I/home/user/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/modules/mactool -I./libXml -I./libutils -I../../include -c -o main.o main.c arm-ca9-linux-uclibcgnueabihf-ar crus -o arp.a arp_data_modal.o main.o -lpthread /home/user/Platform_NVMP/sdk/soc/nvt9856x/uclibc-toolchain-1.0.32/arm-ca9-linux-uclibcgnueabihf-8.4.01/bin/arm-ca9-linux-uclibcgnueabihf-ar: two different operation options specified Makefile:10: recipe for target 'arp.a' failed make[4]: *** [arp.a] Error 1 make[4]: Leaving directory '/home/user/Platform_NVMP/nvmp/build_dir/target-arm-ca9-linux-uclibcgnueabihf-cx20iv1.20/nsd/modules/arp'这是什么问题,给我解释一下
08-29
(base) xyz@xyz-Lenovo-XiaoXinPro-16ACH-2021:~/Downloads$ conda create -n sports python=3.9 -y 2 channel Terms of Service accepted Retrieving notices: done Channels: - defaults Platform: linux-64 Collecting package metadata (repodata.json): done Solving environment: done ## Package Plan ## environment location: /home/xyz/miniconda3/envs/sports added / updated specs: - python=3.9 The following packages will be downloaded: package | build ---------------------------|----------------- ca-certificates-2025.9.9 | h06a4308_0 127 KB libzlib-1.3.1 | hb25bd0a_0 59 KB pip-25.2 | pyhc872135_0 1.2 MB zlib-1.3.1 | hb25bd0a_0 96 KB ------------------------------------------------------------ Total: 1.5 MB The following NEW packages will be INSTALLED: _libgcc_mutex pkgs/main/linux-64::_libgcc_mutex-0.1-main _openmp_mutex pkgs/main/linux-64::_openmp_mutex-5.1-1_gnu bzip2 pkgs/main/linux-64::bzip2-1.0.8-h5eee18b_6 ca-certificates pkgs/main/linux-64::ca-certificates-2025.9.9-h06a4308_0 expat pkgs/main/linux-64::expat-2.7.1-h6a678d5_0 ld_impl_linux-64 pkgs/main/linux-64::ld_impl_linux-64-2.40-h12ee557_0 libffi pkgs/main/linux-64::libffi-3.4.4-h6a678d5_1 libgcc-ng pkgs/main/linux-64::libgcc-ng-11.2.0-h1234567_1 libgomp pkgs/main/linux-64::libgomp-11.2.0-h1234567_1 libstdcxx-ng pkgs/main/linux-64::libstdcxx-ng-11.2.0-h1234567_1 libxcb pkgs/main/linux-64::libxcb-1.17.0-h9b100fa_0 libzlib pkgs/main/linux-64::libzlib-1.3.1-hb25bd0a_0 ncurses pkgs/main/linux-64::ncurses-6.5-h7934f7d_0 openssl pkgs/main/linux-64::openssl-3.0.17-h5eee18b_0 pip pkgs/main/noarch::pip-25.2-pyhc872135_0 pthread-stubs pkgs/main/linux-64::pthread-stubs-0.3-h0ce48e5_1 python pkgs/main/linux-64::python-3.9.23-he99959a_0 readline pkgs/main/linux-64::readline-8.3-hc2a1206_0 setuptools pkgs/main/linux-64::setuptools-78.1.1-py39h06a4308_0 sqlite pkgs/main/linux-64::sqlite-3.50.2-hb25bd0a_1 tk pkgs/main/linux-64::tk-8.6.15-h54e0aa7_0 tzdata pkgs/main/noarch::tzdata-2025b-h04d1e81_0 wheel pkgs/main/linux-64::wheel-0.45.1-py39h06a4308_0 xorg-libx11 pkgs/main/linux-64::xorg-libx11-1.8.12-h9b100fa_1 xorg-libxau pkgs/main/linux-64::xorg-libxau-1.0.12-h9b100fa_0 xorg-libxdmcp pkgs/main/linux-64::xorg-libxdmcp-1.1.5-h9b100fa_0 xorg-xorgproto pkgs/main/linux-64::xorg-xorgproto-2024.1-h5eee18b_1 xz pkgs/main/linux-64::xz-5.6.4-h5eee18b_1 zlib pkgs/main/linux-64::zlib-1.3.1-hb25bd0a_0 Downloading and Extracting Packages: Preparing transaction: done Verifying transaction: done Executing transaction: done # # To activate this environment, use # # $ conda activate sports # # To deactivate an active environment, use # # $ conda deactivate 分析
09-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值