gpt4 book ai didi

c++ - 在体系结构中找不到符号 + 链接器命令失败,退出代码为 1

转载 作者:行者123 更新时间:2023-11-30 02:41:19 31 4
gpt4 key购买 nike

我一直在为这个问题绞尽脑汁。我到处搜索,我似乎发现的都是相同错误消息的问题,但涉及构建完整的 iphone 应用程序或处理头文件,以及各种各样的东西。

我只是在写一个简单的 C++ 程序,除了典型的 iostream、stdlib.h 和 time.h 之外没有头文件。这是一个非常简单的大学作业,但我无法继续工作,因为 Xcode 给我这个与实际代码无关的错误(基于我读过的内容)。除了实际的 .cpp 文件,我没有弄乱任何东西,我什至不知道我怎么会把它搞砸。我以同样的方式完成了多项作业,之前从未遇到过这个问题。

当前代码:

#include <iostream>
#include <stdlib.h>
#include <time.h>


using namespace std;

//functions
void funcion1(int matriz, int renglones, int columnas);
void funcion2(int matriz, int renglones, int columnas);

//variables
int renglones=8;
int columnas=8;
int ** matriz = new int*[renglones];

int main()
{
//reservar columnas
for (int i=0; i < renglones; i++)
{
matriz[i] = new int[columnas];
}

srand(time(NULL));
funcion1(**matriz, renglones, columnas);
funcion2(**matriz, renglones, columnas);
}

void funcion1(int **matriz, int renglones, int columnas)
{
for (int y = 0; y <= renglones; y++)
{
for (int x = 0; x <= columnas; x++)
{
matriz[y][x] = rand() % 10;
}
}
}

void funcion2(int **matriz, int renglones, int columnas)
{
for (int y = 0; y <= renglones; y++)
{
for (int x = 0; x <= columnas; x++)
{
cout << matriz[y][x] << " ";
}
cout << "\n";
}
}

错误屏幕截图 Screenshot of error screen

编辑:修复了下面的代码。

void funcion1(int **matriz, int renglones, int columnas)
{
for (int y = 0; y < renglones; y++)
{
for (int x = 0; x < columnas; x++)
{
matriz[y][x] = rand() % 10;
}
}
}

void funcion2(int **matriz, int renglones, int columnas)
{
for (int y = 0; y < renglones; y++)
{
for (int x = 0; x < columnas; x++)
{
cout << matriz[y][x] << " ";
}
cout << "\n";
}
}

最佳答案

您未能向链接器提供 funcion1(int, int, int)funcion2(int, int, int) 函数。您在 main() 程序中调用它们,但链接器找不到它。

不,这不会调用您的 funcion1(int**, int, int) 函数:

funcion1(**matriz, renglones, columnas);

您在两个级别上取消引用 int**,从而产生一个 int。您对 funcion2 的调用也是如此。


要调用 funcion1(**matriz, renglones, columnas) 函数:

funcion1(matriz, renglones, columnas);

funcion2(int **, int, int); 相同

funcion2(matriz, renglones, columnas);

关于c++ - 在体系结构中找不到符号 + 链接器命令失败,退出代码为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28225967/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com