0

I'm getting this error when I try compiling my C++ mode

main.cpp

#include <iostream>
#include <fstream>
#include "storage.h"

using namespace std;

int main()
{
    uint pool_size = 300000000; // 300MB memory
    uint block_size = 200;

    Storage storage(pool_size, block_size); 
}

And this is my storage.h

#ifndef STORAGE_H
#define STORAGE_H

typedef unsigned int uint;
typedef unsigned char uchar;

using namespace std;

struct Address {
    void *block_address;
    short int offset;
};

class Storage {
    private:
        uint pool_size;
        uint block_size;
        uint total_block_size_used;
        uint total_record_size_used;
        uint curr_block_size_used;
        
        int num_allocated;

        uchar *storage_ptr;
        uchar *block_ptr;
    public:
        Storage(uint pool_size, uint block_size);

        bool allocate_block();
        
        Address allocate(uint record_size);

        int get_num_allocated() { 
            return num_allocated;
        }
        
        uint get_total_block_size_used() {
            return total_block_size_used; 
        }
        
        ~Storage();
};

#endif

And for storage.cpp, I have

Storage::Storage(uint pool_size, uint block_size) {
    this->pool_size = pool_size;
    this->block_size = block_size;
    this->total_block_size_used = 0;
    this->total_record_size_used = 0;

    this->num_allocated= 0;

    this->storage_ptr = new uchar[pool_size];
    this->block_ptr = nullptr;   
}

However, when I try running my code, the compiler gives the following error:

Undefined symbols for architecture arm64: "Storage::Storage(unsigned int, unsigned int)", referenced from: _main in main-9d3a25.o "Storage::~Storage()", referenced from: _main in main-9d3a25.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Could someone help me out here? I'm really at a lost

user7381027
  • 31
  • 1
  • 10

0 Answers0