134k views
1 vote
Error- sh -c make -s

/nix/store/039g378vc3pc3dvi9dzdlrd0i4q93qwf-binutils-2.39/bin/ld: /nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib/crt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:10: main] Error 1
exit status 2


Maybe i missed of forgot something

The header file is:

#ifndef MAIN_SAVITCH_SEQUENCE_H
#define MAIN_SAVITCH_SEQUENCE_H

#include // Provides size_t

namespace main_savitch_3
{
class sequence
{
public:
// TYPEDEFS and MEMBER CONSTANTS
typedef double value_type;
typedef size_t size_type;
static const size_type CAPACITY = 30;

// CONSTRUCTOR
sequence();

// MODIFICATION MEMBER FUNCTIONS
void start();
void advance();
void insert(const value_type& entry);
void attach(const value_type& entry);
void remove_current();

// CONSTANT MEMBER FUNCTIONS
size_type size() const;
bool is_item() const;
value_type current() const;

private:
value_type data[CAPACITY];
size_type used;
size_type current_index;
};
}

#endif


The implementation file is:

#include "sequence1.h"
#include "iostream"
namespace main_savitch_3 {

// CONSTRUCTOR
sequence::sequence()
{
used = 0;
current_index = CAPACITY; // Indicates there is no current item
}

// MODIFICATION MEMBER FUNCTIONS
void sequence::start()
{
if (used > 0)
{
current_index = 0;
}
}

void sequence::advance()
{
if (is_item())
{
++current_index;
}
}

void sequence::insert(const value_type& entry)
{
if (size() < CAPACITY)
{
if (!is_item()) // No current item, so insert at start
{
current_index = 0;
}
for (size_type i = used; i > current_index; --i)
{
data[i] = data[i-1];
}
data[current_index] = entry;
++used;
}
}

void sequence::attach(const value_type& entry)
{
if (size() < CAPACITY)
{
if (!is_item()) // No current item, so attach at end
{
current_index = used - 1;
}
else // Attach after current item
{
++current_index;
for (size_type i = used; i > current_index; --i)
{
data[i] = data[i-1];
}
}
data[current_index] = entry;
++used;
}
}

void sequence::remove_current()
{
if (is_item())
{
for (size_type i = current_index + 1; i < used; ++i)
{
data[i-1] = data[i];
}
--used;
if (current_index == used)
{
current_index = CAPACITY; // Indicates there is no current item
}
}
}

// CONSTANT MEMBER FUNCTIONS
sequence::size_type sequence::size() const
{
return used;
}

bool sequence::is_item() const
{
return current_index < used;
}

sequence::value_type sequence::current() const
{
if (is_item())
{
return data[current_index];
}
else
{
return 0; // This could be changed to throw an exception instead
}
}

} // end namespace main_savi

User Ramon Snir
by
8.7k points

1 Answer

5 votes

Final answer:

The error message you encountered is a linker error that indicates the 'main' function is missing or not defined in your code. To fix this error, you need to define the 'main' function in your code.

Step-by-step explanation:

The error message you encountered is a linker error. Linker errors occur when the compiler is unable to find the definition of a function or variable that is used in your code. In this case, the linker is unable to find the 'main' function.

The 'main' function is the entry point of a C++ program. Every C++ program must have a 'main' function. The linker error you received indicates that the 'main' function is missing or not defined in your code. To fix this error, you need to define the 'main' function in your code.

Here is an example of how the 'main' function should be defined:

#include <iostream>

int main() {
// Your code goes here
return 0;
}

User Nothing
by
8.3k points