Today, when compiling code, I was prompted with an error: ' Sem_union ' storage size is unknown
Problem reason: in the new 2.6 kernel about Union sem_union This consortium has been annotated and needs to write the consortium itself .
Solution: First define in C file:
Union Semun
{
int val;
struct Semid_ds *buf;
unsigned short *array;
} Sem_union;
It will then be able to find a pre-defined sem_union consortium at compile time.
Linux compile-time errors and solutions
(1) because it is a novice Linux, so now began to contact threading programming, according to an example of the Gun/linux Programming Guide to compile, the results of the following error:
Undefined reference to ' pthread_create '
Undefined reference to ' Pthread_join '
Problem Reason:
The Pthread library is not the default library of the Linux system, which requires the use of a static library libpthread.a, so that when you create a thread using Pthread_create () and call the Pthread_atfork () function to establish a fork handler, You need to link to the library.
Problem solving:
To add-lpthread parameters to the compilation
Gcc-o Thread Thread.c-lpthread
THREAD.C for your source files, don't forget to add the header file #include<pthread.h>
(2) Warning: built-in function strlen incompatible implicit declaration, built-in function exit incompatible implicit declaration
Problem reason: Because the function strlen in string, exit is inside Stdlib. No header files are added to the file string.h and Stdlib
Problem Resolution: Add header files to files String.h and stdlib
(3) Error: Sem_union storage size is unknown
Problem reason: In the new 2.6 kernel about Union sem_union This consortium has been annotated and needs to write the consortium itself.
Problem solving: First defined in C file
Union Semun {int val; struct semid_ds *buf; unsigned short *array;} sem_union;
It will then be able to find a pre-defined sem_union consortium at compile time.