ld:未找到架构 x86_64 的符号

2024-02-25

并感谢您提前提供的所有帮助。我是 C/C++ 新手,正在通过深入学习来自学。我正在尝试编写一个共享(静态?不确定区别)库并编写一个简单的程序来使用该库。我可能没有以最有效的方式做这件事(如果是Python,我一周前就完成了这个项目),但我更关心的是知道我做错了什么以及为什么做错了。再次感谢大家的帮助:

LinAlg.h

//// PROTECT HEADER
#pragma once


//// IMPORT LIBRARIES
// standard modules
#include <exception>
// custom modules



//// DEFINE OBJECT
namespace LinAlg
{
    class ktaArr
    {
    public:
        // INIT
        ktaArr(int w, int h);
        ktaArr(int w, int h, double val);
        // SETTERS
        void SetValue(int row, int col, double val);
        // GETTERS
        int GetWidth();
        int GetHeight();
        double GetValue(int row, int col);
        // METHODS
        ktaArr dot(ktaArr arr2);
        void Display();
        // OPPERATORS
        ktaArr operator=(ktaArr arr2);
        ktaArr operator+(ktaArr arr2);
        ktaArr operator-(ktaArr arr2);
        ktaArr operator*(ktaArr arr2);
        ktaArr operator/(ktaArr arr2);
        // RELATIONS
        bool operator==(ktaArr arr2);
        bool operator<=(ktaArr arr2);
        bool operator>=(ktaArr arr2);
        bool operator!=(ktaArr arr2);
        // DECONSTRUCTOR
        ~ktaArr()
        {
            for(int i = 0; i < h; i++)
            {
                delete arr[i];
            }
        };

    protected:
        int w, h;
        double** arr;

    private:


    };
}

//// DEFINE EXCEPTION
namespace LinAlg
{
    class IllegalArraySize: public std::exception {
    private:
        virtual const char* what() const throw()
        {
            return "Invalid use: array sizes do not match.";
        }
    };
}

LinAlg.cpp

//// IMPORT LIBRARIES
// standard modules
#include <iostream>
// custom modules
#include "LinAlg.h"


///////////////////////////////////////////////////////////////////////////////
// INIT

LinAlg::ktaArr::ktaArr(int h, int w)
{
    LinAlg::ktaArr::w = w;
    LinAlg::ktaArr::h = h;
//  LinAlg::ktaArr::arr = new double[LinAlg::ktaArr::h][LinAlg::ktaArr::w];
    LinAlg::ktaArr::arr = new double*[LinAlg::ktaArr::h];
    for (int col = 0; col < LinAlg::ktaArr::w; col++)
    {
        LinAlg::ktaArr::arr[col] = new double[LinAlg::ktaArr::w];
    }
}

LinAlg::ktaArr::ktaArr(int h, int w, double val)
{
    LinAlg::ktaArr::w = w;
    LinAlg::ktaArr::h = h;
//  LinAlg::ktaArr::arr = new double[LinAlg::ktaArr::h][LinAlg::ktaArr::w];
    LinAlg::ktaArr::arr = new double*[LinAlg::ktaArr::h];
    for (int col = 0; col < LinAlg::ktaArr::w; col++)
    {
        LinAlg::ktaArr::arr[col] = new double[LinAlg::ktaArr::w];
    }

    //iterate over array and set values to val
    for (int row = 0; row < LinAlg::ktaArr::h; row++)
    {
        for (int col = 0; col < LinAlg::ktaArr::w; col++)
        {
            LinAlg::ktaArr::arr[row][col] = val;
        }
    }
}

// INIT
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// SETTERS

void LinAlg::ktaArr::SetValue(int row, int col, double val)
{
    if ((row+1 > LinAlg::ktaArr::h) || (col+1 > LinAlg::ktaArr::w))
    {
        throw LinAlg::IllegalArraySize();
    }
    LinAlg::ktaArr::arr[row][col] = val;
}

// SETTERS
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// GETTERS

int LinAlg::ktaArr::GetWidth()
{
    return LinAlg::ktaArr::w;
}

int LinAlg::ktaArr::GetHeight()
{
    return LinAlg::ktaArr::h;
}

double LinAlg::ktaArr::GetValue(int row, int col)
{
    return LinAlg::ktaArr::arr[row][col];
}

// GETTERS
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// METHODS

LinAlg::ktaArr LinAlg::ktaArr::dot(LinAlg::ktaArr arr2)
{
    // Check size of arrays first
    if (LinAlg::ktaArr::h != arr2.GetHeight())
    {
        throw LinAlg::IllegalArraySize();
    }

    // Create new array
    LinAlg::ktaArr arrNew(LinAlg::ktaArr::h, arr2.GetWidth());
    // Assign each value
    double value;
    for (int row = 0; row < arrNew.GetHeight(); row++)
    {
        for (int col = 0; col < arrNew.GetWidth(); col++)
        {
            value = 0;
            // Perform multiplication
            for (int el = 0; el < w; el++)
            {
                value += LinAlg::ktaArr::arr[row][el] *
                         arr2.GetValue(el, col);
            }
            arrNew.SetValue(row, col, value);
        }
    }

    return arrNew;
}

void LinAlg::ktaArr::Display()
{
    for (int row = 0; row < LinAlg::ktaArr::h; row++)
    {
        for (int col = 0; col < LinAlg::ktaArr::w; col++)
        {
            if ((row == 0) && (col == 0))
            {
                // first element
                std::cout << "[[" << LinAlg::ktaArr::arr[row][col];
            }
            else if ((row == LinAlg::ktaArr::h-1) &&
                     (col == LinAlg::ktaArr::w-1))
            {
                // last element
                std::cout << ", " << LinAlg::ktaArr::arr[row][col]
                          << "]]" << std::endl;
            }
            else if ((row != 0) && (col == 0))
            {
                // first element of row
                std::cout << " [" << LinAlg::ktaArr::arr[row][col];
            }
            else if ((row != LinAlg::ktaArr::h-1) &&
                     (col == LinAlg::ktaArr::w-1))
            {
                // last element of row
                std::cout << ", " << LinAlg::ktaArr::arr[row][col]
                          << "]" << std::endl;
            }
            else
            {
                // print out value
                std::cout << ", " << LinAlg::ktaArr::arr[row][col];
            }
        }
    }
}

// METHODS
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// OPPERATORS

LinAlg::ktaArr LinAlg::ktaArr::operator=(LinAlg::ktaArr arr2)
{
    LinAlg::ktaArr newArr = LinAlg::ktaArr(arr2.GetHeight(),
                           arr2.GetWidth());
    for(int row = 0; row < arr2.GetHeight(); row++)
    {
        for(int col = 0; col < arr2.GetWidth(); col++)
        {
            newArr.SetValue(row, col, arr2.GetValue(row,col));
        }
    }
    return newArr;
}

LinAlg::ktaArr LinAlg::ktaArr::operator+(LinAlg::ktaArr arr2)
{
    if ((LinAlg::ktaArr::h != arr2.GetHeight()) ||
        (LinAlg::ktaArr::w != arr2.GetWidth()))
    {
        throw LinAlg::IllegalArraySize();
    }
    LinAlg::ktaArr newArr = LinAlg::ktaArr(arr2.GetHeight(),
                           arr2.GetWidth());
    for(int row = 0; row < arr2.GetHeight(); row++)
    {
        for(int col = 0; col < arr2.GetWidth(); col++)
        {
            newArr.SetValue(row, col,
                            LinAlg::ktaArr::arr[row][col]
                                + arr2.GetValue(row,col));
        }
    }
    return newArr;
}

LinAlg::ktaArr LinAlg::ktaArr::operator-(LinAlg::ktaArr arr2)
{
    if ((LinAlg::ktaArr::h != arr2.GetHeight()) ||
        (LinAlg::ktaArr::w != arr2.GetWidth()))
    {
        throw LinAlg::IllegalArraySize();
    }
    LinAlg::ktaArr newArr = LinAlg::ktaArr(arr2.GetHeight(),
                           arr2.GetWidth());
    for(int row = 0; row < arr2.GetHeight(); row++)
    {
        for(int col = 0; col < arr2.GetWidth(); col++)
        {
            newArr.SetValue(row, col,
                            LinAlg::ktaArr::arr[row][col]
                                - arr2.GetValue(row,col));
        }
    }
    return newArr;
}

LinAlg::ktaArr LinAlg::ktaArr::operator*(LinAlg::ktaArr arr2)
{
    if ((LinAlg::ktaArr::h != arr2.GetHeight()) ||
        (LinAlg::ktaArr::w != arr2.GetWidth()))
    {
        throw LinAlg::IllegalArraySize();
    }
    LinAlg::ktaArr newArr = LinAlg::ktaArr(arr2.GetHeight(),
                           arr2.GetWidth());
    for(int row = 0; row < arr2.GetHeight(); row++)
    {
        for(int col = 0; col < arr2.GetWidth(); col++)
        {
            newArr.SetValue(row, col,
                            LinAlg::ktaArr::arr[row][col]
                                * arr2.GetValue(row,col));
        }
    }
    return newArr;
}

LinAlg::ktaArr LinAlg::ktaArr::operator/(LinAlg::ktaArr arr2)
{
    if ((LinAlg::ktaArr::h != arr2.GetHeight()) ||
        (LinAlg::ktaArr::w != arr2.GetWidth()))
    {
        throw LinAlg::IllegalArraySize();
    }
    LinAlg::ktaArr newArr = LinAlg::ktaArr(arr2.GetHeight(),
                           arr2.GetWidth());
    for(int row = 0; row < arr2.GetHeight(); row++)
    {
        for(int col = 0; col < arr2.GetWidth(); col++)
        {
            newArr.SetValue(row, col,
                            LinAlg::ktaArr::arr[row][col]
                                / arr2.GetValue(row,col));
        }
    }
    return newArr;
}

// OPPERATORS
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// RELEATIONS

bool LinAlg::ktaArr::operator==(LinAlg::ktaArr arr2)
{
    if ((LinAlg::ktaArr::h != arr2.GetHeight()) ||
        (LinAlg::ktaArr::w != arr2.GetWidth()))
    {
        throw LinAlg::IllegalArraySize();
    }
    for(int row = 0; row < arr2.GetHeight(); row++)
    {
        for(int col = 0; col < arr2.GetWidth(); col++)
        {
            if (LinAlg::ktaArr::arr[row][col] != arr2.GetValue(row, col))
            {
                return false;
            }
        }
    }
    return true;
}

bool LinAlg::ktaArr::operator<=(LinAlg::ktaArr arr2)
{
    if ((LinAlg::ktaArr::h != arr2.GetHeight()) ||
        (LinAlg::ktaArr::w != arr2.GetWidth()))
    {
        throw LinAlg::IllegalArraySize();
    }
    for(int row = 0; row < arr2.GetHeight(); row++)
    {
        for(int col = 0; col < arr2.GetWidth(); col++)
        {
            if (LinAlg::ktaArr::arr[row][col] >= arr2.GetValue(row, col))
            {
                return false;
            }
        }
    }
    return true;
}

bool LinAlg::ktaArr::operator>=(LinAlg::ktaArr arr2)
{
    if ((LinAlg::ktaArr::h != arr2.GetHeight()) ||
        (LinAlg::ktaArr::w != arr2.GetWidth()))
    {
        throw LinAlg::IllegalArraySize();
    }
    for(int row = 0; row < arr2.GetHeight(); row++)
    {
        for(int col = 0; col < arr2.GetWidth(); col++)
        {
            if (LinAlg::ktaArr::arr[row][col] <= arr2.GetValue(row, col))
            {
                return false;
            }
        }
    }
    return true;
}

bool LinAlg::ktaArr::operator!=(LinAlg::ktaArr arr2)
{
    if ((LinAlg::ktaArr::h != arr2.GetHeight()) ||
        (LinAlg::ktaArr::w != arr2.GetWidth()))
    {
        throw LinAlg::IllegalArraySize();
    }
    for(int row = 0; row < arr2.GetHeight(); row++)
    {
        for(int col = 0; col < arr2.GetWidth(); col++)
        {
            if (LinAlg::ktaArr::arr[row][col] == arr2.GetValue(row, col))
            {
                return false;
            }
        }
    }
    return true;
}

// RELATIONS
///////////////////////////////////////////////////////////////////////////////

main.cpp

//// IMPORT LIBRARIES
// standard modules
#include <iostream>
// custom modules
#include "../LinAlgLib/LinAlg.h"

int main()
{
    LinAlg::ktaArr identity (3,3,0.0);
    std::cout << "Display 3x3 zeros array:" << std::endl;
    identity.Display();
    std::cout << "test" << std::endl;
    return 0;
}

一切都是在Mac OSX 10.9上完成的,使用GCC如下:

LinAlg库

make all 
Building file: ../LinAlg.cpp
Invoking: Cross G++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"LinAlg.d" -MT"LinAlg.d" -o "LinAlg.o" "../LinAlg.cpp"
Finished building: ../LinAlg.cpp

Building target: libLinAlg.so
Invoking: Cross G++ Linker
g++ -shared -o "libLinAlg.so"  ./LinAlg.o   
Finished building target: libLinAlg.so

测试应用程序(main.cpp):

make all 
Building file: ../main.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp

Building target: testKyleLinAlg
Invoking: Cross G++ Linker
g++  -o "testKyleLinAlg"  ./main.o   
Undefined symbols for architecture x86_64:
  "LinAlg::ktaArr::ktaArr(int, int, double)", referenced from:
      _main in main.o
  "LinAlg::ktaArr::Display()", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [testKyleLinAlg] Error 1

再次感谢您的任何/所有帮助。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ld:未找到架构 x86_64 的符号 的相关文章

随机推荐

  • FCM 安全警报

    安全警报 您的应用包含公开的 Google Cloud Platform GCP API 密钥 请看这个Google 帮助中心文章 https support google com faqs answer 9287711了解详情 我在 Go
  • Java:从方法调用返回两个整数

    我在处理大量二维坐标的代码中经常这样做 int getSize int res gridRows gridColumns return res 我知道我可以定义一个小类并获得类型安全 但我没有这样做 因为在它自己的小琐碎 java 文件中拥
  • C 多个单行声明

    当我在一行上声明多个变量时会发生什么 例如 int x y z 全部都是整数 问题是下面语句中的 y 和 z 是什么 int x y z 都是int指针吗 Only x是一个指向 int 的指针 y and z是常规整数 这是 C 声明语法
  • 停止系统中的所有参与者而不关闭系统本身?

    在Akka 2 0中 有没有一个好的方法来关闭 user路径下的所有actor 例如 假设我执行以下操作 val system ActorSystem create mySystem system actorOf Props new MyA
  • 对 UIView 的 CoreGraphics/drawRect 内容进行动画处理

    是否可以制作动画UIView的 CoreGraphics 内容 说我有一个UIView子类称为MyView实现了drawRect 像这样的方法 void drawRect CGRect rect CGContextRef c UIGraph
  • 如何将 Google 图表集成为 AngularJs 指令?

    有一些将 Google 图表集成为 AngularJs 指令的示例 像这个 http plnkr co edit YzwjuU p preview http plnkr co edit YzwjuU p preview Update 我想避
  • 为什么我的代码没有向标准输出打印任何内容? [关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 我正在尝试计算学生的平均分 impo
  • 如何获取角度形式数组中更改项目的索引

    我正在使用带有反应形式的 Angular 4 我有一个表单数组 我试图将其绑定到我在组件中跟踪的数组 我使用反应式表单 这样我就可以进行验证 所以我不想使用模板表单方法 我将项目添加到表单数组中 如下所示 createFormWithMod
  • 有没有办法用静态 OpenSSL 构建静态 Qt?

    原始问题略有不同 但属于更主要问题的一部分 我正在尝试在 Windows 上使用静态 OpenSSL 将 Qt 5 2 构建为静态 我的最终目标是发送单个二进制文件无需提供 libeay32 dll 和 ssleay32 dll 然而 在我
  • 角度异步等待中的单元测试位置

    我使用 Angular 9 与 karma 测试运行器和 jasmine 测试框架进行单元测试 我只想进行单元测试app component其中有一个依赖注入 app component ts import Component Embedd
  • HTML5 Canvas - 用图像填充圆圈

    如何在圆内绘制图像 如果我做 context beginPath context arc e pageX e pageY 161 0 Math PI 2 true context closePath 然后我如何使用 fill 用我绘制的图像
  • 为组合 ggplots 添加通用图例

    我有两个水平对齐的 ggplotsgrid arrange 我浏览了很多论坛帖子 但我尝试的所有命令似乎现在都已更新并命名为其他名称 我的数据如下所示 Data plot 1 axis1 axis2 group1 0 212201 0 35
  • Django:找出菜单中已选择的项目

    我确信我以前在 Stack Overflow 上见过这个问题 但我找不到它 所以这里什么也没有 我有一个普通的 Django 菜单 它使用 url 菜单项的标签和静态名称 现在我想为已选择的菜单项设置不同的样式 但是菜单是在基本模板中渲染的
  • Objective-C HashMap 等效项

    我正在尝试转换一段使用 HashMap 的 Java 代码 其中包含一个对象作为键 一个对象包含一个值 private static HashMap
  • zfcuser 注册后添加用户角色

    我使用 Zend Framework 2 以及 ZfcUser BjyAuthorize 和 Doctrine 作为数据库 到目前为止 注册等工作进展顺利 我的问题是 注册用户没有分配角色 所以我想在注册过程中向用户添加角色 用户 我想我可
  • 如何在 Windows 上禁用调试断言对话框?

    我有一堆以批处理模式运行的单元测试 有时 Visual C 库发出的调试断言会导致崩溃 这会弹出一个对话框 并且单元测试停止运行 直到我单击 确定 关闭对话框 如何让 C 程序在遇到断言时崩溃 就像在 Linux 上一样 而不是弹出烦人的对
  • Angular Elements - 未捕获类型错误:无法构造“HTMLElement”

    我一直在尝试让 Angular 元素组件正常工作 因为我正在考虑在即将到来的项目中使用它们 我已经遵循了许多教程 都非常相似 但无法让它们工作 其中一个教程是this one https www techiediaries com angu
  • tomcat后台线程

    我有一个正在运行的 tomcat 6 20 实例 并且想通过后台线程发送电子邮件以防止电子邮件发送功能阻止请求 有什么方法可以在后台执行线程 同时仍然允许正常的页面流发生 该应用程序是用 ICEfaces 编写的 Thanks 创建一个Ex
  • Maven Mojo 映射复杂对象

    我正在尝试编写一个 Maven 插件 包括 mvn 配置参数中自定义类的映射 有谁知道等效的 Person 类会是什么样子 http maven apache org guides mini guide configuring plugin
  • ld:未找到架构 x86_64 的符号

    并感谢您提前提供的所有帮助 我是 C C 新手 正在通过深入学习来自学 我正在尝试编写一个共享 静态 不确定区别 库并编写一个简单的程序来使用该库 我可能没有以最有效的方式做这件事 如果是Python 我一周前就完成了这个项目 但我更关心的