本帖最后由 everbright 于 2017-9-14 17:47 编辑
用ecliipse生成Ko文件成功,但编写makefile生成so时,提示各种错误?请高手指教!
环境是:ubuntu+eclipse+cdt,用的是nanopi2开发板
源代码文件名叫share_test.c,代码如下:
<p>
/*
* share_test.c
*
* Created on: 2017骞?鏈?3鏃?
* Author: hanyl
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/gpio.h>
#include <mach/platform.h>
#include <mach/gpio_desc.h>
#include <mach/gpio.h></p><p>#define LED_GPIO (PAD_GPIO_B + 26) //GPB26涓篖ED杈撳嚭鎺у埗寮曡剼
#define KEY_GPIO (PAD_GPIO_C + 28) //GPB31涓鸿Е鍙戠粓绔簮
#define KEY_GPIO_IRQ gpio_to_irq(KEY_GPIO) //鏍规嵁GPIO缂栧彿鑾峰彇瀵瑰簲鐨勫紩鑴氱殑涓柇缂栧彿
#define DEVICE_NAME "key_irq"</p><p>
char const irq_types[5] = {
IRQ_TYPE_EDGE_RISING,
IRQ_TYPE_EDGE_FALLING,
IRQ_TYPE_EDGE_BOTH,
IRQ_TYPE_LEVEL_HIGH,
IRQ_TYPE_LEVEL_LOW
};
int Init_Gpio(void)
{
int ret;
/*鐢宠GPIO*/
gpio_free(KEY_GPIO); /*棣栧厛閲婃斁GPIO*/
gpio_free(LED_GPIO); /*棣栧厛閲婃斁GPIO*/
ret = gpio_request_one(KEY_GPIO, GPIOF_IN, "KEY IRQ"); /* 鐢宠 IO 锛屼负杈撳叆*/
if (ret < 0) {
printk(KERN_ERR "Failed to request GPIO for KEY\n");
}</p><p> ret = gpio_request_one(LED_GPIO, GPIOF_OUT_INIT_HIGH, "LED OUTPUT"); /* 鐢宠 IO 锛屼负杈撳嚭*/
if (ret < 0) {
printk(KERN_ERR "Failed to request GPIO for LED\n");
}</p><p> gpio_direction_input(KEY_GPIO); /* 璁剧疆 GPIO 涓鸿緭鍏?*/
gpio_direction_output(LED_GPIO,0); /* 璁剧疆 GPIO 涓鸿緭鍑?鍙傛暟0浠h〃杈撳嚭*/
gpio_set_value(LED_GPIO,0); /*鍒濆鍖朙ED涓虹唲鐏姸鎬?/</p><p> return 0;
}
void LED_light( void )
{
gpio_set_value(LED_GPIO,1);
}
void LED_off(void)
{
gpio_set_value(LED_GPIO,0);
}</p><p>int out_hello(void)
{
printk("hello s3c4418!\n");
return 0;
}
</p><p> </p>
用eclipse生成ko时用的自己的makefile文件,文件内容如下
obj-m += share_test.o
KERN_DIR = /home/hanyl/linux-3.4.y
PWD := $(shell pwd)
ARCH=arm
CROSS_COMPILE=arm-cortexa9-linux-gnueabihf-
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
all:
make -C $(KERN_DIR) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) M=${PWD} modules
clean:
make -C $(KERN_DIR) M=`pwd` modules clean
rm -rf modules.order
虽然写的不规则,但可以编译成功。这里是把初始化和卸载去掉了;
我想生成so动态连接库文件,这是应该怎么写makefile文件?自己写了一个编译不通过,请各位高手支招呀,谢谢
<p><p>KERN_DIR = /home/hanyl/linux-3.4.y
PWD := $(shell pwd)
ARCH=arm
CROSS_COMPILE=arm-cortexa9-linux-gnueabihf-
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
CFLAGS :=
LDFLAGS := -shared -fPIC
SOURCE := $(wildcard *.c)
OBJS := $(patsubst %.c,%.o,$(SOURCE))
TARGET_LIB := share_test.so
all:$(OBJS)
echo $(OBJS)
$(LD) $(LDFLAGS) -o $(TARGET_LIB) $(OBJS)
%.o:%.c
[url=home.php?mod=space&uid=3148]@echo[/url] Compiling [ DISCUZ_CODE_11 ]lt; ...
$(CC) -c $(CFLAGS) [ DISCUZ_CODE_11 ]lt; -o $*.o </p><p>.PHONY: clean
clean:
rm *.so *.o -rf</p>
|