LinuxForum.Fans
Тема

Использование curses библиотеки с g++

Автор: Nixel 4 сообщений 5067 просмотров
#5788

Привет всем!

Изучаю книгу "Брюс Моли Unix Linux Теория и практика программирования", остановился на разделе посвященному библиотеке curses и возникла проблема.

Вот простой код файла curses.c

text
#include <stdio.h>
#include <curses.h>

int main (int ac, char *av[]){ initscr(); clear(); addstr("Hello World!"); move(LINES-1,0); refresh(); getch(); endwin(); return 0; }

Это самый первый листинг программы из раздела о "curses". При выполнении g++ curses.c -o curses, g++ выдал следующий результат.

text
/tmp/ccqXDHK2.o: In function `main':
curses.c:(.text+0x10): undefined reference to `initscr'
curses.c:(.text+0x15): undefined reference to `clear'
curses.c:(.text+0x1c): undefined reference to `stdscr'
curses.c:(.text+0x2e): undefined reference to `waddnstr'
curses.c:(.text+0x34): undefined reference to `LINES'
curses.c:(.text+0x43): undefined reference to `move'
curses.c:(.text+0x48): undefined reference to `refresh'
curses.c:(.text+0x4f): undefined reference to `stdscr'
curses.c:(.text+0x57): undefined reference to `wgetch'
curses.c:(.text+0x5c): undefined reference to `endwin'
collect2: выполнение ld завершилось с кодом возврата 1

Выполнил поиск файла "curses.h" в "/usr", выдал "/usr/include/curses.h"

Откомпилировал использовав опцию "-B", "g++ curses.c -o curses -B /usr/include/*"
Выдал следующее, это не все, только несколько кусков, при необходимости могу выложить полностью, но остальные части похожи на эти, только ссылаются на другие объекты.

text
In file included from /usr/include/cursesw.h:36,
                 from /usr/include/cursslk.h:39,
                 from /usr/include/cursesapp.h:39:
/usr/include/etip.h: In constructor 'NCursesPanelException::NCursesPanelException(const char*, int)':
/usr/include/etip.h:187: ошибка: нет декларации 'NULL' в этой области видимости
/usr/include/etip.h: In constructor 'NCursesPanelException::NCursesPanelException(int)':
/usr/include/etip.h:199: ошибка: нет декларации 'NULL' в этой области видимости
/usr/include/etip.h: In constructor 'NCursesMenuException::NCursesMenuException(const char*, int)':
/usr/include/etip.h:238: ошибка: нет декларации 'NULL' в этой области видимости
/usr/include/etip.h: In constructor 'NCursesMenuException::NCursesMenuException(int)':
/usr/include/etip.h:250: ошибка: нет декларации 'NULL' в этой области видимости
/usr/include/etip.h: In constructor 'NCursesFormException::NCursesFormException(const char*, int)':
/usr/include/etip.h:289: ошибка: нет декларации 'NULL' в этой области видимости
/usr/include/etip.h: In constructor 'NCursesFormException::NCursesFormException(int)':
/usr/include/etip.h:301: ошибка: нет декларации 'NULL' в этой области видимости
In file included from /usr/include/cursesw.h:36,
                 from /usr/include/cursesp.h:39,
                 from /usr/include/cursesf.h:39:
/usr/include/etip.h: In constructor 'NCursesPanelException::NCursesPanelException(const char*, int)':
/usr/include/etip.h:187: ошибка: нет декларации 'NULL' в этой области видимости
/usr/include/etip.h: In constructor 'NCursesPanelException::NCursesPanelException(int)':
/usr/include/etip.h:199: ошибка: нет декларации 'NULL' в этой области видимости
/usr/include/etip.h: In constructor 'NCursesMenuException::NCursesMenuException(const char*, int)':
/usr/include/etip.h:238: ошибка: нет декларации 'NULL' в этой области видимости
/usr/include/etip.h: In constructor 'NCursesMenuException::NCursesMenuException(int)':
/usr/include/etip.h:250: ошибка: нет декларации 'NULL' в этой области видимости
/usr/include/etip.h: In constructor 'NCursesFormException::NCursesFormException(const char*, int)':
/usr/include/etip.h:289: ошибка: нет декларации 'NULL' в этой области видимости
/usr/include/etip.h: In constructor 'NCursesFormException::NCursesFormException(int)':
/usr/include/etip.h:301: ошибка: нет декларации 'NULL' в этой области видимости

......

/usr/include/gcrypt-module.h:41: ошибка: ISO C++ запрещает декларации 'gcry_err_code_t' без типа /usr/include/gcrypt-module.h:41: ошибка: typedef 'gcry_err_code_t' is initialized (use decltype instead) /usr/include/gcrypt-module.h:41: ошибка: нет декларации 'gcry_cipher_setkey_t' в этой области видимости /usr/include/gcrypt-module.h:79: ошибка: 'size_t' does not name a type /usr/include/gcrypt-module.h:80: ошибка: 'size_t' does not name a type /usr/include/gcrypt-module.h:81: ошибка: 'size_t' does not name a type /usr/include/gcrypt-module.h:82: ошибка: 'gcry_cipher_setkey_t' does not name a type /usr/include/gcrypt-module.h:92: ошибка: 'gcry_error_t' does not name a type /usr/include/gcrypt-module.h:103: ошибка: ISO C++ запрещает декларации 'gcry_err_code_t' без типа /usr/include/gcrypt-module.h:103: ошибка: typedef 'gcry_err_code_t' is initialized (use decltype instead) /usr/include/gcrypt-module.h:103: ошибка: нет декларации 'gcry_pk_generate_t' в этой области видимости /usr/include/gcrypt-module.h:110: ошибка: ISO C++ запрещает декларации 'gcry_err_code_t' без типа /usr/include/gcrypt-module.h:110: ошибка: typedef 'gcry_err_code_t' is initialized (use decltype instead) /usr/include/gcrypt-module.h:110: ошибка: нет декларации 'gcry_pk_check_secret_key_t' в этой области видимости /usr/include/gcrypt-module.h:114: ошибка: ISO C++ запрещает декларации 'gcry_err_code_t' без типа /usr/include/gcrypt-module.h:114: ошибка: typedef 'gcry_err_code_t' is initialized (use decltype instead) /usr/include/gcrypt-module.h:114: ошибка: нет декларации 'gcry_pk_encrypt_t' в этой области видимости /usr/include/gcrypt-module.h:121: ошибка: ISO C++ запрещает декларации 'gcry_err_code_t' без типа /usr/include/gcrypt-module.h:121: ошибка: typedef 'gcry_err_code_t' is initialized (use decltype instead) /usr/include/gcrypt-module.h:121: ошибка: нет декларации 'gcry_pk_decrypt_t' в этой области видимости /usr/include/gcrypt-module.h:128: ошибка: ISO C++ запрещает декларации 'gcry_err_code_t' без типа /usr/include/gcrypt-module.h:128: ошибка: typedef 'gcry_err_code_t' is initialized (use decltype instead) /usr/include/gcrypt-module.h:128: ошибка: нет декларации 'gcry_pk_sign_t' в этой области видимости /usr/include/gcrypt-module.h:134: ошибка: ISO C++ запрещает декларации 'gcry_err_code_t' без типа /usr/include/gcrypt-module.h:134: ошибка: typedef 'gcry_err_code_t' is initialized (use decltype instead) /usr/include/gcrypt-module.h:134: ошибка: нет декларации 'gcry_pk_verify_t' в этой области видимости /usr/include/gcrypt-module.h:142: ошибка: 'gcry_mpi_t' has not been declared /usr/include/gcrypt-module.h:155: ошибка: 'gcry_pk_generate_t' does not name a type /usr/include/gcrypt-module.h:156: ошибка: 'gcry_pk_check_secret_key_t' does not name a type /usr/include/gcrypt-module.h:157: ошибка: 'gcry_pk_encrypt_t' does not name a type /usr/include/gcrypt-module.h:158: ошибка: 'gcry_pk_decrypt_t' does not name a type /usr/include/gcrypt-module.h:159: ошибка: 'gcry_pk_sign_t' does not name a type /usr/include/gcrypt-module.h:160: ошибка: 'gcry_pk_verify_t' does not name a type /usr/include/gcrypt-module.h:167: ошибка: 'gcry_error_t' does not name a type /usr/include/gcrypt-module.h:181: ошибка: 'size_t' has not been declared /usr/include/gcrypt-module.h:206: ошибка: 'size_t' does not name a type /usr/include/gcrypt-module.h:212: ошибка: 'gcry_error_t' does not name a type /usr/include/jpegint.h:46: ошибка: 'prepare_for_pass' has not been declared /usr/include/jpegint.h:46: ошибка: expected identifier before '(' token /usr/include/jpegint.h:46: ошибка: expected ')' before 'cinfo' /usr/include/jpegint.h:46: ошибка: expected ')' before 'cinfo' /usr/include/jpegint.h:46: ошибка: ISO C++ запрещает декларации 'JMETHOD' без типа /usr/include/jpegint.h:46: ошибка: expected ';' before 'cinfo' /usr/include/jpegint.h:47: ошибка: 'pass_startup' has not been declared /usr/include/jpegint.h:47: ошибка: expected identifier before '(' token /usr/include/jpegint.h:47: ошибка: expected ')' before 'cinfo' /usr/include/jpegint.h:47: ошибка: expected ')' before 'cinfo' /usr/include/jpegint.h:47: ошибка: ISO C++ запрещает декларации 'JMETHOD' без типа /usr/include/jpegint.h:47: ошибка: expected ';' before 'cinfo' /usr/include/jpegint.h:48: ошибка: 'finish_pass' has not been declared /usr/include/jpegint.h:48: ошибка: expected identifier before '(' token /usr/include/jpegint.h:48: ошибка: expected ')' before 'cinfo' /usr/include/jpegint.h:48: ошибка: expected ')' before 'cinfo'

......

/usr/include/jpegint.h:363: ошибка: expected constructor, destructor, or type conversion before 'jinit_color_deconverter' /usr/include/jpegint.h:364: ошибка: expected constructor, destructor, or type conversion before 'jinit_1pass_quantizer' /usr/include/jpegint.h:365: ошибка: expected constructor, destructor, or type conversion before 'jinit_2pass_quantizer' /usr/include/jpegint.h:366: ошибка: expected constructor, destructor, or type conversion before 'jinit_merged_upsampler' /usr/include/jpegint.h:368: ошибка: expected constructor, destructor, or type conversion before 'jinit_memory_mgr' /usr/include/jpegint.h:371: ошибка: expected constructor, destructor, or type conversion before 'jdiv_round_up' /usr/include/jpegint.h:372: ошибка: expected constructor, destructor, or type conversion before 'jround_up' /usr/include/jpegint.h:373: ошибка: expected constructor, destructor, or type conversion before 'jcopy_sample_rows' /usr/include/jpegint.h:376: ошибка: expected constructor, destructor, or type conversion before 'jcopy_block_row' /usr/include/jpegint.h:378: ошибка: expected constructor, destructor, or type conversion before 'jzero_far' /usr/include/jpeglib.h:719: ошибка: 'size_t' does not name a type /usr/include/jpeglib.h:731: ошибка: 'size_t' does not name a type /usr/include/jpeglib.h:762: ошибка: 'size_t' has not been declared /usr/include/jpeglib.h:764: ошибка: 'size_t' has not been declared /usr/include/jpeglib.h:904: ошибка: 'size_t' has not been declared /usr/include/jpeglib.h:906: ошибка: 'size_t' has not been declared /usr/include/jpeglib.h:914: ошибка: 'FILE' has not been declared /usr/include/jpeglib.h:915: ошибка: 'FILE' has not been declared /usr/include/limits.h:125:3: warning: #include_next in primary source file /usr/include/pngconf.h:1241: ошибка: expected initializer before '*' token /usr/include/pngconf.h:1242: ошибка: expected initializer before '*' token /usr/include/pngconf.h:1243: ошибка: expected initializer before '*' token /usr/include/regexp.h: In function 'char* compile(char*, char*, const char*, int)': /usr/include/regexp.h:110: ошибка: нет декларации 'INIT' в этой области видимости /usr/include/regexp.h:115: ошибка: expected ';' before 'regex_t' /usr/include/regexp.h:127: ошибка: нет декларации 'ERROR' в этой области видимости /usr/include/regexp.h:129: ошибка: нет декларации '__expr_ptr' в этой области видимости /usr/include/regexp.h:135: ошибка: нет декларации 'GETC' в этой области видимости /usr/include/regexp.h:139: ошибка: нет декларации 'UNGETC' в этой области видимости /usr/include/regexp.h:182: ошибка: нет декларации 'RETURN' в этой области видимости /usr/include/regexp.h:197: ошибка: нет декларации 'ERROR' в этой области видимости /usr/include/regexp.h:201: ошибка: нет декларации 'RETURN' в этой области видимости /usr/include/term_entry.h:153: ошибка: переменная или поле '_nc_read_entry_source' объявлено void /usr/include/term_entry.h:153: ошибка: нет декларации 'FILE' в этой области видимости /usr/include/term_entry.h:153: ошибка: expected primary-expression before ',' token /usr/include/term_entry.h:153: ошибка: expected primary-expression before 'char' /usr/include/term_entry.h:153: ошибка: expected primary-expression before 'int' /usr/include/term_entry.h:153: ошибка: expected primary-expression before 'bool' /usr/include/term_entry.h:153: ошибка: expected primary-expression before 'bool'

Помогите решить данную проблему.

Система Linux 5.0.4 debian/lenny ядро 2.6.26-2-amd64
Версия gcc 4.4.3, скачивал полный пакет с офф сайта.

Заранее спасибо!

#5836

[console]g++ curses.c -l curses -o curses[/console]

#5847
Atragor написал:
[console]g++ curses.c -l curses -o curses[/console]

Заработало, спасибо !! ))

#6109

У меня тоже частенько (да регулярно) возникают похожие проблемы.
Не с curses, а с другими заголовками... С чем это связано?

Конечно, g++ - это решение. Но это же компилятор c++, а gcc - компилятор c, по идее gcc тоже должен уметь всё нормально компилировать? Ему какую-то опцию надо указать?

Точнее, проблема немного другая... Суть в том, что gcc компилит неправильно, а g++ правильно.
Текст сейчас привести не могу (примерной программы) - позже обязательно отпишу.
Примерно вот такие ошибки:

curses.c:(.text+0x10): undefined reference to
Войдите или зарегистрируйтесь, чтобы ответить.