I am using gcc version 9.3.0 on ubuntu20 and try a test about named semaphore. I found that it would crash at sem_open when using -static but it works fine without -static. I don't why and someone could help me out? Thanks!
The complete code follow here:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <semaphore.h>
int main(int argc, char* argv[]) {
sem_t* p = sem_open("ec_initial_name_sem", O_RDWR|O_CREAT, 0777, 1);
while(1) { usleep(10000000); }
}
when using "g++ testNamedSem.cpp -g -o namedSem -lpthread -static " for compiling, the compiled bin would crashed at sem_open, while "g++ testNamedSem.cpp -g -o namedSem -lpthread" works fine.