我尝试编译程序。但我认为它不起作用,因为包含路径不正确。
我使用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
答案 0 :(得分: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,看起来这对你来说不是一个问题。
答案 1 :(得分: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
我认为Jonathan描述的方式也有效,但我没试过!
感谢所有试图帮助我的人