質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C

C言語は、1972年にAT&Tベル研究所の、デニス・リッチーが主体となって作成したプログラミング言語です。 B言語の後継言語として開発されたことからC言語と命名。そのため、表記法などはB言語やALGOLに近いとされています。 Cの拡張版であるC++言語とともに、現在世界中でもっとも普及されているプログラミング言語です。

Q&A

解決済

2回答

1431閲覧

C言語外部ライブラリPDCursesを使うファイルをコンパイルできない

nohahanon

総合スコア27

C

C言語は、1972年にAT&Tベル研究所の、デニス・リッチーが主体となって作成したプログラミング言語です。 B言語の後継言語として開発されたことからC言語と命名。そのため、表記法などはB言語やALGOLに近いとされています。 Cの拡張版であるC++言語とともに、現在世界中でもっとも普及されているプログラミング言語です。

0グッド

0クリップ

投稿2023/04/04 14:49

編集2023/04/05 02:00

実現したいこと

#include<curses.h>を含むcファイルをgccした際エラーを無くしたい。
(C言語の外部ライブラリPDCursesをダウンロードした後、include pathをvscodeで正常に通す。
そのうえでライブラリに付随するdemoフォルダ内のrain.cを実行する。)

前提

tetrisをc言語で書こうとしています。ミノをどんな入力関数を用いて操作するかという問題の解決策を探していたところ、PDCurseというライブラリを発見しました。(windows向けのcursesらしいです。https://qiita.com/pokohide/items/a246045f3ccaf540a375 のようなブロック崩しゲームを作れているので応用できると考えました。)
しかし、https://github.com/wmcbrine/PDCurses をダウンロードしwindows向けビルド方法の書かれたreadmeの通りにwinconフォルダ内でmingw32-make -f Makefileを実行しました。C:\pg\PDCurses-masterでtreeを実行した結果が以下の通りです。

C:.
│ CNAME
│ curses.h
│ curspriv.h
│ memo.txt
│ panel.h
│ README.md

├─common
│ acs437.h
│ acsgr.h
│ acsuni.h
│ borland.lrf
│ font437.h
│ icon32.xpm
│ icon64.xpm
│ iconbmp.h
│ libobjs.mif
│ pdcurses.rc
│ README.md
│ watcom.mif

├─demos
│ │ firework.c
│ │ nctests.mif
│ │ ncurses_cfg.h
│ │ ozdemo.c
│ │ ptest.c
│ │ rain.c
│ │ README.md
│ │ testcurs.c
│ │ tui.c
│ │ tui.h
│ │ tuidemo.c
│ │ UTF-8-demo.txt
│ │ worm.c
│ │ xmas.c
│ │
│ └─.vscode
│ c_cpp_properties.json

├─docs
│ HISTORY.md
│ IMPLEMNT.md
│ manext.awk
│ MANUAL.md
│ mkman.sh
│ README.md
│ USERS.md

├─dos
│ Makefile
│ Makefile.bcc
│ Makefile.wcc
│ pdcclip.c
│ pdcdisp.c
│ pdcdos.h
│ pdcgetsc.c
│ pdckbd.c
│ pdcscrn.c
│ pdcsetsc.c
│ pdcutil.c
│ README.md

├─os2
│ Makefile
│ Makefile.bcc
│ Makefile.wcc
│ pdcclip.c
│ pdcdisp.c
│ pdcgetsc.c
│ pdckbd.c
│ pdcos2.h
│ pdcscrn.c
│ pdcsetsc.c
│ pdcutil.c
│ README.md

├─pdcurses
│ addch.c
│ addchstr.c
│ addstr.c
│ attr.c
│ beep.c
│ bkgd.c
│ border.c
│ clear.c
│ color.c
│ debug.c
│ delch.c
│ deleteln.c
│ getch.c
│ getstr.c
│ getyx.c
│ inch.c
│ inchstr.c
│ initscr.c
│ inopts.c
│ insch.c
│ insstr.c
│ instr.c
│ kernel.c
│ keyname.c
│ mouse.c
│ move.c
│ outopts.c
│ overlay.c
│ pad.c
│ panel.c
│ printw.c
│ README.md
│ refresh.c
│ scanw.c
│ scroll.c
│ scr_dump.c
│ slk.c
│ termattr.c
│ touch.c
│ util.c
│ window.c

├─sdl1
│ Makefile
│ pdcclip.c
│ pdcdisp.c
│ pdcgetsc.c
│ pdckbd.c
│ pdcscrn.c
│ pdcsdl.h
│ pdcsetsc.c
│ pdcutil.c
│ README.md
│ sdltest.c

├─sdl2
│ Makefile
│ Makefile.vc
│ pdcclip.c
│ pdcdisp.c
│ pdcgetsc.c
│ pdckbd.c
│ pdcscrn.c
│ pdcsdl.h
│ pdcsetsc.c
│ pdcutil.c
│ README.md
│ sdltest.c
│ versions.mif

├─wincon
│ addch.o
│ addchstr.o
│ addstr.o
│ attr.o
│ beep.o
│ bkgd.o
│ border.o
│ clear.o
│ color.o
│ debug.o
│ delch.o
│ deleteln.o
│ getch.o
│ getstr.o
│ getyx.o
│ inch.o
│ inchstr.o
│ initscr.o
│ inopts.o
│ insch.o
│ insstr.o
│ instr.o
│ kernel.o
│ keyname.o
│ Makefile
│ Makefile.bcc
│ Makefile.vc
│ Makefile.wcc
│ mouse.o
│ move.o
│ outopts.o
│ overlay.o
│ pad.o
│ panel.o
│ pdcclip.c
│ pdcclip.o
│ pdcdisp.c
│ pdcdisp.o
│ pdcgetsc.c
│ pdcgetsc.o
│ pdckbd.c
│ pdckbd.o
│ pdcscrn.c
│ pdcscrn.o
│ pdcsetsc.c
│ pdcsetsc.o
│ pdcurses.a
│ pdcurses.dll
│ pdcurses.o
│ pdcutil.c
│ pdcutil.o
│ pdcwin.h
│ printw.o
│ README.md
│ refresh.o
│ scanw.o
│ scroll.o
│ scr_dump.o
│ slk.o
│ termattr.o
│ touch.o
│ util.o
│ window.o

└─x11
aclocal.m4
config.guess
config.h.in
config.sub
configure
configure.ac
install-sh
Makefile.in
pdcclip.c
pdcdisp.c
pdcgetsc.c
pdckbd.c
pdcscrn.c
pdcsetsc.c
pdcutil.c
pdcx11.h
README.md
sb.c
scrlbox.c
scrlbox.h
xcurses-config.in

発生している問題・エラーメッセージ

vscodeの#include<curses.h>に以下のメッセージが表示されます。

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\pg\PDCurses-master\demos\rain.c).C/C++(1696)

gccを実行した際以下のメッセージが表示されます。

PS C:\pg\PDCurses-master\demos> gcc -orain rain.c -lcurses rain.c:29:10: fatal error: curses.h: No such file or directory 29 | #include <curses.h> | ^~~~~~~~~~ compilation terminated. PS C:\pg\PDCurses-master\demos> gcc rain.c rain.c:29:10: fatal error: curses.h: No such file or directory 29 | #include <curses.h> | ^~~~~~~~~~ compilation terminated.

試したこと

Microsoft C/C++ Extensionという拡張機能にあるInclude pathという設定を編集してみました。
一番最初は
${workspaceFolder}/**
という記述があるのみなのですが
${workspaceFolder}/**
C:\pg\PDCurses-master
と追加してみるとエディタ上の赤波が消えます。しかしgccでの上記のようなエラーは出続けます。

補足情報(FW/ツールのバージョンなど)

gcc version 12.2.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)

自動生成されているc_cpp_properties.jsonは以下の通りです。

json

1{ 2 "configurations": [ 3 { 4 "name": "Win32", 5 "includePath": [ 6 "${workspaceFolder}/**", 7 "C:\\pg\\PDCurses-master" 8 ], 9 "defines": [ 10 "_DEBUG", 11 "UNICODE", 12 "_UNICODE" 13 ], 14 "compilerPath": "C:\\pg\\mingw64\\bin\\gcc.exe", 15 "cStandard": "c17", 16 "cppStandard": "gnu++17", 17 "intelliSenseMode": "windows-gcc-x64" 18 } 19 ], 20 "version": 4 21}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

んでも一つの方法を。

#include "../curses.h"

でどうでしょう

ソースファイルから見たヘッダファイルの相対パスを書いとけばいいです
インクルードパスの編集は必要ありません

投稿2023/04/04 22:17

編集2023/04/04 22:27
y_waiwai

総合スコア87749

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

nohahanon

2023/04/05 00:34

回答ありがとうございます。以下のようなログが返りました。 PS C:\pg\PDCurses-master\demos> gcc rain.c C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x41): undefined reference to `has_colors' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x92): undefined reference to `attrset' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0xb4): undefined reference to `initscr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0xd2): undefined reference to `has_colors' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0xe1): undefined reference to `start_color' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0xe6): undefined reference to `use_default_colors' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x106): undefined reference to `init_pair' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x11c): undefined reference to `init_pair' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x121): undefined reference to `nl' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x126): undefined reference to `noecho' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x130): undefined reference to `curs_set' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x13a): undefined reference to `timeout' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x151): undefined reference to `keypad' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x208): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x243): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x28b): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x2d6): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x315): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x353): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x39e): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x3e0): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x41f): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x461): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x49f): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x4ea): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x52c): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x56b): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x5ad): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x5eb): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x631): undefined reference to `wgetch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x66f): undefined reference to `curs_set' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x674): undefined reference to `endwin' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x692): undefined reference to `nodelay' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x6ab): undefined reference to `nodelay' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x6bc): undefined reference to `resize_term' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.text+0x6e4): undefined reference to `napms' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.rdata$.refptr.COLS[.refptr.COLS]+0x0): undefined reference to `COLS' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.rdata$.refptr.LINES[.refptr.LINES]+0x0): undefined reference to `LINES' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccqZZbYa.o:rain.c:(.rdata$.refptr.stdscr[.refptr.stdscr]+0x0): undefined reference to `stdscr' collect2.exe: error: ld returned 1 exit status PS C:\pg\PDCurses-master\demos> gcc -IC:\pg\PDCurses-master -LC:\pg\PDCurses-master\wincon rain.c を実行しても同様でした。 そもそものビルドがうまくできていなかったということでしょうか??
y_waiwai

2023/04/05 01:27

それは、includeが解決したがために、他のエラーが検出されるようになった、ってことで、また別の問題です undefined reference to `なんたら' ってのは、なんたら、と言うのが定義されていない、ってエラーですな。 そもそも、コンパイルのやり方が間違ってるかと思います。 ビルド法ってのをよく確認しよう。
guest

0

ベストアンサー

gccのコマンドを直接実行するのでしたら、VSCode の設定である c_cpp_properties.json は無関係です。
gcc -IC:\pg\PDCurses-master -LC:\pg\PDCurses-master\wincon ... のように -I-L を指定する必要があります。

VSCode の機能でビルドできるようにするなら、tasks.json の設定が必要です。

投稿2023/04/04 21:39

int32_t

総合スコア20845

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

nohahanon

2023/04/05 00:30

回答ありがとうございます。 ``` PS C:\pg\PDCurses-master\demos> gcc -IC:\pg\PDCurses-master -LC:\pg\PDCurses-master\wincon rain.c C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x41): undefined reference to `has_colors' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x92): undefined reference to `attrset' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0xb4): undefined reference to `initscr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0xd2): undefined reference to `has_colors' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0xe1): undefined reference to `start_color' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0xe6): undefined reference to `use_default_colors' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x106): undefined reference to `init_pair' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x11c): undefined reference to `init_pair' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x121): undefined reference to `nl' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x126): undefined reference to `noecho' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x130): undefined reference to `curs_set' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x13a): undefined reference to `timeout' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x151): undefined reference to `keypad' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x208): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x243): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x28b): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x2d6): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x315): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x353): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x39e): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x3e0): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x41f): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x461): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x49f): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x4ea): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x52c): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x56b): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x5ad): undefined reference to `mvaddstr' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x5eb): undefined reference to `mvaddch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x631): undefined reference to `wgetch' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x66f): undefined reference to `curs_set' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x674): undefined reference to `endwin' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x692): undefined reference to `nodelay' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x6ab): undefined reference to `nodelay' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x6bc): undefined reference to `resize_term' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.text+0x6e4): undefined reference to `napms' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.rdata$.refptr.COLS[.refptr.COLS]+0x0): undefined reference to `COLS' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.rdata$.refptr.LINES[.refptr.LINES]+0x0): undefined reference to `LINES' C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.rdata$.refptr.stdscr[.refptr.stdscr]+0x0): undefined reference to `stdscr' collect2.exe: error: ld returned 1 exit status ``` というメッセージが返りました。rain.cのヘッダファイル部分を#include<curses.h>にしても"../curses.h"にしても同じ内容が返りました。おそらくリンクが正常に実行されていないということで、``` C:/pg/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\haihu\AppData\Local\Temp\ccsQjwQO.o:rain.c:(.rdata$.refptr.stdscr[.refptr.stdscr]+0x0): undefined reference to `stdscr' ``` を挙げるとstdsct.oがいつもオブジェクトファイルを探しに行く場所にもC:\pg\PDCurses-master\winconにもいない、ということでしょうか?
int32_t

2023/04/05 00:38

pdcurses.a をコマンドラインに指定する必要があります。MinGW は特殊なのでどう指定するのかよく知りませんが、「gcc ... rain.c -lpdcurses」か 「gcc ... rain.c C:\pg\PDCurses-master\wincon\pdcurses.a」とかだと思います。
nohahanon

2023/04/05 01:00 編集

PS C:\pg\PDCurses-master\demos> gcc -IC:\pg\PDCurses-master -LC:\pg\PDCurses-master\wincon ptest.c -lpdcurses でgcc成功しました! ただ、その後./a.exeしたところ何も返ることなくエラー終了します。main()の頭にprintf("a");をおいても何も起こりませんでした。 PS C:\pg\PDCurses-master\demos> gcc -IC:\pg\PDCurses-master -LC:\pg\PDCurses-master\wincon rain.c -lpdcurses PS C:\pg\PDCurses-master\demos> ./a.exe PS C:\pg\PDCurses-master\demos> ```c #include <curses.h> #include <stdlib.h> #include <time.h> /* rain 1980-11-03 EPS/CITHEP */ static int next_j(int j) { if (j == 0) j = 4; else --j; if (has_colors()) { int z = rand() % 3; chtype color = COLOR_PAIR(z); if (z) color |= A_BOLD; attrset(color); } return j; } int main(int argc, char *argv[]) { printf("a"); time_t seed; int x, y, j, r, c; static int xpos[5], ypos[5]; #ifdef XCURSES Xinitscr(argc, argv); #else initscr(); #endif seed = time((time_t *)0); srand(seed); if (has_colors()) { short bg = COLOR_BLACK; start_color(); #if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000) if (use_default_colors() == OK) bg = -1; #endif init_pair(1, COLOR_BLUE, bg); init_pair(2, COLOR_CYAN, bg); } nl(); noecho(); curs_set(0); timeout(0); keypad(stdscr, TRUE); r = LINES - 4; c = COLS - 4; for (j = 5; --j >= 0;) { xpos[j] = rand() % c + 2; ypos[j] = rand() % r + 2; } for (j = 0;;) { x = rand() % c + 2; y = rand() % r + 2; mvaddch(y, x, '.'); mvaddch(ypos[j], xpos[j], 'o'); j = next_j(j); mvaddch(ypos[j], xpos[j], 'O'); j = next_j(j); mvaddch(ypos[j] - 1, xpos[j], '-'); mvaddstr(ypos[j], xpos[j] - 1, "|.|"); mvaddch(ypos[j] + 1, xpos[j], '-'); j = next_j(j); mvaddch(ypos[j] - 2, xpos[j], '-'); mvaddstr(ypos[j] - 1, xpos[j] - 1, "/ \\"); mvaddstr(ypos[j], xpos[j] - 2, "| O |"); mvaddstr(ypos[j] + 1, xpos[j] - 1, "\\ /"); mvaddch(ypos[j] + 2, xpos[j], '-'); j = next_j(j); mvaddch(ypos[j] - 2, xpos[j], ' '); mvaddstr(ypos[j] - 1, xpos[j] - 1, " "); mvaddstr(ypos[j], xpos[j] - 2, " "); mvaddstr(ypos[j] + 1, xpos[j] - 1, " "); mvaddch(ypos[j] + 2, xpos[j], ' '); xpos[j] = x; ypos[j] = y; switch (getch()) { case 'q': case 'Q': curs_set(1); endwin(); return EXIT_SUCCESS; case 's': nodelay(stdscr, FALSE); break; case ' ': nodelay(stdscr, TRUE); #ifdef KEY_RESIZE break; case KEY_RESIZE: # ifdef PDCURSES resize_term(0, 0); # endif r = LINES - 4; c = COLS - 4; #endif } napms(50); } } ``` rain.c
int32_t

2023/04/05 01:10

コンパイルができたのでしたらこの質問は解決済みにして、動作に関しては別の質問を立てるべきかと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問