I am trying to build a custom kernel for NVIDIA Jetson Tk-1 by following the instructions here:
https://github.com/projectara/Android-wiki/wiki/Kernel-Only-Build-Instructions-for-Jetson-reference-platform
Everything goes well until the "Testing Your Custom Kernel" section:
STEP 2. make greybus modules
$ cd $JKB_ROOT/greybus
$ make clean
$ make ARCH=arm KERNELDIR=../kernel-out EXTRA_CFLAGS+=-fno-pic
Here is a snippet for the error I am getting:
/home/jonah/ara_kernel/greybus/loopback.c: In function
'gb_loopback_probe': /home/jonah/ara_kernel/greybus/loopback.c:1207:2:
error: implicit declaration of function 'device_create_with_groups'
[-Werror=implicit-function-declaration] dev =
device_create_with_groups(&loopback_class, ^
/home/jonah/ara_kernel/greybus/loopback.c:1207:6: warning: assignment
makes pointer from integer without a cast [enabled by default] dev =
device_create_with_groups(&loopback_class,
the problem occurs in the loopback.c file, which uses the function device_create_with_groups(...)
Here is the loopback.c file:
https://github.com/projectara/greybus/blob/master/loopback.c
As I understand, this function is found in include/linux/device.h header file, but even if I add #include <linux/device.h> to the beginning of loopback.c, I get the same implicit declaration error.
I am running Ubuntu 14.04 with Linux kernel headers 4.5.0-040500-generic.
Am I using the wrong kernel headers or is the function deprecated or something?
I can get rid of the warning with a declaration in the function above it:
struct device *device_create_with_groups(struct class *class, struct device *parent, dev_t devt, void *drvdata, const struct attribute_group **groups, const char *fmt, ...);
but will this have any severe repercussions when I use the kernel? Or will the function magically be found by the linker eventually?
Related
I am currently writing a Linux Kernel Module (for the first time).
I am trying to use the stat function. I understand that regular imports are not going to work in Kernel code, so I imported their equivalent (that is what I thought...):
#include <linux/stat.h>
#include <linux/errno.h>
#include <linux/unistd.h>
I don't get any error about the imports directly, but I get the following messages:
error: implicit declaration of function ‘stat’ [-Werror=implicit-function-declaration]
error: ‘errno’ undeclared (first use in this function)
For the two lines respectively:
int ret = stat(pathname, statbuf);
and
errno = ENOENT;
Any help woule be welcome.
Thank you.
PS: I am working on Kali 4.9.0-kali4-amd64 but I am trying to write something generic, that could work on multiple versions of Linux.
This question already has answers here:
GCC with -std=c99 complains about not knowing struct timespec
(3 answers)
Closed 6 years ago.
Hello and thanks in advance for all the problems this platform has solved for me in the past. Unfortunately I've found a problem, which I couldn't solve.
I'm pretty new to cmake and expanded a demo project with a new executable and some library files. I have no problems compiling the demo project. However, my new project needs to be compiled with c99 standard and suddenly, I get errors implementing the timespec struct from time.h. This is also used in the demo project, so I compiled the demo again with c99 and I've got the same problem.
Running this on Ubuntu, using the gcc compiler and cmake version 2.8.7
Hope I've got all necessary details covered. If not, please let me know and thanks in advance for your efforts!
Best regards
Edit#1: Error messages I get:
- >CLOCK_MONOTONIC< not declared (first use in this function)
- field 'tv_nsec' could not be resolved
- field 'tv_sec' could not be resolved
- Symbol 'CLOCK_MONOTONIC' could not be resolved
- Warnings for implicit declaration of functions 'clock_gettime', 'nanosleep', 'timeradd', 'timercmp'
Edit#2: error output with make VERBOSE=1
/usr/bin/gcc -D_XOPEN_SOURCE=600 -I/home/localadmin/Eclipse_Workspace/SOEM_master/soem -I/home/localadmin/Eclipse_Workspace/SOEM_master/osal -I/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux -I/home/localadmin/Eclipse_Workspace/SOEM_master/oshw/linux -std=c99 -o CMakeFiles/soem.dir/osal/linux/osal.c.o -c /home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c:60:50: Warning: »struct timezone« declared in parameter list [activated by default]
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c:60:50: Warning: range of validity includes only this definition or declaration [activated by default]
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c: In function »osal_timer_start«:
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c:105:4: Warning: Implicit function »timeradd« [-Wimplicit-function-declaration]
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c: In function »osal_timer_is_expired«:
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c:120:4: Warning: Implicit declaration of function »timercmp« [-Wimplicit-function-declaration]
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c:120:61: Error: expected expression before »<« token
make[2]: *** [CMakeFiles/soem.dir/osal/linux/osal.c.o] Error 1
make[2]: Leaving directory '/home/localadmin/Eclipse_Workspace/SOEM_master/build'
make[1]: *** [CMakeFiles/soem.dir/all] Error 2
make[1]: Leaving directory '/home/localadmin/Eclipse_Workspace/SOEM_master/build'
make: *** [all] Error 2
This was the output after definining _XOPEN_SOURCE=600, what was suggested in the other thread that got posted below. So the timespec struct is available, but the functions aren't.
Edit #3: minimal, complete and verifiable example
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
int main()
{
struct timespec test;
test.tv_sec = 0;
struct timeval start_time;
struct timeval timeout;
struct timeval stop_time;
timeradd(&start_time, &timeout, &stop_time);
return 0;
}
Compiles without problems. If I use gcc mcv_example.c -std=c99 I get:
mcv_example.c: In function 'main':
mcv_example.c:24:18: error: storage size of 'test' isn't known
mcv_example.c:29:2: warning: implicit declaration of function 'timeradd' [-Wimplicit-function-declaration]
Edit#4: The solution for me was using gnu99 instead of c99. Now I can create the UNIX Makefiles with cmake, but still can't create a working Eclipse project.
Since that is a different problem, I guess this case is closed and thank you all for your help and efforts!
As man timeradd says, definition of function timeradd is available only when _DEFAULT_SOURCE feature-test-macro is defined:
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
All functions shown above:
Since glibc 2.19:
_DEFAULT_SOURCE
Glibc 2.19 and earlier:
_BSD_SOURCE
Description for _DEFAULT_SOURCE macro in man feature_test_macros says:
This macro can be defined to ensure that the "default" definitions
are provided even when the defaults would otherwise be disabled,
as happens when individual macros are explicitly defined, or the
compiler is invoked in one of its "standard" modes (e.g.,
cc -std=c99).
So you need to explicitely define _DEFAULT_SOURCE macro for make function timeradd being available in -std=c99 mode:
#define _DEFAULT_SOURCE
#include <sys/time.h>
...
timeradd(...);
While compiling code for softiwarp using this guide
I encountered the following errors while compile codes in kernel directory.
error: implicit declaration of function ‘remap_vmalloc_range’
error: implicit declaration of function ‘vmalloc’
error: implicit declaration of function ‘vmalloc_user’
error: implicit declaration of function ‘vfree’
Anyone here could help guide me, how to install the libraries related to this function? I'm using ubuntu 16.04.
These functions are declared in <linux/vmalloc.h>. You need to #include that header.
I'm trying to compile libpcap with cross compilator arm-linux-gcc. When I run 'make' I get an error:
./pcap-linux.c:254:14: conflicting types for socklen_t /usr/arm-linux-gnueabi/include/unistd.h:275:21: note previous declaration of 'socklen_t'
I've also tried to compile it using common gcc but i have the same error. I work on ubuntu. How to resolve this problem
pcap-linux.c makes an alias in next way:
#ifndef HAVE_SOCKLEN_T
typedef int socklen_t;
#endif
You should pass -DHAVE_SOCKLEN_T to compiler or put
#define HAVE_SOCKLEN_T
to some header (usually it is done automatically by configure script or similar, that generates config.h).
Seems like you skipped build configuration step, so be ready to see another weird build errors.
I am trying to use execl call to execute a binary in kernel-space-driver (driver.c) at this point(line no. 850 onward):
if (!retval)
{
pr_info("%s: registered new device driver %s\n",
usbcore_name, new_udriver->name);
execl("binarylocation", "binary", NULL);
}
I have also added the #include < linux/unistd.h> in the file.
But when the kernel is build I get the following error:
error: implicit declaration of function 'execl' [-Werror=implicit-function-declaration]
and thus the kernel failed to built.
And one warning is coming:
warning: incompatible implicit declaration of built-in function 'execl' [enabled by default]
Why are these errors and warning coming, even though the required header files are included?
execl is provided by libc, which is user-mode. In addition, exec functions replace the current process, but that context in the kernel doesn't really have a "current process" you'd want to be replacing.
The correct way to do this would be through a udev rule. If you really don't want to use udev for some reason, you can use the usermode helper API (example).