lundi 4 novembre 2019

How to fix 'd: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)'?

I am trying to compile a test bench for my little C++ program but I cannot build it. I always get the following error:

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

when I use -v I get this:

clang -cc1 version 11.0.0 (clang-1100.0.33.12) default target x86_64-apple-darwin19.0.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
 /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.

I tried to install xcode and also updating pkg via brew but none of it worked so far. I am using a Mac OS Catalina V. 10.15.1

This is the code I am trying to run:

logicgates.hpp:

#include<iostream>
#include<vector>
#ifndef LOGICGATES_HPP
#define LOGICGATES_HPP

class LogicGates 
{
    public:
// Declaration of the gate values
    std::vector<int> inputs;
    int output;
    int  inputSize;

// Constractor and Deconstractor
    LogicGates();
    virtual~LogicGates();

// Function Declarations
    virtual void SetInput(int inputValue, int inputNum);
    virtual int CalculateOutput();
    virtual void PrintInfo();
};

class AND : public LogicGates
{
    public:
// Declaration of the gate values
    std::vector<int> inputs;
    int output;
    int  inputSize;
// Constractor and Deconstractor
    AND(int inputSizeAND);
    ~AND();

// Function Declarations
    void SetInput(int inputValue, int inputNum);
    int CalculateOutput();
    void PrintInfo();
};

logicgates.cpp:

#include "./logicgates.hpp"
#include <vector>
#include <iostream>
using namespace std;

// -------------------------------------- Method declarations ----------------------------------------

// ----------------- LogicGates Class ------------------
LogicGates::LogicGates(){}//Constractor 
LogicGates::~LogicGates(){}//Destractor

// Methods
void LogicGates::SetInput(int inputValue, int inputNum){}
int LogicGates::CalculateOutput(){ return 0; }
void LogicGates::PrintInfo(){}


// ----------------- AND Class ------------------

AND::AND(int inputSizeAND) //Constructor
{
    if ((inputSizeAND == 1) || (inputSizeAND == 0)){
        cout << "ERROR! : Input size ERROR, AND gates minimum input size is 2. " << endl;
        exit(-1);
    }
    else 
    {
        for(int i=0; i<inputSizeAND; i++){
            inputs.push_back(0);
        }
        inputs.clear();
        inputSize = inputSizeAND;
    }   

}

AND::~AND(){} //Destructor

// Methods
void AND::SetInput(int inputValue, int inputNum)
{
    inputs[inputNum] = inputValue;
}

int AND::CalculateOutput()
{
    for (int i = 0; i<inputSize-1; i++ ) 
    {
        output = inputs[i] and inputs[i+1];
    }
    return output;
}

void AND::PrintInfo() 
{
    cout << "\n\n\n" << endl;
    cout << " Gate : AND " << endl;
    cout << " Input Size : " << inputSize << endl;
    cout << " Input Table: " << endl;
    for (int i = 0; i<inputSize; i++)
    {
        cout << " Input number : " << i << " Value : " << inputs[i] << endl;
    }
    cout << " Output : " << AND::CalculateOutput() << endl;
    cout << "\n\n" << endl;
}

logicgates_tb.cpp:


#include "./logicgates.hpp"
#include <iostream>
#include <vector>

using namespace std;
int main(){

AND and1(2);
    and1.SetInput(1,0);
    and1.SetInput(0,1);

    if ( 0 == and1.CalculateOutput())
    {
        cout << " Test AND 1 is PASS " << endl;
    }
    else 
    {
        cout << " Test AND 1 is FAIL " << endl;
    }
    and1.PrintInfo();

    return 0;
}

I really why it is not working at this point and I have been trying dor 3 days now.

Aucun commentaire:

Enregistrer un commentaire