0

我尝试编译一个程序。但我认为它不起作用,因为包含路径不正确。

我使用 ELDK 中的 power-linux-gcc。

文件结构是这样的

linux-kernel ----- driver----graphic_test----- Makefile
               |                          |
               |                          | -- main.c
               |
                --  include--linux --- jiffies.h
                                    |
                                      -- semaphore.h   

这是我将它们包含在 semLib.c 文件中的方式

#include <jiffies.h>
#include <semaphore.h> 

我也试过

#include <linux/jiffies.h>
#include <linux/semaphore.h>     

我不太确定问题是否在于包含,但我认为。

那是我的Makefile:

CC=powerpc-linux-gcc

LIBS = ../../kernel/time/jiffies.o ../../kernel/semaphore.o #libdrmko.o libdrm.o libs3gko.o

INC =   -I../../include

C_SRC = main.c lstLib.c  systLib.c semLib.c    #taskLib.c

C_OBJ = main.o lstLib.o systLib.o semLib.o    # taskLib.o

graphics_test: $(LIBS) $(C_OBJ)
    $(CC) -o graphics_test $(LIBS) $(C_OBJ) $(INC)

那是来自make

:~/Linux_Development_Workspace/linux-kernel/drivers/graphic_test$ make
powerpc-linux-gcc    -c -o ../../kernel/semaphore.o ../../kernel/semaphore.c
../../kernel/semaphore.c:28:28: error: linux/compiler.h: No such file or directory
../../kernel/semaphore.c:30:26: error: linux/module.h: No such file or directory
../../kernel/semaphore.c:32:29: error: linux/semaphore.h: No such file or directory
../../kernel/semaphore.c:33:28: error: linux/spinlock.h: No such file or directory
../../kernel/semaphore.c:34:26: error: linux/ftrace.h: No such file or directory
../../kernel/semaphore.c:36: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
../../kernel/semaphore.c:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
../../kernel/semaphore.c:38: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
../../kernel/semaphore.c:39: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
../../kernel/semaphore.c:40: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
../../kernel/semaphore.c:53: warning: 'struct semaphore' declared inside parameter list
../../kernel/semaphore.c:53: warning: its scope is only this definition or declaration, which is probably not what you want
../../kernel/semaphore.c: In function 'down':
../../kernel/semaphore.c:57: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:58: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:59: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:62: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c: At top level:
../../kernel/semaphore.c:64: warning: data definition has no type or storage class
../../kernel/semaphore.c:64: warning: parameter names (without types) in function declaration
../../kernel/semaphore.c:75: warning: 'struct semaphore' declared inside parameter list
../../kernel/semaphore.c: In function 'down_interruptible':
../../kernel/semaphore.c:80: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:81: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:82: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:85: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c: At top level:
../../kernel/semaphore.c:89: warning: data definition has no type or storage class
../../kernel/semaphore.c:89: warning: parameter names (without types) in function declaration
../../kernel/semaphore.c:101: warning: 'struct semaphore' declared inside parameter list
../../kernel/semaphore.c: In function 'down_killable':
../../kernel/semaphore.c:106: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:107: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:108: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:111: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c: At top level:
../../kernel/semaphore.c:115: warning: data definition has no type or storage class
../../kernel/semaphore.c:115: warning: parameter names (without types) in function declaration
../../kernel/semaphore.c:130: warning: 'struct semaphore' declared inside parameter list
../../kernel/semaphore.c: In function 'down_trylock':
../../kernel/semaphore.c:135: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:136: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:138: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:139: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c: At top level:
../../kernel/semaphore.c:143: warning: data definition has no type or storage class
../../kernel/semaphore.c:143: warning: parameter names (without types) in function declaration
../../kernel/semaphore.c:155: warning: 'struct semaphore' declared inside parameter list
../../kernel/semaphore.c: In function 'down_timeout':
../../kernel/semaphore.c:160: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:161: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:162: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:165: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c: At top level:
../../kernel/semaphore.c:169: warning: data definition has no type or storage class
../../kernel/semaphore.c:169: warning: parameter names (without types) in function declaration
../../kernel/semaphore.c:178: warning: 'struct semaphore' declared inside parameter list
../../kernel/semaphore.c: In function 'up':
../../kernel/semaphore.c:182: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:183: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:184: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c:187: error: dereferencing pointer to incomplete type
../../kernel/semaphore.c: At top level:
../../kernel/semaphore.c:189: warning: data definition has no type or storage class
../../kernel/semaphore.c:189: warning: parameter names (without types) in function declaration
../../kernel/semaphore.c:194: error: field 'list' has incomplete type
../../kernel/semaphore.c:204: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__down_common'
../../kernel/semaphore.c:236: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
../../kernel/semaphore.c:241: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
../../kernel/semaphore.c:246: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
../../kernel/semaphore.c:251: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
../../kernel/semaphore.c:256: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
make: *** [../../kernel/semaphore.o] Fehler 1
4

2 回答 2

1

您要么需要添加:

-I../../include/linux

到命令行,或者您需要编写:

#include <linux/jiffies.h>

以访问该文件。检查其他代码使用jiffies.h以查看哪个是标准样式。


另一个问题是单个文件编译没有获得-I选项:

powerpc-linux-gcc    -c -o ../../kernel/semaphore.o ../../kernel/semaphore.c

您需要知道编译 C 文件的内置规则是什么样的。最终,您需要将${INC}价值转化为${CFLAGS}. 简单地说,这可能是:

CFLAGS = ${INC}

更典型的是(至少以我的经验),CFLAGS 是由许多宏构建的。OTOH,看起来这对您来说不是问题。

于 2012-09-18T14:42:16.200 回答
0

乔纳森描述了关键点。(或多或少)问题是/是编译器尝试编译/构建 semaphore.o 并使用默认包含路径。所以我编辑了我的 makefile ,你可以在下面看到它,是什么解决了这个问题。

CC=powerpc-linux-gcc

LIBS =  ../../kernel/semaphore.o  #libdrmko.o libdrm.o libs3gko.o #../../kernel/time/jiffies.o

INC  =  -I/home/linuxdev/Linux_Development_Workspace/linux-kernel/include/ 
INC +=  -I/home/linuxdev/Linux_Development_Workspace/linux-kernel/
INC +=  -I/home/linuxdev/Linux_Development_Workspace/linux-kernel/include/linux

KDIR =  /home/linuxdev/Linux_Development_Workspace/linux-kernel/

C_SRC = main.c lstLib.c  systLib.c semLib.c    #taskLib.c

C_OBJ = main.o lstLib.o systLib.o semLib.o    # taskLib.o

graphics_test: $(LIBS) $(C_OBJ)
    echo Halloq
    $(CC)  -o --sysroot=$(KDIR)  graphics_test   $(LIBS) $(C_OBJ)  #$(INC)

semaphore: semaphore.o
    $(CC)  -o --sysroot=$(KDIR) semaphore ../../kernel/semaphore.o

semaphore.o: 
    @echo pwd:  $(shell pwd)
    $(CC)  -c  $(INC) ../../kernel/semaphore.c

我认为乔纳森描述的方式也可以,但我没有尝试过!

感谢所有试图帮助我的人

于 2012-09-19T08:21:02.570 回答