Get the App
SLTechnology News&Howtos  ›  Servers  › 

Errors in compilation under Linux and their Solutions

Shulou Source: shulou.com Published: 2022-06-01 17:39:00 10月05日 Update

This article mainly explains the "Linux compilation errors and solutions", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Linux compilation errors and solutions" bar!

(1) because he is a novice in Linux, he just started thread programming. Input and compile according to an example in the GUN/Linux programming guide, resulting in the following error:

Undefined reference to 'pthread_create'

Undefined reference to 'pthread_join'

The cause of the problem:

The pthread library is not the default library for the Linux system, and you need to use the static library libpthread.a when connecting, so you need to link it when you create a thread using pthread_create () and when you call the pthread_atfork () function to set up a fork handler.

Problem solving:

Add the-lpthread parameter to the compilation

Gcc-o thread thread.c-lpthread

Thread.c is some source files for you, don't forget to add the header file # include

(2) warning: implicit declaration of built-in function strlen incompatibility, implicit declaration of built-in function exit incompatibility

The reason for the problem: because the function strlen is in string and exit is in stdlib. The header files string.h and stdlib are not added to the file

Problem solving: add header files string.h and stdlib to the file

(3) error occurred: the storage size of sem_union is unknown

The reason for the problem: the union sem_union consortium has been annotated in the new 2.6 kernel, so you need to write it yourself.

Problem solving: define in C file first

Union semun {int val; struct semid_ds * buf; unsigned short * array;} sem_union

It can then find the predefined sem_union complex when it compiles.

Thank you for your reading, the above is the "Linux compilation errors and solutions" content, after the study of this article, I believe you under the Linux compilation errors and solutions to this problem have a deeper understanding, the specific use of the need for practice to verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Problems errors files downloads solutions solutions timeouts functions causes unions learning compilation federation content threads programming examples kernels parameters size Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MariaDB NVidia Linux MySQL