Linux compiler h no such file or directory

linux/compiler-gcc6.h: No such file or directory #2762

Comments

aleisterdev commented Sep 5, 2016

Please describe your issue:

I get en error about a missing gcc6.h when compiling

If known, describe the steps to reproduce the issue:

When arrived to the command:
$ make-kpkg —rootcmd fakeroot kernel_image kernel_headers

In file included from include/linux/compiler.h:54:0,
from include/uapi/linux/stddef.h:1,
from include/linux/stddef.h:4,
from ./include/uapi/linux/posix_types.h:4,
from include/uapi/linux/types.h:13,
from include/linux/types.h:5,
from include/linux/page-flags.h:8,
from kernel/bounds.c:9:
include/linux/compiler-gcc.h:107:30: fatal error: linux/compiler-gcc6.h: No such file or directory
#include gcc_header(GNUC)
^
compilation terminated.
Kbuild:35: recipe for target ‘kernel/bounds.s’ failed
make[3]: *** [kernel/bounds.s] Error 1
Makefile:1006: recipe for target ‘prepare0’ failed
make[2]: *** [prepare0] Error 2
make[2]: Leaving directory ‘/home/kali/kernel’
debian/ruleset/targets/common.mk:194: recipe for target ‘debian/stamp/conf/kernel-conf’ failed
make[1]: *** [debian/stamp/conf/kernel-conf] Error 2
make[1]: Leaving directory ‘/home/kali/kernel’
/usr/share/kernel-package/ruleset/minimal.mk:93: recipe for target ‘debian/stamp/conf/minimal_debian’ failed
make: *** [debian/stamp/conf/minimal_debian] Error 2
Failed to create a ./debian directory: No such file or directory at /usr/bin/make-kpkg line 970.

But of course:
(kali-rolling)kali@localhost:

/kernel$ sudo apt-get install gcc-6 g++-6
Reading package lists. Done
Building dependency tree
Reading state information. Done
g++-6 is already the newest version (6.1.1-11).
g++-6 set to manually installed.
gcc-6 is already the newest version (6.1.1-11).
gcc-6 set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

That’s not the first time that I had this issue, I had it also when compiling the drivers for my wifi adapter.
Can someone help me with this please?
I’m compiling the kernel headers:
3.18.0-12320-gf988d48
That’s the version I have on: $ uname -r
3.18.0-12320-gbb6b499

I know that the last bit is different and not sure if it matters.
The commit for that kernel was found with:
kali@localhost: /kernel$ git checkout HEAD 675

Any other number different from 675 would have changed the «12320» part of the kernel version.

The text was updated successfully, but these errors were encountered:

Источник

error compiling: linux/module.h: No such file or directory

I’ve written a simple module:

and compiling it with this command:

but I’m getting this error:

EDIT: I used this commad:

and it goes one step ahead, now I get this error:

5 Answers 5

First thing you need the kernel sources. Many confuse user space headers and kernel space headers because many of them have the same folder structure. Most of the distros only have the user space headers and not the kernel space ones.

Читайте также:  Windows 10 владение файлами

And generally make is used to build a kernel module and not a bare cc . Follow the simple step-by-step explained Hello World kernel module given here

Source file name is basic.c

now make file for ubuntu

At first type on ur terminal that $(uname -r) then u will get the version.. that is using on ur system

To run the code

You need the kernel headers; they are usually in /usr/include/ if installed.

Unless you are using a source-based distro or built your own kernel chances are good they are not installed by default; use your distro’s package manager to install them. The package is often called linux-headers .

You need the kernel build environment (selection of scripts, header and Makefiles) usually this is reachable through /lib/modules/version/build (a symlink to it) if a kernel has been installed already. Otherwise, the directory is the build directory (the one where System.map is in). Full sources are not needed (smart distros recognize this), and neither is /usr/include/whatever.

You also must use kbuild; calling cc -I is not enough, and has not been for more than 10 years. You start off with a Kbuild file:

and then utilize make .

#defining __KERNEL__ and MODULE is also pointless, because that is already set by kbuild if needed.

Most Linux distros don’t install kernel headers as default. Look for a package kernel-headers or something similar.

Источник

windows.h no such file or directory (compile c code on linux) [closed]

Want to improve this question? Update the question so it’s on-topic for Stack Overflow.

Closed 4 years ago .

I have a c program that includes a header . This program works fine on windows but on linux when I compile the code with:

main.c:2:10: fatal error windows.h: No such file or directory compilation terminated

Do you have any idea why this error happens and how to fix?

1 Answer 1

The problem is that your code is using the windows.h header file to get function declarations for Windows-only functions. This file does not normally exist on Linux, because its installations of toolchains (such as GCC) will (by default) only include the files needed to compile for Linux.

You have a few options:

As Ed Heal suggested, port the code to Linux. That means you would remove the inclusion of windows.h, and replace all the function calls that used the Windows API with their Linux equivalents. This will make your source code only work on Linux, unless you can refactor the OS-dependent calls into platform-agnostic code. A word of warning: unless the program you’re working with is trivial, this is not an easy task. There’s no guarantee that every Windows API function has a Linux equivalent.

Читайте также:  Linux pax что это

Install a Windows toolchain for your build system, which should include windows.h, and cross-compile your code. This will result in a binary that won’t work on Linux, but will work on Windows.

A middle ground between those two options would be to actually do both, and use conditional compilation to allow you to selectively compile for one target or another.

Источник

linux/module.h: No such file or directory

i’m a beginner and i’m trying out some basics of kernel programming in linux. Today morning i’ve opened the module.h file in VIM, and closed without saving any changes as well. After that i’m not able to compile any of my codes. I’m getting the following error message

Here is a sample code which was running successfully till the last day.

I searched for the module.h file like the following and it do exist

Please help me out. I’m using CentOS in virtual box.

3 Answers 3

You’re trying to compile your module with plain gcc with none of the surrounding kbuild framework. You might have gotten something to work in the past with this approach, but it is painful horrible awful to try to maintain a module using anything other than pure-kbuild Makefile approaches. I’ve wasted too much of my life fighting against kbuild and I don’t want the same to happen with you — embrace kbuild and let it help you build your module. Please read Documentation/kbuild/modules.txt before writing another line of code.

What you need to do is create a Makefile for your module. Its contents should look like this:

I know it’s a lot more complicated than most Makefile s you’re used to seeing, but it serves a dual-purpose. If you just run make in your directory, it’ll re-invoke make to use the kbuild mechanism from the currently-running kernel (assumed to at least have a symlink from /lib/modules/. /build to the correct location).

The re-invoked make command ( $(MAKE) ) will properly build your module and save you more time than you can ever appreciate. (Really.)

Источник

gcc/g++: «No such file or directory»

g++ gives me errors of the form:

It is the same when compiling C-programs with gcc .

Please note: This question has been asked many times before, but each time it was specific to the askers situation. This question’s purpose is to have a question that others can be closed as duplicates of, once and for all; a FAQ.

2 Answers 2

Your compiler just tried to compile the file named foo.cc . Upon hitting line number line , the compiler finds:

The compiler then tries to find that file. For this, it uses a set of directories to look into, but within this set, there is no file bar . For an explanation of the difference between the versions of the include statement look here.

Читайте также:  Installing windows on the machine

How to tell the compiler where to find it

g++ has an option -I . It lets you add include search paths to the command line. Imagine that your file bar is in a folder named frobnicate , relative to foo.cc (assume you are compiling from the directory where foo.cc is located):

You can add more include-paths; each you give is relative to the current directory. Microsoft’s compiler has a correlating option /I that works in the same way, or in Visual Studio, the folders can be set in the Property Pages of the Project, under Configuration Properties->C/C++->General->Additional Include Directories.

Now imagine you have multiple version of bar in different folders, given:

The priority with #include «bar» is leftmost:

As you see, when the compiler started looking through A/ , B/ and C/ , it stopped at the first or leftmost hit.

This is true of both forms, include <> and incude «» .

Difference between #include and #include «bar»

Usually, the #include makes it look into system folders first, the #include «xxx» makes it look into the current or custom folders first.

Imagine you have the following files in your project folder:

For this, your compiler will #include the file list in your project folder, because it currently compiles main.cc and there is that file list in the current folder.

But with main.cc :

and then g++ main.cc , your compiler will look into the system folders first, and because
is a standard header, it will #include the file named list that comes with your C++ platform as part of the standard library.

This is all a bit simplified, but should give you the basic idea.

Details on <> / «» -priorities and -I

According to the gcc-documentation, the priority for include <> is, on a «normal Unix system», as follows:

For C++ programs, it will also look in /usr/include/c++/version, first. In the above, target is the canonical name of the system GCC was configured to compile code for; [. ].

The documentation also states:

You can add to this list with the -Idir command line option. All the directories named by -I are searched, in left-to-right order, before the default directories. The only exception is when dir is already searched by default. In this case, the option is ignored and the search order for system directories remains unchanged.

To continue our #include
/ #include»list» example (same code):

and indeed, the -I. prioritizes the folder . over the system includes and we get a compiler error.

Источник

Оцените статью