2010-07-31 59 views
2

我試圖用llvm-gcc(llvm版本1.7)來編譯驅動程序(linux/drivers /淨/ zorro8390.c)爲研究目的的Linux內核源代碼(版本2.6.18.8),但我從jiffies.h得到了很多的錯誤:編譯與llvm-gcc驅動程序代碼時得到「錯誤:在#if中除零#」在編譯驅動程序代碼與llvm-gcc

bash-3.2$ llvm-gcc -D__GNUCC -E -I../../include zorro8390.c -o test.o 
In file included from ../../include/linux/lockdep.h:12, 
       from ../../include/linux/spinlock_types.h:12, 
       from ../../include/linux/spinlock.h:78, 
       from ../../include/linux/module.h:10, 
       from zorro8390.c:22: 
../../include/linux/list.h:887:2: warning: #warning "don't include kernel headers in userspace" 
In file included from zorro8390.c:30: 
../../include/linux/jiffies.h:210:31: error: division by zero in #if 
../../include/linux/jiffies.h:210:31: error: division by zero in #if 
...(a bunch of same errors) 
../../include/linux/jiffies.h:432:28: error: division by zero in #if 

我上GOOGLE了很多的討論這個錯誤,但很多都是關於用make命令構建內核的。直接使用llvm-gcc時我仍然不知道如何解決它。對此有何建議?非常感謝您的幫助!

丹尼爾

回答

1

你,因爲你還沒有定義一些需要手工編譯Linux內核源文件時要在命令行上定義的許多事情幾乎可以肯定收到此錯誤。此消息也尖端斷:

linux/list.h:887:2: warning: #warning "don't include kernel headers in userspace" 

您應該make命令行上執行內核的正常生成與V = 1,記錄輸出到文件中,並且挖出線zorro8390。 c - 這會告訴你需要額外的-D開關。可能還有其他必要的(-I,-include等)。

0

jiffies是內核的內部時鐘滴答,取決於名爲HZ的定義,其中iirc是jiffies /秒的數量。這通常是一個配置常量(我記得它一次從100到1024,也許現在更多)。 HZ通常用於分區,因此div/0錯誤。

所以這些都是@Zack正確指的問題;你沒有配置定義等,但你可以嘗試和定義HZ(或它今天叫什麼),看看你是否可以使它工作。

0

我在交叉編譯訪問內核頭文件的程序(ti-davinci toolset)時遇到了同樣的錯誤,我使用here上的信息對它進行了整理。

The correct way to package the header files for a distribution is to run 'make headers_install' from the kernel source directory to install the headers into /usr/include and then rebuild the C library package, with a dependency on the specific version of the just installed kernel headers.

這在我的內核源代碼目錄中創建了一個/ usr/include文件夾,它包含了要包含的頭文件。

0

在我的情況下,#include <linux/time.h>在標題中,但time.h標題文件從... osprey/obj/include/linux中丟失。只要我把頭添加到out文件夾中,錯誤就解決了。 linux/time.h具有所需的正確定義。
出於某種原因,它在拾取丟失的文件之前拾取了錯誤。