deepin20编译ckermit

由于deepin20的软件仓库里面没有ckermit,所以只能自行编译了,期间遇到了一些坑,记录一下

一、在哥伦比亚大学官网下载最新的ckermit源码

http://www.columbia.edu/kermit/ck90.html

这个下载地址不好找,或者又是下载不动,很麻烦,我这里也有下载好的

cku302.zip

二、编译源码

解压进入源码目录,执行

make linux

报错:

ckucmd.c: In function ‘cmdconchk’:
ckucmd.c:7385:48: error: ‘FILE’ {aka ‘struct _IO_FILE’} has no member named ‘_cnt’
     debug(F101,"cmdconchk stdin->_cnt","",stdin->_cnt);
                                                ^~
ckcdeb.h:5129:51: note: in definition of macro ‘debug’
 ((void)(deblog?dodebug(a,b,(char *)(c),(CK_OFF_T)(d)):0))
                                                   ^
ckucmd.c:7386:14: error: ‘FILE’ {aka ‘struct _IO_FILE’} has no member named ‘_cnt’
     x = stdin->_cnt;
              ^~

分析ckucmd.c:7385源代码:

/* Here we must look inside the stdin buffer - highly platform dependent */

#ifdef _IO_file_flags            /* Linux */
    x = (int) ((stdin->_IO_read_end) - (stdin->_IO_read_ptr));
    debug(F101,"cmdconchk _IO_file_flags","",x);
#else  /* _IO_file_flags */
#ifdef USE_FILE_CNT            /* Traditional */
#ifdef VMS
    debug(F101,"cmdconchk (*stdin)->_cnt","",(*stdin)->_cnt);
    x = (*stdin)->_cnt;
#else
#ifdef NOARROWKEYS
    debug(F101,"cmdconchk NOARROWKEYS x","",0);
#else
    debug(F101,"cmdconchk stdin->_cnt","",stdin->_cnt);
    x = stdin->_cnt;
#endif /* NOARROWKEYS */

根据注释来看,这段代码是高度平台相关的。而我经过搜索得知,在linux下stdin结构体是没有_cnt成员的,而在msvc下才有这个成员,所以肯定是错误地执行了#ifdef分支,应该要执行注释为/* Linux */的分支,可是由于宏定义_IO_file_flags不存在,执行了/* Traditional */分支。所以我们需要手动把宏定义加进去

三、解决第一个错误

编辑makefile中的linuxa目标:

linuxa:
    @echo 'Making C-Kermit $(CKVER) for Linux 1.2 or later...'
    @echo 'IMPORTANT: Read the comments in the linux section of the'
    @echo 'makefile if you have trouble.'
    $(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
    "CFLAGS = -O -DLINUX -pipe -funsigned-char -DFNFLOAT -DCK_POSIX_SIG -D_IO_file_flags \
    -DCK_NEWTERM -DTCPSOCKET -DLINUXFSSTND -DNOCOTFMC -DPOSIX \
    -DUSE_STRERROR $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
    "LIBS = $(LIBS) -lm"

在CFLAGS后面加上-D_IO_file_flags

继续执行

make linux

编译成功,但是链接报错

/usr/bin/ld: ckuusx.o: in function `shocps':
ckuusx.c:(.text+0xdb): undefined reference to `stdscr'
/usr/bin/ld: ckuusx.c:(.text+0xe0): undefined reference to `wmove'
/usr/bin/ld: ckuusx.c:(.text+0xf6): undefined reference to `printw'
/usr/bin/ld: ckuusx.c:(.text+0xfd): undefined reference to `stdscr'
/usr/bin/ld: ckuusx.c:(.text+0x102): undefined reference to `wclrtoeol'
/usr/bin/ld: ckuusx.c:(.text+0x17f): undefined reference to `stdscr'
/usr/bin/ld: ckuusx.c:(.text+0x184): undefined reference to `wmove'
/usr/bin/ld: ckuusx.c:(.text+0x1f8): undefined reference to `printw'

后面还有类似的好多错误信息,我就不贴了,搜索一下,似乎是缺少curses库造成的

四、解决第二个错误

编辑makefile文件,在linuxa目标的-lm后面加上-lcurses

linuxa:
    @echo 'Making C-Kermit $(CKVER) for Linux 1.2 or later...'
    @echo 'IMPORTANT: Read the comments in the linux section of the'
    @echo 'makefile if you have trouble.'
    $(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
    "CFLAGS = -O -DLINUX -pipe -funsigned-char -DFNFLOAT -DCK_POSIX_SIG -D_IO_file_flags \
    -DCK_NEWTERM -DTCPSOCKET -DLINUXFSSTND -DNOCOTFMC -DPOSIX \
    -DUSE_STRERROR $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
    "LIBS = $(LIBS) -lm -lcurses"

似乎还要安装一下curses库,反正我装了

sudo apt install libncurses5-dev

继续执行

make linux

编译链接成功,在源码根目录生成wermit可执行文件

运行一下

juju@juju-PC:~/ckermit$ ./wermit 
?SET SPEED has no effect without prior SET LINE
C-Kermit 9.0.302 OPEN SOURCE:, 20 Aug 2011, for Linux (64-bit)
 Copyright (C) 1985, 2011,
  Trustees of Columbia University in the City of New York.
Type ? or HELP for help.
(/home/juju/ckermit/) C-Kermit>exit

标签: linux, deepin, ckermit, 编译

赞赏排名 赞赏支持

添加新评论