Common errors and solutions for Linux programming

Source: Internet
Author: User

Linux programmers often encounter problems with Linux novices, and today lists the most common programming errors encountered by novices, and provides solutions for them:


1) because it is a new Linux novice, it is now beginning to touch threading programming, according to an example in the Gun/linux Programming Guide to enter the compilation, resulting in the following error:

Undefined reference to ' pthread_create '

Undefined reference to ' Pthread_join '

Cause of the problem:

The Pthread library is not the default library for Linux systems and requires static library LIBPTHREAD.A when connecting, so when creating a thread with pthread_create () and calling the Pthread_atfork () function to set up a fork handler, You need to link to the library.

Problem solving:

Add the-lpthread parameter to the compilation

Gcc-o Thread Thread.c-lpthread

THREAD.C for you some of the source files, don't forget to add header file # # #

(2) Warning: Implicit declaration of strlen incompatible with built-in function, implicit declaration of an incompatible exit of the built-in function

Cause of the problem: because the function strlen within a string, exit is within Stdlib. Header file not added in file string.h and Stdlib

Problem solving: Adding header files to files String.h and stdlib

(3) Error occurred: 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: Define in C file first

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.


Common errors and solutions for Linux programming

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.