Error: Sem_union solution for storage size unknown problem _c language

Source: Internet
Author: User
Tags strlen

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.