Include header files in linux

what is default path for header file included in c program?

Try running gcc -v -E — . When I do, part of the output is as follows:

#include search starts here: /usr/lib/gcc/i686-linux-gnu/4.6.1/include /usr/local/include /usr/lib/gcc/i686-linux-gnu/4.6.1/include-fixed /usr/include/i386-linux-gnu /usr/include 

It’s not an answer to the gstreamer question, but I hope this still helps!

/usr/local/include /usr/include 

If you use another path, you can add in your compile command with -I flag. In your case, assuming you have a /usr/local/gst/include directory, you may add -I/usr/local/gst/include and use #include

The path searched depends on the implementation (and current configuration). The correct way to find the include path is to use pkg-config

pkg-config --cflags gstreamer 

it shows this error —> Package gstreamer was not found in the pkg-config search path. Perhaps you should add the directory containing `gstreamer.pc’ to the PKG_CONFIG_PATH environment variable No package ‘gstreamer’ found

@Mr.32 Perhaps you need to specify a version. Or maybe gstreamer isn’t correctly installed. Look in /usr/lib/pkgconfig and /usr/share/pkgconfig .

@Mr.32: As cnicutar has pointed out you need to use pkg-config. For gstreamer it is not just gstreamer, it is gstreamer-. As you have installed gstreamer in /usr/local check the output of ls /usr/local/lib/pkgconfig/gstreamer* , you should find a bunch of .pc files. Now try this: export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig then pkg-config —cflags gstreamer-0.10 assuming you found gstreamer-0.10.pc in ls command. Does that show any output?

Источник

How to include local header files in linux kernel module

My makefile contains EXTRA_CFLAGS= -I$(shell pwd)/../inc/ but when the kernel is made, I get an error stating:

The reason seems to be that when kernel modules are made this command gets run from the makefile: (using make V1):

In other works my $(shell pwd) got expanded to . This is not what I want. How can I specify the -I parameter to point to src/inc of my mymod source tree?

Читайте также:  Linux standard base lsb

2 Answers 2

The Linux kernel makefiles use the Kbuild framework. Although these are interpreted by GNU make, Kbuild consists of a large set of macros with peculiar usage conventions, so typical makefile guidelines do not apply. The nice thing about Kbuild is that you need very little boilerplate considering the complexity of the task.

Kbuild is documented in the kernel source, in Documentation/kbuild . As a module writer, you should especially read modules.txt (and at least skim through the others).

What you’re doing now isn’t working because $(shell pwd) is expanded when the EXTRA_CFLAGS variable is used. Since the makefile runs from the kernel source tree rather than from your module’s directory (this is one of Kbuild’s many nonobvious aspects), it’s picking up the wrong directory.

The official idiom for specifying include directories in an out-of-tree module is in §5.3 of modules.txt . The src variable is set to your module’s toplevel directory. Therefore:

Note that this declaration should be in a file called Kbuild at the root of your module tree. (You may want to consider the src directory to be the root of your module tree; if so, put Kbuild there and replace the value above by -I$(src)/inc ). It’s also possible to put them in a Makefile , but mind that this definition (as long as anything else that applies only when building a kernel module) should be within a conditional directive ifeq ($(KERNELRELEASE),) . See §4.1 of modules.txt .

If you don’t have a Kbuild file already and want to switch to having one, read §4.1 of modules.txt . Having a separate Kbuild file is slightly clearer. Don’t put anything that applies to the kernel in your main makefile, other than a rule to call make -C $(KERNELDIR) M=$(pwd) . In Kbuild , the minimum you need is the list of modules you’re building (often just the one) and a list of files to include in your module, plus a dependency declaration:

EXTRA_CFLAGS := -I$(src)/inc obj-m := mymod.o mymod-y := $(src)/mod/mymod.o $(src)/mod/mymod.o: $(src)/inc/mymod.h 

Источник

However, this code is located in various folders within /home/me/development/skia (which includes core/ animator/ images/ ports/ svg/ and a lot more.) How can I make GCC recognize this path?

Читайте также:  Linux настройка dhcp relay

3 Answers 3

Try gcc -c -I/home/me/development/skia sample.c .

Glad to see this answer here. Another point worth mentioning would be that when you have many «.c» source files, it’s necessary to specify each and every one of them in the commandline itself. You can’t just do something like a -I to specify that all source files are in a certain directory.

If the header is in the same directory as the source, do you need a special include? I can’t get my code to compile either way, and I’m not sure what the problem is

According to this answer to a similar question, gcc would not search the subdirectories for the different header files automatically. Instead, pkg-config could produce the proper -I option?

@EdwinPratt Perhaps you meant to say that -L tells GCC where to look for binary libraries to include (which are specified with -l ). And -I tells GCC where to look for header files to include.

The -I directive does the job:

gcc -Icore -Ianimator -Iimages -Ianother_dir -Iyet_another_dir my_file.c 

To anyone needing this: it looks like you can include directories with spaces in them with quotes: -I»some path/with spaces» .

Using environment variable is sometimes more convenient when you do not control the build scripts / process.

For C includes use C_INCLUDE_PATH .

For C++ includes use CPLUS_INCLUDE_PATH .

See this link for other gcc environment variables.

Example usage in MacOS / Linux

# `pip install` will automatically run `gcc` using parameters # specified in the `asyncpg` package (that I do not control) C_INCLUDE_PATH=/home/scott/.pyenv/versions/3.7.9/include/python3.7m pip install asyncpg 

Example usage in Windows

set C_INCLUDE_PATH="C:\Users\Scott\.pyenv\versions\3.7.9\include\python3.7m" pip install asyncpg # clear the environment variable so it doesn't affect other builds set C_INCLUDE_PATH= 

Источник

Where are include files stored — Ubuntu Linux, GCC

the compiler, GCC in my case, knows where that stdio.h (and even the object file) are located on my hard drive. It just utilizes the files with no interaction from me. I think that on my Ubuntu Linux machine the files are stored at /usr/include/ . How does the compiler know where to look for these files? Is this configurable or is this just the expected default? Where would I look for this configuration? Since I’m asking a question on these include files, what are the source of the files? I know this might be fuzzy in the Linux community but who manages these? Who would provide and manage the same files for a Windows compiler. I was always under the impression that they come with the compiler but that was an assumption.

Читайте также:  Show if port is open linux

4 Answers 4

When the include file is in brackets the preprocessor first searches in paths specified via the -I flag. Then it searches the standard include paths (see the above link, and use the -v flag to test on your system).

When the include file is in quotes the preprocessor first searches in the current directory, then paths specified by -iquote, then -I paths, then the standard paths.

-nostdinc can be used to prevent the preprocessor from searching the standard paths at all.

Environment variables can also be used to add search paths.

When compiling if you use the -v flag you can see the search paths used.

gcc is a rich and complex «orchestrating» program that calls many other programs to perform its duties. For the specific purpose of seeing where #include «goo» and #include will search on your system, I recommend:

$ touch a.c $ gcc -v -E a.c . #include ". " search starts here: #include search starts here: /usr/local/include /usr/lib/gcc/i686-apple-darwin9/4.0.1/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. # 1 "a.c" 

This is one way to see the search lists for included files, including (if any) directories into which #include «. » will look but #include <. >won’t. This specific list I’m showing is actually on Mac OS X (aka Darwin) but the commands I recommend will show you the search lists (as well as interesting configuration details that I’ve replaced with . here;-) on any system on which gcc runs properly.

Источник

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