Analysis of Linux module compiling problem

Source: Internet
Author: User

Tag: Indicates that the start GPO does not display the Star project introduction wal compilation options

Problem Description:

To compile a Linux module, the following error occurred:

Error:conversion to ' int. ' from ' unsigned int ' could change the sign of the result [-werror=sign-conversion]

The problem is that there is no explicit type conversion and the code is as follows:

extern void Bitmap_set (unsigned long *map, unsigned int start, int len);

unsigned int nr;

Bitmap_set (fdev->memory->used, POS, nr);

Problem Analysis:

From the results and analysis to see that this is a compile option configuration resulting in compile error, in theory you can use the method to modify the compilation options to correct the problem, but in makefile to modify the Extra_cflags invalid.

Modification Method: Extra_cflags + =-wno-error or extra_cflags + +-wno-error=sign-conversion

Continue analysis:

1) Use make v=1 to find the detailed GCC options and not found-werror=sign-conversion

2) The same compilation option compiles the test file without errors

Root cause:

The module code uses the #pragma gcc diagnostic error "-wsign-conversion", which defines the file-level GCC alarm option and deletes it.

Introduction to compiling alarm processing:

One

-W means to turn off the compile-time warning, which is not to show any warning after compiling, because sometimes the compiler will display some warnings such as data conversion after compiling, which we can usually ignore.

The-wall option means that all warnings are displayed after compilation.

The-w option is similar to-wall, and displays a warning, but only a warning that the compiler thinks an error will occur.

-werror all alarms are displayed as error

-wno-error do not tell the alarm to appear as error

Two

GCC warnings at various levels
Overwrite

variable (code) level: Specify a variable warning

int a __ ATTRIBUTE__ ((unused)); The
specifies that the variable is unused. Even if the variable is not used, a warning output is ignored at compile time.


file-level: diagnostics (Ignore/warn) in source code file

Syntax:
#pragma GCC diagnostic [error|warning|ignored] "-w< warning Options >
Diagnostics-Ignore: (Turn off warning)


#pragma GCC diagnostic ignored "-wunused"
#pragma GCC diagnostic ignored "-wunused-parameter"
Diagnostics-Warning: (Turn on warning)

#pragma GCC diagnostic warning "-wunused"
#pragma GCC diagnostic warning "-wunused-parameter"
Diagnostics-Error: (Turn on warning-upgrade to error)

#pragma GCC diagnostic error "-wunused"
#pragma GCC diagnostic error "-wunused-parameter"
Usage:
Close the warning at the beginning of the file, and then turn on the warning at the end of the file to ignore the specified warning in the file.


Project-level: command line/compile parameters specified

Warning:
GCC Main.c-wall ignored:
GCC Mian.c-wall-wno-unused-parameter//Open all warning, but ignore-unused-parameter warning

Option format:-w[no-]< warning Options >
such as:-wno-unused-parameter # no-indicates that this warning is ignored when diagnosing

Analysis of Linux module compiling problem

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.