歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 解決從源碼編譯ncurses6.0編譯lib_gen.c報錯的問題

解決從源碼編譯ncurses6.0編譯lib_gen.c報錯的問題

日期:2017/3/1 9:18:00   编辑:Linux編程

解決從源碼編譯ncurses6.0編譯lib_gen.c報錯的問題

直接從官網的源碼編譯時,會提示報錯:

gcc -DHAVE_CONFIG_H -I. -I../include -D_GNU_SOURCE -DNDEBUG -O2 --param max-inline-insns-single=1200 -c ../ncurses/lib_gen.c -o ../objects/lib_gen.o
In file included from ./curses.priv.h:325:0,
from ../ncurses/lib_gen.c:19:
_18018.c:843:15: error: expected ‘)’ before ‘int’
../include/curses.h:1631:56: note: in definition of macro ‘mouse_trafo’
#define mouse_trafo(y,x,to_screen) wmouse_trafo(stdscr,y,x,to_screen)
^
Makefile:967: recipe for target '../objects/lib_gen.o' failed
make[1]: *** [../objects/lib_gen.o] Error 1
make[1]: Leaving directory '/home/abuu/project/ncurses-6.0/ncurses'
Makefile:113: recipe for target 'all' failed
make: *** [all] Error 2

報錯信息提示宏參數不正確,於是在lib_gen.c中搜索wmouse_trafo或者mouse_trafo。

在lib_gen.c中檢索時,發現這部分的代碼與上邊格式不一致,於是嘗試手動修改這部分代碼,嘗試與文件中的其他部分代碼一致。

手動修改後,依然繼續報錯。於是想了解如何自動生成該文件。

在生成日志中,找到如下命令:

/bin/sh -e ./base/MKlib_gen.sh "gcc -E -DHAVE_CONFIG_H -I. -I../include -D_GNU_SOURCE -DNDEBUG" "mawk" generated <../include/curses.h >lib_gen.c

了解到lib_gen.c是通過腳本ncurses/base/MKlib_gen.sh讀取文件include/curses.h後生成的。

打開include/curses.h文件時,發現該文件是通過多個文件生成合並的。查找到跟wmouse_trafo相關的代碼是由curses.tail文件引入生成。

查找到mouse_trafo所在行的代碼:

extern NCURSES_EXPORT(bool) mouse_trafo (int*, int*, bool); /* generated */

於是懷疑是否因為後邊注釋的問題導致的。

刪除include/curses.h中mouse_trafo所在行的注釋,重新make,順利編譯通過.

總結:

這個錯誤是因為curses.tail文件中的多出來的“/* generated */”注釋,刪掉它,再刪掉curses.h,重新make即可。

Copyright © Linux教程網 All Rights Reserved