0

I want to compile one of linux kernel source files (/net/rds/recv.c) for this, call gcc like below :

 gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 

 cc1 -E -quiet -nostdinc -v -imultiarch x86_64-linux-gnu
-iprefix ../lib/gcc/x86_64-linux-gnu/5/ 
-D __attribute__(x)= 
-D __restrict= -D __extension__=
-D __asm__= -D __asm__(x)=
-D __const= -D __inline__=
-D __inline= -D __volatile__=
-D __builtin_va_list=int
-D __KERNEL__ -isystem /lib/modules/4.7.0-rc1+/build/
-isystem /home/username/Desktop/linux/include/
-isystem /home/username/Desktop/linux/usr/include/
-isystem /home/username/workspace/Repositories/4.7.0-rc1+-
 headers/linux/arch/x86/include/ 
-isystem /home/username/workspace/Repositories/4.7.0-rc1+-
headers/linux/arch/x86/include/uapi/
-isystem /home/username/workspace/Repositories/4.7.0-rc1+-
 headers/linux/arch/x86/include/generated/ 
-isystem /home/username/workspace/Repositories/4.7.0-rc1+-
 headers/linux/arch/x86/include/generated/uapi/
-isystem /usr/lib/gcc/x86_64-linux-gnu/5/include/
-isystem /usr/include/
 home/myfolder/linux/net/rds/recv.c -mtune=generic -march=x86-64 -std=c99 -
 fstack-protector-strong -Wformat -Wformat-security

but gcc return me error :

 /home/username/linux/include/linux/jiffies.h:40:3: error: #error Invalid 
 value of HZ.
 # error Invalid value of HZ.

/home/username/linux/include/linux/jiffies.h:257:31: error: division by zero    
in #if
 #if !((((NSEC_PER_SEC << 2) / TICK_NSEC) << (SEC_JIFFIE_SC - 2)) &   
0x80000000)
                           ^
/home/username/linux/include/linux/jiffies.h:293:42: error: division by zero   
in #if
#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
                                      ^
 /home/username/linux/include/linux/jiffies.h:366:20: error: division by 
  zero in   #if
   #if !(USEC_PER_SEC % HZ)

 /home/username/linux/include/linux/mm_types.h:163:45: error: missing binary 
  operator before token "("
  #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && USE_SPLIT_PMD_PTLOCKS

. . .

how can I solve this errors. thanks very much for your help.

2

try with

make net/rds/recv.o

But you should realize that you need a configured kernel in order to compile files. The kernel configuration setup which architecture is it used, which main features are to be included (e.g. multi-core/multi-processor), etc. Many of the kernel header needs such information to generate the correct wrappers around common functions.

Note: the make command will give you (if you are in verbose mode V=1) the parameters that you need to add to compile that file (e.g. which directory to include).

  • dear, thanks for your reply. I tried make command and get answer but unfortunately I have to use gcc. in fact, my main goal is parsing of this file with a special parser that first, calls 'gcc' command to compile program. – Mary Nov 30 '16 at 14:40
  • @Mary As I wrote, you should configure kernel and use V=1 make net/rds/recv.o. The make command will output the gcc command he used to compile the file. Then you can use directly the gcc. But you need the real options (e.g. the directory of the include files). – Giacomo Catenazzi Nov 30 '16 at 14:43
  • How to achieve similar when O=/my/cool/path is supplied as well? – 0andriy Jul 6 '18 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.