LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1822|回复: 15

有个想法,不知道能否实现,请linux编程高手赐教

[复制链接]
发表于 2006-10-31 16:35:09 | 显示全部楼层 |阅读模式
我在编译一个公开代码时,不能通过,发现是内核版本不对
要求是2.4的内核版本
而我的是2.6.13的
我想可否在我2.6.13的系统下装个2.4的源码
然后进行编译呢
我阐述不好
但相信大家能够理解我的原意
不知道可否实行
请赐教!!
发表于 2006-10-31 17:35:01 | 显示全部楼层
我认为不可以啊,既然要求内核是2.4的,那么你装一个2.4的源代码就能把你的内核变成2.4了吗? 要求的是内核,而不是源代码. 我这样认为.  除非你编译一个2.4的内核. 不过多数情况是在一个低版本的内核系统上编译一个较高版本的内核. 而在2.6内核的系统上编译2.4的内核,这种情况我没有试过.:sorry
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-31 19:08:39 | 显示全部楼层
谢谢楼上
不过我的意思不是这个
我的意思是只是下个2.4的内核源码
然后修改编译的环境变量,不编译内核
我想编译用到的只是2.4的头文件嘛
而不是将系统的内核编译修改成2.4的
回复 支持 反对

使用道具 举报

发表于 2006-10-31 20:11:58 | 显示全部楼层
需要C库支持的,C库和内核版本关系很紧密。
回复 支持 反对

使用道具 举报

发表于 2006-11-1 10:37:14 | 显示全部楼层
一般应用程序编译时,是不会用到内核头文件的(除非你强制使用).而且应用程序受内核影响的情况是很小的.所以我怀疑你要编译的公开代码是需要在内核里安装一个自己的模块;或是使用了只有2.4内核才提供的系统调用.

能否把编译错误发出来看看呢?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-11-1 19:26:49 | 显示全部楼层

头痛阿,怎么都搞不定

编译时出错
提示没有arm-linux-gcc
我看了它的makefile,发现其中有几句如下:
ifeq ($(TARGET),arm)
    CC := arm-linux-gcc
    LD := arm-linux-ld -m armelf -r
    KPATH := /home/adhoc/ipaq/include/
    MODCFLAGS :=  -O3 -DMODULE -D__KERNEL__ -DLINUX -DARM
endif
我想确实要arm-linux-gcc的包了
于是我就下载了一个3.3.2版本的
装上,再编译
结果:
arm-linux-gcc -O3 -DMODULE -D__KERNEL__ -DLINUX -DARM -DMESSAGES -DAODV_GATEWAY -DAODV_SIGNAL -I/home/adhoc/ipaq/include/ -c aodv_dev.c -o aodv_dev.o
In file included from /usr/local/arm/3.3.2/include/sys/uio.h:24,
                 from /usr/local/arm/3.3.2/include/sys/socket.h:27,
                 from /usr/local/arm/3.3.2/include/net/route.h:25,
                 from packet_queue.h:24,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/include/sys/types.h:41: error: conflicting types for `fsid_t'
/usr/local/arm/3.3.2/arm-linux/sys-include/asm/statfs.h:8: error: previous declaration of `fsid_t'
/usr/local/arm/3.3.2/include/sys/types.h:62: error: conflicting types for `dev_t'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/types.h:14: error: previous declaration of `dev_t'
/usr/local/arm/3.3.2/include/sys/types.h:72: error: conflicting types for `mode_t'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/types.h:16: error: previous declaration of `mode_t'
/usr/local/arm/3.3.2/include/sys/types.h:77: error: conflicting types for `nlink_t'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/types.h:17: error: previous declaration of `nlink_t'
In file included from /usr/local/arm/3.3.2/include/sys/types.h:216,
                 from /usr/local/arm/3.3.2/include/sys/uio.h:24,
                 from /usr/local/arm/3.3.2/include/sys/socket.h:27,
                 from /usr/local/arm/3.3.2/include/net/route.h:25,
                 from packet_queue.h:24,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/include/sys/select.h:38: error: conflicting types for `sigset_t'
/usr/local/arm/3.3.2/arm-linux/sys-include/asm/signal.h:21: error: previous declaration of `sigset_t'
In file included from /usr/local/arm/3.3.2/include/sys/select.h:44,
                 from /usr/local/arm/3.3.2/include/sys/types.h:216,
                 from /usr/local/arm/3.3.2/include/sys/uio.h:24,
                 from /usr/local/arm/3.3.2/include/sys/socket.h:27,
                 from /usr/local/arm/3.3.2/include/net/route.h:25,
                 from packet_queue.h:24,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/include/time.h:119: error: redefinition of `struct timespec'
In file included from /usr/local/arm/3.3.2/include/sys/select.h:46,
                 from /usr/local/arm/3.3.2/include/sys/types.h:216,
                 from /usr/local/arm/3.3.2/include/sys/uio.h:24,
                 from /usr/local/arm/3.3.2/include/sys/socket.h:27,
                 from /usr/local/arm/3.3.2/include/net/route.h:25,
                 from packet_queue.h:24,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/include/bits/time.h:68: error: redefinition of `struct timeval'
In file included from /usr/local/arm/3.3.2/include/sys/types.h:216,
                 from /usr/local/arm/3.3.2/include/sys/uio.h:24,
                 from /usr/local/arm/3.3.2/include/sys/socket.h:27,
                 from /usr/local/arm/3.3.2/include/net/route.h:25,
                 from packet_queue.h:24,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/include/sys/select.h:78: error: conflicting types for `fd_set'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/types.h:13: error: previous declaration of `fd_set'
In file included from /usr/local/arm/3.3.2/include/sys/uio.h:29,
                 from /usr/local/arm/3.3.2/include/sys/socket.h:27,
                 from /usr/local/arm/3.3.2/include/net/route.h:25,
                 from packet_queue.h:24,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/include/bits/uio.h:43: error: redefinition of `struct iovec'
In file included from /usr/local/arm/3.3.2/include/sys/socket.h:35,
                 from /usr/local/arm/3.3.2/include/net/route.h:25,
                 from packet_queue.h:24,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/include/bits/socket.h:43: error: parse error before numeric constant
In file included from /usr/local/arm/3.3.2/include/sys/socket.h:35,
                 from /usr/local/arm/3.3.2/include/net/route.h:25,
                 from packet_queue.h:24,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/include/bits/socket.h:146: error: redefinition of `struct sockaddr'
/usr/local/arm/3.3.2/include/bits/socket.h:173: error: parse error before numeric constant
/usr/local/arm/3.3.2/include/bits/socket.h:188: error: parse error before numeric constant
/usr/local/arm/3.3.2/include/bits/socket.h:216: error: redefinition of `struct msghdr'
/usr/local/arm/3.3.2/include/bits/socket.h:231: error: redefinition of `struct cmsghdr'
/usr/local/arm/3.3.2/include/bits/socket.h:258: error: conflicting types for `__cmsg_nxthdr'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/socket.h:104: error: previous declaration of `__cmsg_nxthdr'
/usr/local/arm/3.3.2/include/bits/socket.h:265: error: redefinition of `__cmsg_nxthdr'
/usr/local/arm/3.3.2/include/bits/socket.h:258: error: `__cmsg_nxthdr' previously defined here
/usr/local/arm/3.3.2/include/bits/socket.h:286: error: parse error before numeric constant
/usr/local/arm/3.3.2/include/bits/socket.h:298: error: redefinition of `struct ucred'
/usr/local/arm/3.3.2/include/bits/socket.h:310: error: redefinition of `struct linger'
In file included from /usr/local/arm/3.3.2/include/net/route.h:27,
                 from packet_queue.h:24,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/include/netinet/in.h:259: error: parse error before '(' token
/usr/local/arm/3.3.2/include/netinet/in.h:259: error: parse error before "__u32"/usr/local/arm/3.3.2/include/netinet/in.h:260: error: parse error before '(' token
/usr/local/arm/3.3.2/include/netinet/in.h:260: error: parse error before "__u16"/usr/local/arm/3.3.2/include/netinet/in.h:262: error: parse error before '(' token
/usr/local/arm/3.3.2/include/netinet/in.h:262: error: parse error before "__u32"/usr/local/arm/3.3.2/include/netinet/in.h:264: error: parse error before '(' token
/usr/local/arm/3.3.2/include/netinet/in.h:264: error: parse error before "__u16"In file included from /usr/local/arm/3.3.2/arm-linux/sys-include/net/sock.h:39,
                 from packet_queue.h:25,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:25: error: conflicting types for `IPPROTO_IP'
/usr/local/arm/3.3.2/include/netinet/in.h:32: error: previous declaration of `IPPROTO_IP'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:26: error: conflicting types for `IPPROTO_ICMP'
/usr/local/arm/3.3.2/include/netinet/in.h:36: error: previous declaration of `IPPROTO_ICMP'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:27: error: conflicting types for `IPPROTO_IGMP'
/usr/local/arm/3.3.2/include/netinet/in.h:38: error: previous declaration of `IPPROTO_IGMP'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:28: error: conflicting types for `IPPROTO_IPIP'
/usr/local/arm/3.3.2/include/netinet/in.h:40: error: previous declaration of `IPPROTO_IPIP'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:29: error: conflicting types for `IPPROTO_TCP'
/usr/local/arm/3.3.2/include/netinet/in.h:42: error: previous declaration of `IPPROTO_TCP'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:30: error: conflicting types for `IPPROTO_EGP'
/usr/local/arm/3.3.2/include/netinet/in.h:44: error: previous declaration of `IPPROTO_EGP'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:31: error: conflicting types for `IPPROTO_PUP'
/usr/local/arm/3.3.2/include/netinet/in.h:46: error: previous declaration of `IPPROTO_PUP'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:32: error: conflicting types for `IPPROTO_UDP'
/usr/local/arm/3.3.2/include/netinet/in.h:48: error: previous declaration of `IPPROTO_UDP'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:33: error: conflicting types for `IPPROTO_IDP'
/usr/local/arm/3.3.2/include/netinet/in.h:50: error: previous declaration of `IPPROTO_IDP'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:34: error: conflicting types for `IPPROTO_RSVP'
/usr/local/arm/3.3.2/include/netinet/in.h:60: error: previous declaration of `IPPROTO_RSVP'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:35: error: conflicting types for `IPPROTO_GRE'
/usr/local/arm/3.3.2/include/netinet/in.h:62: error: previous declaration of `IPPROTO_GRE'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:37: error: conflicting types for `IPPROTO_IPV6'
/usr/local/arm/3.3.2/include/netinet/in.h:54: error: previous declaration of `IPPROTO_IPV6'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:39: error: conflicting types for `IPPROTO_PIM'
/usr/local/arm/3.3.2/include/netinet/in.h:78: error: previous declaration of `IPPROTO_PIM'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:41: error: conflicting types for `IPPROTO_ESP'
/usr/local/arm/3.3.2/include/netinet/in.h:64: error: previous declaration of `IPPROTO_ESP'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:42: error: conflicting types for `IPPROTO_AH'
/usr/local/arm/3.3.2/include/netinet/in.h:66: error: previous declaration of `IPPROTO_AH'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:43: error: conflicting types for `IPPROTO_COMP'
/usr/local/arm/3.3.2/include/netinet/in.h:80: error: previous declaration of `IPPROTO_COMP'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:45: error: conflicting types for `IPPROTO_RAW'
/usr/local/arm/3.3.2/include/netinet/in.h:82: error: previous declaration of `IPPROTO_RAW'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:47: error: conflicting types for `IPPROTO_MAX'
/usr/local/arm/3.3.2/include/netinet/in.h:85: error: previous declaration of `IPPROTO_MAX'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:51: error: redefinition of `struct in_addr'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:92: error: redefinition of `struct ip_mreq'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:98: error: redefinition of `struct ip_mreqn'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:105: error: redefinition of `struct in_pktinfo'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in.h:113: error: redefinition of `struct sockaddr_in'
In file included from /usr/local/arm/3.3.2/arm-linux/sys-include/net/sock.h:42,
                 from packet_queue.h:25,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in6.h:31: error: redefinition of `struct in6_addr'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in6.h:43: error: redefinition of `struct sockaddr_in6'
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/in6.h:51: error: redefinition of `struct ipv6_mreq'
In file included from /usr/local/arm/3.3.2/arm-linux/sys-include/net/sock.h:43,
                 from packet_queue.h:25,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/arm-linux/sys-include/linux/ipv6.h:18: error: redefinition of `struct in6_pktinfo'
In file included from /usr/local/arm/3.3.2/arm-linux/sys-include/net/sock.h:55,
                 from packet_queue.h:25,
                 from aodv_route.h:17,
                 from aodv_dev.h:21,
                 from aodv_dev.c:10:
/usr/local/arm/3.3.2/arm-linux/sys-include/net/protocol.h:89: error: `SOCK_PACKET' undeclared here (not in a function)
/usr/local/arm/3.3.2/arm-linux/sys-include/net/protocol.h:93: error: `SOCK_PACKET' undeclared here (not in a function)
aodv_dev.c: In function `insert_aodv_dev':
aodv_dev.c:105: error: `SOCK_DGRAM' undeclared (first use in this function)
aodv_dev.c:105: error: (Each undeclared identifier is reported only once
aodv_dev.c:105: error: for each function it appears in.)
make: *** [aodv_dev.o] 错误 1
我的系统是suse10.1 内核版本2.6.16
真是郁闷阿
怎么都搞不定
是什么原因哦
在线等高手赐教!!
回复 支持 反对

使用道具 举报

发表于 2006-11-1 20:01:23 | 显示全部楼层
arm-linux-gcc -O3 -DMODULE -D__KERNEL__ -DLINUX -DARM -DMESSAGES -DAODV_GATEWAY -DAODV_SIGNAL -I/home/adhoc/ipaq/include/ -c aodv_dev.c -o aodv_dev.o

原来你是要交叉编译ARM上的源码啊.而且确实有要加入内核的模块.
由于2.6内核和2.4内核的模块编译的调用方式不同,看样子你没法在你2.6内核的系统上直接编译.但我记得你可以在Linux下,安装一个uclinux的虚拟机(当然uclinux内核版本也得是2.4的),在那个上面你应该可以编译.你可以试试!

具体的安装过程,我就不记得了,因为不是我装的.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-11-1 20:11:36 | 显示全部楼层
谢谢楼上!
其实我并不想交叉编译
我的本意是想只在PC机上进行试验
这个代码是下来的别人的
我想在PC机上运行通过后,确认它是正确的
然后边学习边试着在上面进行修改

不知道这个交叉编译的代码与纯PC上的代码有何区别
是不是只要对makefile进行修改
而不必对代码本身进行修改就行了呢
若要改makefile该怎么改呢?能否做个指点
谢谢!!
下面是原来的makefile文件的内容
#Thanks to Bruno Randolf for cleaning up the Makefile
#It should be more extensible now.

KVERSION=`uname -r`

#LOCATE=locate
# if you don't have locate uncomment the line below...it should work.
# you may get alot of permission denied errors...just ignore them.
# find is scouring through every file in /usr/lib...some you'll have
# permission to...some you won't. Hence the error. (David Gervais)
#LOCATE=find /usr/lib | grep

# Select the machine type you wish to compile for
# Your choices are:
#  arm
#  x86
#  mipsel

TARGET:=arm

# These are the options you wish to compile in
# Your choices are:
#  -DMESSAGES       = Support for printing kernel messages to the console
#  -DTRACE          = Support for trace messages for debuggin purposes
#  -DAODV_GATEWAY   = Support for gatewaying to outside networks
#  -DAODV_SIGNAL    = Support for monitoring the signal strength of neighbors
#  -DAODV_MULTICAST = Support for multicasting

AODV_FLAGS := -DMESSAGES -DAODV_GATEWAY -DAODV_SIGNAL

ifeq ($(TARGET),x86)
    CC := gcc
    LD := ld -m elf_i386 -r
    KPATH := /lib/modules/$(KVERSION)/build/include/
    MODCFLAGS :=  -O3 -DMODULE -D__KERNEL__ -DLINUX
endif

ifeq ($(TARGET),arm)
    CC := arm-linux-gcc
    LD := arm-linux-ld -m armelf -r
    KPATH := /home/adhoc/ipaq/include/
    MODCFLAGS :=  -O3 -DMODULE -D__KERNEL__ -DLINUX -DARM
endif
ifeq ($(TARGET),mipsel)
    CC := mipsel-linux-gcc
    LD := mipsel-linux-ld -r
    KPATH := /data/kernel/mips-2_4/include
    MODCFLAGS := -O2 -DMODULE -D__KERNEL__ -DLINUX
    MODCFLAGS += -Wall -fomit-frame-pointer
    MODCFLAGS += -fno-strict-aliasing -G 0 -mno-abicalls -fno-pic
    MODCFLAGS += -mips32 -Wa,--trap -pipe -mlong-calls
    MODCFLAGS += -DEXPORT_SYMTAB -fno-common -c -finline-limit=5000 -mno-abicalls
endif

COMPILE := $(CC) $(MODCFLAGS) $(AODV_FLAGS) -I$(KPATH)

TARGET_MODDIR := /lib/modules/$(KVERSION)

OBJ := aodv_dev.o aodv_neigh.o aodv_route.o aodv_thread.o flood_id.o hello.o kernel_route.o module.o packet_in.o packet_out.o packet_queue.o rerr.o rrep.o rreq.o signal.o socket.o task_queue.o timer_queue.o utils.o rrep_ack.o

SRC := $(wildcard *.c)

all: kernel_aodv.o

    @echo "-----------------------------------------"
    @echo ""
    @echo "Kernel AODV v2.1"
    @echo "Luke Klein-Berndt (kleinb@nist.gov)"
    @echo "Wireless Communications Technologies Group"
    @echo "National Institute Of Standards and Technology"

%.o:    %.c
    $(COMPILE) -c $< -o $@

kernel_aodv.o: $(OBJ)

    @echo ""
    @echo "*** Searching for libgcc.a (Thanks to David Gervais for this routine) ***"     @echo "-----------------------------------------"     @echo "Linking Modules..."

    $(LD) -o kernel_aodv.o $(OBJ)

clean:
    @echo "Removing all .o files..."
    @rm *.o -f

install: kernel_aodv.o

    mkdir -p $(DESTDIR)$(TARGET_MODDIR)/net
    cp kernel_aodv.o $(DESTDIR)$(TARGET_MODDIR)/net

请继续赐教!
初学linux开发
什么都不懂
请不吝赐教!
回复 支持 反对

使用道具 举报

发表于 2006-11-1 20:23:24 | 显示全部楼层
原来你的源码支持X86啊,把TARGET的值改成x86.但即使这样,你还是得在2.4内核上编译才行.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-11-1 20:28:03 | 显示全部楼层
就这样就可以了吗?
它不会根据makefile的内容
ifeq ($(TARGET),arm)
CC := arm-linux-gcc
LD := arm-linux-ld -m armelf -r
KPATH := /home/adhoc/ipaq/include/
MODCFLAGS := -O3 -DMODULE -D__KERNEL__ -DLINUX -DARM
endif
进行交叉编译
从而继续出错了吗
只是修改target就可以是纯PC机上的编译了吗
而这也就是在PC和嵌入式交叉编译时makefile的书写区别
是这样的吗?
请教我
谢谢!!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表