I have wrote below code:
#include<stdio.h>
#include<pthread.h>
int pthread_create(
pthread_t*,
const pthread_attr_t *,
void* (*)(void *),
void*) __attribute__ ((weak)) ;
int main(){
if (pthread_create) {
printf("multi-thread");
} else {
printf("single-thread");
}
}
When compiling the code with different ways and running it, it shows the same consequence . The codes are undermentioned:
zoushengfu@zoushengfudeMacBook-Pro:~/Documents/code/c++$ gcc -o pt
pthread.cpp
zoushengfu@zoushengfudeMacBook-Pro:~/Documents/code/c++$ ./pt
multi-thread
zoushengfu@zoushengfudeMacBook-Pro:~/Documents/code/c++$ gcc -o pt pthread.cpp -lpthread
zoushengfu@zoushengfudeMacBook-Pro:~/Documents/code/c++$ ./pt
multi-thread
I want to know why the result is same wheather I use library pthread when compile it. And do I some error when using __attribute__((weak))