[英]How to compile “Hello World” using ncurses in C on Kali
我已經在Kali中成功安裝了ncurses(至少在ncurses-6.1 / test文件夾中包含的例子),但是我自己無法編譯任何東西。
我的代碼:
#include <stdlib.h>
#include <ncurses.h>
int main(void)
{
initscr();
printw("Hello World!!");
refresh();
getch();
endwin();
return 0;
}
編譯失敗:
gcc game.c -lncurses
fatal error: ncurses.h: No such file or directory
我已經詳盡地研究了這個類似的問題,其中包括:
不幸的是,在嘗試了包括curses.h與ncurses.h,使用-lncurses或-lncursesw等編譯的各種排列之后,我不得不向社區尋求幫助!
這聽起來像你手動安裝。 如果是這種情況,則需要在任何安裝它的地方#include "/path/to/ncurses.h"
。
如果您使用aptitude(afaik是默認的Kali包管理器),您可能需要通過apt-get install libncurses-dev
安裝開發包。
希望有所幫助。
您應該使用-I標志或-iquote編譯程序,其中包含包含ncurses.h文件的目錄的路徑
對我來說: gcc game.c -lncurses -iquote/usr/include/
或者您可以將#include </usr/include/ncurses.h>
更改為#include </usr/include/ncurses.h>
根據@Thomas Dickey的評論,我去了invisible-island.net/ncurses並從“開發ncurses源代碼(gzip的tar via http)”鏈接下載了一個干凈的副本,並重新安裝了所有內容./configure
make install
make
然后一切只是神奇地工作。
不需要額外的命令行參數。 它只是gcc game.c -lncurses
使用#include <ncurses.h>
的源文件。 也就是說,我不知道為什么以前沒有其他人的建議。 我之前下載的ncurses確實有頭文件。
關鍵證據是你說的時候
當我運行“apt-get install libncurses-dev”時,它說“E:無法找到包libncurses-dev。”
這意味着您的機器需要進行設置才能訪問更廣泛的軟件包,一旦它能夠找到該軟件包。 發出這個
cat /etc/apt/sources.list
我們只需要更好地填充該文件...因為Kali基於debian版本測試,以下鏈接可以合成/etc/apt/sources.list所需的適當內容
https://debgen.simplylinux.ch/
假設(我沒有Kali盒子方便)它使用debian測試,只需備份sources.list,將其清空並粘貼到你的/etc/apt/sources.list中(從https://debgen.simplylinux.ch/合成)
#------------------------------------------------------------------------------#
# OFFICIAL DEBIAN REPOS
#------------------------------------------------------------------------------#
###### Debian Main Repos
deb http://deb.debian.org/debian/ testing main contrib non-free
deb-src http://deb.debian.org/debian/ testing main contrib non-free
deb http://deb.debian.org/debian/ testing-updates main contrib non-free
deb-src http://deb.debian.org/debian/ testing-updates main contrib non-free
deb http://deb.debian.org/debian-security testing/updates main
deb-src http://deb.debian.org/debian-security testing/updates main
在上面注意每一行中的測試一詞,不同的debian版本會用jessie或者dra ...取代那個單詞然后發行
sudo apt install curl wget apt-transport-https dirmngr
sudo apt-get update && sudo apt-get dist-upgrade
最后你准備安裝了
sudo apt-get install libncurses-dev
您在原始/etc/apt/sources.list中可能擁有的任何存儲庫都可以放回該文件中
PS類人員也為ubuntu https://repogen.simplylinux.ch/提供了類似的列表合成器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.