c++ - 我使用带有 m1 芯片的 Mac(我使用 Clion)并且我遇到了一个问题:链接器命令失败,退出代码为 1(使用 -v 查看调用)
问题描述
我使用狮子,我正在尝试制作蛇游戏,但现在我不知道该怎么做,因为我在互联网上找不到我的代码的答案:
#include<iostream>
#include <ncurses.h>// for snake game
using namespace std;
bool gameOver;
const int width = 20;
const int height = 20;
int x, y, fruitX, fruitY, score;
enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN};
eDirection dir;
int kbhit(void)
{
int ch = getch();
if (ch != ERR) {
ungetch(ch);
return 1;
} else {
return 0;
}
}
void Setup()
{
gameOver = false;
dir = STOP;
x = width/2;
y = height/2;
fruitX = rand() % width;
fruitY = rand() % height;
score = 0;
}
void Draw()
{
system("clear");
for (int i = 0; i < width + 1; ++i) {
cout<<"#";
}
cout<<endl;
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
if(j == 0){
cout<<"#";
}
if(i == y && j == x )
cout<<"O";
else if (i == fruitY && j == fruitX)
cout<<"F";
else{
cout<<" ";
}
if (j == width-1)
cout<<"#";
}
cout<<endl;
}
for (int i = 0; i < width + 1; ++i) {
cout<<"#";
}
cout<<endl;
}
void Input()
{
if(kbhit())
{
switch (getch()) {
case 'a':
{
dir = LEFT;
break;
}
case 'd':
{
dir = RIGHT;
break;
}
case 'w':
{
dir = UP;
break;
}
case 's':
{
dir = DOWN ;
break;
}
case 'x':
{
gameOver = true ;
break;
}
}
}
}
void Logic()
{
switch (dir)
{
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
case UP:
y++;
break;
case DOWN:
y--;
break;
default:
break;
}
}
int main() {
Setup();
while(!gameOver)
{
Draw();
Input();
Logic();
}
return 0;
}
这是错误:
Undefined symbols for architecture arm64:
"_stdscr", referenced from:
kbhit() in main.cpp.o
Input() in main.cpp.o
"_ungetch", referenced from:
kbhit() in main.cpp.o
"_wgetch", referenced from:
kbhit() in main.cpp.o
Input() in main.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [training] Error 1
make[2]: *** [CMakeFiles/training.dir/all] Error 2
make[1]: *** [CMakeFiles/training.dir/rule] Error 2
make: *** [training] Error 2
如果你能帮助我,我将不胜感激
也许是因为我尝试使用 kbhit 功能,因为我不知道如何将舒适更改为 ncurses。如果你也能帮忙就好了
解决方案
推荐阅读
- reactjs - Nivo 散点图如何显示每个绘制点的标签
- python - 如何在同一实例中刷新 Plotly 图表
- reactjs - 在 Axios 中,如何捕获网络选项卡报告的响应错误正文?
- github-pages - 访问 Github Pages 上的文件夹时出现问题
- azure - 为什么这个 powershell 命令显示所有邮箱而不是一些?
- multithreading - 如何在不同线程中从磁盘加载 Unity 中的图像?
- python - 多面 px.line 图中 y 轴的大小不起作用
- gcloud - 当我第一次部署 Cloud Run 服务时,设置服务区域、基础镜像和连接的 Cloud SQL 实例:它显示错误
- python - 在 numpy n 维内部数组上选择并应用条件
- c# - 在运行时修改 WPF 资源,其中资源在共享 dll 的资源字典中定义