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

标签 c++ xcode linker command

我一直在为这个问题绞尽脑汁。我到处搜索,我似乎发现的都是相同错误消息的问题,但涉及构建完整的 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/

相关文章:

ios - iOS 应用程序中的 Android keystore 摘要等效项是什么

c - 如何解决两个共享库之间的相互引用?

c++ - 剔除点云中的受阻点

c++ - 如何将带有冒号的输入文件读入数组?

XCode 在调用函数之前调用它?

ios - 超链接到 uitextview 中的文本部分

c++ - 链接器如何知道哪个符号链接(symbolic link)到哪个符号?

c++ - MSVC查找符号来自何处

c++ - 从输入字符串中提取数字 C++

c++ - 基类需要引用尚未构造的派生类成员