xcode 在体系结构 + 链接器命令中找不到符号失败,退出代码为 1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28225967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Symbols not found in architecture + linker command failed with exit code 1
提问by Alonso Iturbe
I have been cracking my head over this one. I've searched all over and all I seem to find are issues with the same error messages but involving either building complete iphone apps or dealing with header files, all sorts of stuff.
我一直在为这个而头疼。我已经搜索了所有我似乎发现的都是相同错误消息的问题,但涉及构建完整的 iphone 应用程序或处理头文件,各种各样的东西。
I was just writing a simple C++ program, no header files except the typical iostream, stdlib.h and time.h. This is for a very simple college assignment, but I can't keep working because Xcode gives me this error that has nothing to do with the actual code (based on what I've read). I haven't messed with anything other than the actual .cpp file, I don't even know how I could've messed this up. I've done multiple assignments the same way and have never run into this issue before.
我只是在写一个简单的 C++ 程序,除了典型的 iostream、stdlib.h 和 time.h 之外没有头文件。这是一个非常简单的大学作业,但我不能继续工作,因为 Xcode 给了我这个与实际代码无关的错误(基于我读过的内容)。除了实际的 .cpp 文件之外,我没有弄乱任何东西,我什至不知道我怎么会弄乱它。我以同样的方式完成了多项作业,以前从未遇到过这个问题。
Current code:
当前代码:
#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
错误屏幕截图
EDIT: Fixed code below.
编辑:下面的固定代码。
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";
}
}
回答by PaulMcKenzie
You failed to supply the funcion1(int, int, int)
and funcion2(int, int, int)
functions to the linker. You're calling them in your main() program, but the linker can't find it.
您未能向链接器提供funcion1(int, int, int)
和funcion2(int, int, int)
函数。您在 main() 程序中调用它们,但链接器找不到它。
And no, this does not call your funcion1(int**, int, int)
function:
不,这不会调用您的funcion1(int**, int, int)
函数:
funcion1(**matriz, renglones, columnas);
You are dereferencing the int**
on two levels, thus yielding an int
. Same thing with your call to funcion2
.
您正在int**
两个级别取消引用,从而产生int
. 与您的呼叫相同funcion2
。
To call the funcion1(**matriz, renglones, columnas)
function:
调用 funcion1(**matriz, renglones, columnas)
函数:
funcion1(matriz, renglones, columnas);
Same thing with funcion2(int **, int, int);
同样的事情 funcion2(int **, int, int);
funcion2(matriz, renglones, columnas);