Undefined reference to main collect2 error ld returned 1 exit status

Free source code and tutorials for Software developers and Architects.; Updated: 6 Sep 2021

When I am trying to compile the host code using make command. It gave me this error:

`/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
make: *** [bin/host] Error 1
`

my main.cpp

#include<assert.h>
#include<math.h>
#include<cstring>


#include<CL/cl.h>
#include<time.h>

#include<CL/cl_ext.h>
#include<algorithm>
#include<iomanip>
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <array> 
#include <string.h>
#include <CL/opencl.h>

using namespace std;
using namespace aocl_utils;
void cleanup() {}

bool read_data_set(string filename, array<array<int, 20>, 5430>& array_X_dataset, array<int, 5430>& array_Y_dataset) {
    int field0, field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11,
        field12, field13, field14, field15, field16, field17, field18, field19, field20, field21;
    char comma;
    int line = 0;

    ifstream myfile(filename);

    if (myfile.is_open())
    {
        while (myfile
            >> field0 >> comma
            >> field1 >> comma
            >> field2 >> comma
            >> field3 >> comma
            >> field4 >> comma
            >> field5 >> comma
            >> field6 >> comma
            >> field7 >> comma
            >> field8 >> comma
            >> field9 >> comma
            >> field10 >> comma
            >> field11 >> comma
            >> field12 >> comma
            >> field13 >> comma
            >> field14 >> comma
            >> field15 >> comma
            >> field16 >> comma
            >> field17 >> comma
            >> field18 >> comma
            >> field19 >> comma
            >> field20 >> comma
            >> field21)
        {


            array<int, 20> inner_array{ field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11,
            field12, field13, field14, field15, field16, field17, field18, field19, field20 };
            array_X_dataset[line] = inner_array;
            array_Y_dataset[line] = field21;
            line++;

        }

        myfile.close();

    }
    else {
        cout << "Unable to open file";
        return true;
    }
    return false;
}


void mix_dataset(array<array<int, 20>, 5430>& array_X_dataset, array<int, 5430>& array_Y_dataset) {
    size_t len = array_X_dataset.size();
    for (size_t i = 0; i < len; ++i) {
        size_t swap_index = rand() % len;  
        if (i == swap_index)
            continue;

        array<int, 20> data_point{  };
        data_point = array_X_dataset[i];
        array_X_dataset[i] = array_X_dataset[swap_index];
        array_X_dataset[swap_index] = data_point;
        int Y = array_Y_dataset[i];
        array_Y_dataset[i] = array_Y_dataset[swap_index];
        array_Y_dataset[swap_index] = Y;
    }
}




void split_dataset(int fold, int **array_X_set, int *array_Y_set,int **X_train, int *Y_train,
    int **X_test, int *Y_test) {
   int rows = 5430;
    int cols = 20;
    int division = 1086;
    switch (fold) {
    case 1:
              
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                if (i < division) {
                    X_test[i][j] = array_X_set[i][j];
                    Y_test[i] = array_Y_set[i];
                }

                else {
                    X_train[i - division][j] = array_X_set[i][j];
                    Y_train[i - division] = array_Y_set[i];
                }
            }
        }
        break;

    case 2:
        
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                if (i >= 1086 && i <= 2171) {
                    X_test[i - 1086][j] = array_X_set[i][j];
                    Y_test[i - 1086] = array_Y_set[i];
                }
                else {
                    if (i < 1086) {
                        X_train[i][j] = array_X_set[i][j];
                        Y_train[i] = array_Y_set[i];
                    }
                    else {
                        X_train[i - (2171 - 1086 + 1)][j] = array_X_set[i][j];
                        Y_train[i - (2171 - 1086 + 1)] = array_Y_set[i];
                    }
                }
            }
        }
        break;

    case 3:
        
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                if (i >= 2172 && i <= 3257) {
                    X_test[i - 2172][j] = array_X_set[i][j];
                    Y_test[i - 2172] = array_Y_set[i];
                }

                else {
                    if (i < 2172) {
                        X_train[i][j] = array_X_set[i][j];
                        Y_train[i] = array_Y_set[i];
                    }
                    else
                    {
                        X_train[i - (3257 - 2172 + 1)][j] = array_X_set[i][j];
                        Y_train[i - (3257 - 2172 + 1)] = array_Y_set[i];

                    }
                }
            }
        }
        break;

    case 4:
        
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                if (i >= 3258 && i <= 4343) {
                    X_test[i - 3258][j] = array_X_set[i][j];
                    Y_test[i - 3258] = array_Y_set[i];
                }

                else {
                    if (i < 3258) {
                        X_train[i][j] = array_X_set[i][j];
                        Y_train[i] = array_Y_set[i];
                    }
                    else
                    {
                        X_train[i - (4343 - 3258 + 1)][j] = array_X_set[i][j];
                        Y_train[i - (4343 - 3258 + 1)] = array_Y_set[i];

                    }
                }
            }
        }
        break;
    case 5:
        
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                if (i >= 4344 && i <= 5429) {
                    X_test[i - 4344][j] = array_X_set[i][j];
                    Y_test[i - 4344] = array_Y_set[i];
                }

                else {
                    if (i < 4344) {
                        X_train[i][j] = array_X_set[i][j];
                        Y_train[i] = array_Y_set[i];
                    }
                    else
                    {
                        X_train[i - (5429 - 4344 + 1)][j] = array_X_set[i][j];
                        Y_train[i - (5429 - 4344 + 1)] = array_Y_set[i];

                    }
                }
            }
        }
        break;
    }

}



int main()
{
    
    string filename = ".//dataset.csv";
    static array<array<int, 20>, 5430> array_X_dataset{};
    static array<int, 5430> array_Y_dataset{};
   
    bool error = read_data_set(filename, array_X_dataset, array_Y_dataset);
    if (error) {
        cout << "Exiting with error while reading dataset file " << filename << endl;
        exit(-1);
    }
    
    


    
    
    srand(3);
    mix_dataset(array_X_dataset, array_Y_dataset);

    
   
     
    int* array_Y_set = new int[5430];
    int** array_X_set = new int* [5430];
    for (int i = 0; i < 5430; i++) {
        array_X_set[i] = new int[20];
    }
    
    for (int i = 0; i < 5430; i++) {
        for (int j = 0; j < 20; j++)
            array_X_set[i][j] = array_X_dataset[i][j];
        array_Y_set[i] = array_Y_dataset[i];
    }
  

    
    int* Y_train = new int[4344];
    int* Y_test = new int[1086];

    int** X_train = new int* [4344];
    for (int i = 0; i < 4344; i++) {
        X_train[i] = new int[20];
    }
    int** X_test = new int* [1086];
    for (int i = 0; i < 1086; i++) {
        X_test[i] = new int[20];
    }
    
    int fold = 1;    
   
     
    split_dataset(fold, array_X_set, array_Y_set, X_train, Y_train, X_test, Y_test);
   
   
    
   
    
   

    
    
    

    
    cl_platform_id fpga_paltform = NULL;
    if (clGetPlatformIDs(1, &fpga_paltform, NULL) != CL_SUCCESS) {
        printf("Unable to get platform_idn");
        return 1;
    }

    
    cl_device_id fpga_device = NULL;
    if (clGetDeviceIDs(fpga_paltform, CL_DEVICE_TYPE_ALL, 1, &fpga_device, NULL) != CL_SUCCESS) {
        printf("Unable to get device_idn");
        return 1;
    }

    
    cl_context context = clCreateContext(NULL, 1, &fpga_device, NULL, NULL, NULL);

    
    cl_command_queue queue = clCreateCommandQueue(context, fpga_device, 0, NULL);

    
    size_t length = 0x10000000;
    unsigned char* binary = (unsigned char*)malloc(length);
    FILE* fp = fopen("kernel.aocx", "rb");
    fread(binary, length, 1, fp);
    fclose(fp);

    
    cl_program program = clCreateProgramWithBinary(context, 1, &fpga_device, &length, (const unsigned char**)&binary, NULL, NULL);

    
    cl_kernel kernel = clCreateKernel(program, "KNN_classifier", NULL); 


    
    
    

    int host_output[4344];
    int k = 3;  
    int data_point[20] = {};
    for (int i = 0; i < 4344; ++i) {
        for (int j = 0; j < 20; ++j) {
            data_point[j] = array_X_set[i][j];
        }
    }

    cl_mem dev_X_train = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(int) * 4344 * 20, X_train, NULL);
    cl_mem dev_Y_train = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(int) * 4344, Y_train, NULL);
    cl_mem dev_data_point = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(int) * 20, data_point, NULL);
    cl_mem dev_output = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(int) * 4344, host_output, NULL);

    
    clEnqueueWriteBuffer(queue, dev_X_train, CL_TRUE, 0, sizeof(int) * 4344 * 20, X_train, 0, NULL, NULL);
    clEnqueueWriteBuffer(queue, dev_Y_train, CL_TRUE, 0, sizeof(int) * 4344, Y_train, 0, NULL, NULL);
    clEnqueueWriteBuffer(queue, dev_data_point, CL_TRUE, 0, sizeof(int) * 20, data_point, 0, NULL, NULL);

    
    clSetKernelArg(kernel, 0, sizeof(cl_mem), &dev_X_train);
    clSetKernelArg(kernel, 1, sizeof(cl_mem), &dev_Y_train);
    clSetKernelArg(kernel, 2, sizeof(cl_mem), &dev_data_point);
    clSetKernelArg(kernel, 3, sizeof(int), &k);
    clSetKernelArg(kernel, 4, sizeof(cl_mem), &dev_output);


    
    cl_event kernel_event;
    clEnqueueTask(queue, kernel, 0, NULL, &kernel_event);
    clWaitForEvents(1, &kernel_event);
    clReleaseEvent(kernel_event);

    
    clEnqueueReadBuffer(queue, dev_output, CL_TRUE, 0, sizeof(int) * 4344, host_output, 0, NULL, NULL);

    
    for (int i = 0; i < 4344; i++)
        printf("class_label[%d] = %dn", i, host_output[i]);


    clFlush(queue);
    clFinish(queue);
    
    clReleaseMemObject(dev_X_train);
    clReleaseMemObject(dev_Y_train);
    clReleaseMemObject(dev_data_point);
    clReleaseMemObject(dev_output);
    clReleaseKernel(kernel);
    clReleaseProgram(program);
    clReleaseCommandQueue(queue);
    clReleaseContext(context);

   
    
    
    
    for (int i = 0; i < 5430; i++) {
        delete[] array_X_set[i];
    }
    delete[] array_X_set;
    for (int i = 0; i < 4344; i++) {
        delete[] X_train[i];
    }
    delete[] X_test;
    for (int i = 0; i < 1086; i++) {
        delete[] X_test[i];
    }
    delete[] X_train;

    delete[] array_Y_set;
    delete[] Y_train;
    delete[] Y_test;
    free(data_point);
    free(host_output);

    return 0;
    
 }

What I have tried:

I am not sur why the compiler does not see my main function

C undefined reference errorC++ undefined reference is a linker error that often may come up when the function is declared but not implemented. These errors are usually partly identified by the linker error messages, but a programmer still needs to manually investigate the code, build system or linked libraries.

In the following article, we will mostly focus on the causes that occur in source code rather than in the build process or during library linkage. Find out the details in the upcoming paragraphs.

What Does Undefined Reference Mean in C++?

Undefined reference means that the linker is not able to find a symbol definition in any object file, but it’s still referenced. Undefined reference error is not C++ language-specific but rather a result of the executable program generation process. The latter process roughly works as follows: the compiler translates the human-readable source code into machine instructions and generates objects files. Then, the linker will try to combine all needed object files to generate an executable program or, alternatively, a library.

The linker itself can be considered as standalone software which deals with the object files and symbols defined in them. Symbols represent different entities like global variables, function names, member function names, etc.

In the following example, we have a SampleClass class that declares a constructor member. The only thing missing is that no definition is provided. So, if we try to build this program, the linker will throw an undefined reference error related to SampleClass::SampleClass() symbol.

– Code:

#include <iostream>
using std::string;
class SampleClass {private:
string user;
string name;
int number;public:
SampleClass();
};
int main() {
SampleClass sp1;
return 0;
}

– Program Output:

/usr/bin/ld: /tmp/ccoWSfKj.o: in function `main’:
tmp.cpp:(.text+0x24): undefined reference to `SampleClass::SampleClass()’
/usr/bin/ld: tmp.cpp:(.text+0x35): undefined reference to `SampleClass::~SampleClass()’
collect2: error: ld returned 1 exit status

How To Fix Undefined Reference in C++

You can fix undefined reference in C++ by investigating the linker error messages and then providing the missing definition for the given symbols. Note that not all linker errors are undefined references, and the same programmer error does not cause all undefined reference errors.

However, it’s more likely to be function-related when it’s declared somewhere, but the definition is nowhere to be found. The issue in the previous example code can be very easily traced as the program is very small.

On the other hand, huge codebases can yield undefined reference errors that may be harder to track down. The next code snippet tries to demonstrate a similar scenario which generates quite a large output of errors from the linker. Notice that the error comes from the polymorphic class SampleClass, which declares PrintContents() as a virtual function.

However, it does not even include empty curly braces to denote the body and qualify for the definition, resulting in an undefined reference error.

– Code:

#include <iostream>
#include <utility>
#include <sstream>using std::cout;
using std::endl;
using std::string;
class SampleClass {
private:
string user;
string name;
int number;public:
SampleClass(string  u, string  n, int num) :
user{std::move(u)}, name{std::move(n)}, number{num} {};
SampleClass(string  u, int num) :
user{std::move(u)}, name{“Name”}, number{num} {} ;virtual string PrintContents() const;
string getName() const;
string getUser() const;
int getNumber() const;
};
class DerivedClass : public SampleClass {
string identifier;public:
DerivedClass(string u, string n, int num, std::string id) :
SampleClass(std::move(u), std::move(n), num),
identifier{std::move(id)} {};
string PrintContents() const override;
string getIdentifier() const;
};
string DerivedClass::getIdentifier() const {
return this->identifier;
}
string DerivedClass::PrintContents() const {
std::stringstream ss;
ss << “user: ” << this->getUser()
<< ” name: ” << this->getName()
<< ” number: ” << this->getNumber()
<< ” identifier: ” << this->identifier  << ‘n’;
return ss.str();
}
string SampleClass::getName() const {
return this->name;
}
string SampleClass::getUser() const {
return this->user;
}
int SampleClass::getNumber() const {
return this->number;
}
void print(SampleClass& sp) {
cout << sp.PrintContents();
}
int main() {
auto dc1 = DerivedClass(“it”, “ai”, 5122, “tait”);
print(dc1);
return 0;
}

– Program Output:

/usr/bin/ld: /tmp/cckqLhcA.o: in function `SampleClass::SampleClass(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)’:

tmp.cpp:(.text._ZN11SampleClassC2ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_i[_ZN11SampleClassC5ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_i]+0x1f): undefined reference to `vtable for SampleClass’
/usr/bin/ld: /tmp/cckqLhcA.o: in function `SampleClass::~SampleClass()’:
tmp.cpp:(.text._ZN11SampleClassD2Ev[_ZN11SampleClassD5Ev]+0x13): undefined reference to `vtable for SampleClass’
/usr/bin/ld: /tmp/cckqLhcA.o:(.data.rel.ro._ZTI12DerivedClass[_ZTI12DerivedClass]+0x10): undefined reference to `typeinfo for SampleClass’
collect2: error: ld returned 1 exit status

Undefined Reference in Programs Without Main Function

Undefined reference error can occur if you try to compile the source code file that does not have the main() function. To be more precise, these types of source files will yield linker errors if compiled with the usual compiler arguments.

If you intend to compile a given source file without the main() function, you should pass the special argument to not run the linker stage. The latter is usually achieved with a -c argument to the compiler command (e.g., g++ or clang++ ).

– Code:

#include <iostream>
#include <utility>
#include <sstream>using std::cout;
using std::endl;
using std::string;
class SampleClass {private:
string user;
string name;
int number;public:
SampleClass(string  u, string  n, int num) :
user{std::move(u)}, name{std::move(n)}, number{num} {};
SampleClass(string  u, int num) :
user{std::move(u)}, name{“Name”}, number{num} {} ;
virtual string PrintContents() const;string getName() const;
string getUser() const;
int getNumber() const;
};
class DerivedClass : public SampleClass {
string identifier;
public:
DerivedClass(string u, string n, int num, std::string id) :
SampleClass(std::move(u), std::move(n), num),
identifier{std::move(id)} {};
string PrintContents() const override;
string getIdentifier() const;
};
string DerivedClass::getIdentifier() const {
return this->identifier;
}
string DerivedClass::PrintContents() const {
std::stringstream ss;
ss << “user: ” << this->getUser()
<< ” name: ” << this->getName()
<< ” number: ” << this->getNumber()
<< ” identifier: ” << this->identifier  << ‘n’;
return ss.str();
}
string SampleClass::getName() const {
return this->name;
}
string SampleClass::getUser() const {
return this->user;
}
int SampleClass::getNumber() const {
return this->number;
}
void print(SampleClass& sp) {
cout << sp.PrintContents();
}

– Program Output:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/Scrt1.o: in function `_start’:
(.text+0x24): undefined reference to `main’
collect2: error: ld returned 1 exit status

Tracking Down Undefined Reference Errors in Derived Classes

Another useful method to easily track down undefined reference errors in large codebases is enabling compiler warnings. Sometimes these may warn that functions are referenced but never defined. In the following example, the derived class explicitly overrides a virtual function but does not provide an implementation. Note that these types of errors may also be caused when the program build script or file does not include the corresponding source file.

– Code:

#include <iostream>
#include <utility>
#include <sstream>
#include “tmp.h”using std::cout;
using std::endl;
using std::cin;
using std::string;class SampleClass {
private:
string user;
string name;
int number;
public:
SampleClass(string  u, string  n, int num) :
user{std::move(u)}, name{std::move(n)}, number{num} {};
SampleClass(string  u, int num) :
user{std::move(u)}, name{“Name”}, number{num} {} ;
virtual string PrintContents() const { return {}; };string getName() const;
string getUser() const;
int getNumber() const;
};
class DerivedClass : public SampleClass {
string identifier;
public:
DerivedClass(string u, string n, int num, std::string id) :
SampleClass(std::move(u), std::move(n), num),
identifier{std::move(id)} {};
string PrintContents() const override;
string getIdentifier() const;
};
string DerivedClass::getIdentifier() const {
return this->identifier;
}
string SampleClass::getName() const {
return this->name;
}
string SampleClass::getUser() const {
return this->user;
}
int SampleClass::getNumber() const {
return this->number;
}
void print(SampleClass& sp) {
cout << sp.PrintContents();
}
int main() {
auto dc1 = DerivedClass(“it”, “ai”, 5122, “tait”);
print(dc1);
return 0;
}

– Program Output:

/usr/bin/ld: /tmp/ccdcAqfb.o: in function `DerivedClass::DerivedClass(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)’:

tmp.cpp:(.text._ZN12DerivedClassC2ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_iS5_[_ZN12DerivedClassC5ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_iS5_]+0xa6): undefined reference to `vtable for DerivedClass’
/usr/bin/ld: /tmp/ccdcAqfb.o: in function `DerivedClass::~DerivedClass()’:

tmp.cpp:(.text._ZN12DerivedClassD2Ev[_ZN12DerivedClassD5Ev]+0x13): undefined reference to `vtable for DerivedClass’
collect2: error: ld returned 1 exit status

Key Takeaways

In this article, we covered common reasons that yield an undefined reference to C++ function errors and described several ways to identify them. Here are some key points to bear in mind:

  • Undefined reference error is thrown by the linker rather than the compiler
  • It’s usually caused by the reference to the function that has been declared, but a definition can’t be found
  • Investigate linker error messages which can help to pin down the identifiers that are related to the cause of the problem
  • Don’t run the linker stage on programs that don’t include the main function

How to fix undefined reference in cNow you should be able to move on to some practical problems of analyzing linker errors and fixing them. You are definitely ready to try manually building relatively medium programs with multiple files and investigate possible causes for linker errors.

  • Author
  • Recent Posts

Position is Everything

Position Is Everything: Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL.

Position is Everything

Moniboi

Posts: 8
Joined: 2021-02-01 08:50

[Solved] GCC not working? undefined reference to `main’

#1

Post

by Moniboi » 2022-04-19 08:48

So I have set up a Debian system. It’s a bullseye install with newest updates. I’m using multiarch to make steam able to run.
I have installed build-essential, which includes gcc-multilib.

I have a simple piece of C code (the output remains the same regardless of code):

Code: Select all

#include <stdio.h>

int main() {
    printf("%s","Hello world!");
    return 0;
}

Compiled with:

The output is:

Code: Select all

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

With a -v flag:

Code: Select all

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 10.2.1-6' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-10-Km9U7s/gcc-10-10.2.1/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-Km9U7s/gcc-10-10.2.1/debian/tmp-gcn/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-mutex
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.1 20210110 (Debian 10.2.1-6) 
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/10/cc1 -quiet -v -imultiarch x86_64-linux-gnu Ex1.c -quiet -dumpbase Ex1.c -mtune=generic -march=x86-64 -auxbase Ex1 -version -fasynchronous-unwind-tables -o /tmp/ccCjCumF.s
GNU C17 (Debian 10.2.1-6) version 10.2.1 20210110 (x86_64-linux-gnu)
        compiled by GNU C version 10.2.1 20210110, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.0, isl version isl-0.23-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/10/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/10/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C17 (Debian 10.2.1-6) version 10.2.1 20210110 (x86_64-linux-gnu)
        compiled by GNU C version 10.2.1 20210110, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.0, isl version isl-0.23-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 1f803793fa2e3418c492b25e7d3eac2f
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 as -v --64 -o /tmp/ccAXLnIF.o /tmp/ccCjCumF.s
GNU assembler version 2.35.2 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.35.2
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/10/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/10/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper -plugin-opt=-fresolution=/tmp/ccUXWOCD.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/10/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/10 -L/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/10/../../.. /tmp/ccAXLnIF.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/10/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

Last edited by Moniboi on 2022-04-23 20:14, edited 1 time in total.


LE_746F6D617A7A69

Posts: 934
Joined: 2020-05-03 14:16
Has thanked: 7 times
Been thanked: 64 times

Re: GCC not working? undefined reference to `main’

#2

Post

by LE_746F6D617A7A69 » 2022-04-19 21:22

Moniboi wrote: ↑2022-04-19 08:48
I have installed build-essential, which includes gcc-multilib.

For sure the GCC is working, it’s the linker which returns a fault ;)
The build-essential package does not depend on gcc-multilib and it does not recommend installing the multilib packages — how did You get them?

Anyway, I’ve double-checked the output provided by Your gcc -v and it seems to be correct — so I can’t see a reason why it doesn’t work.
The only idea which comes to my mind is a broken system.

You can try the debsums command to verify the OS installation.

Bill Gates: «(…) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system.»
The_full_story and Nothing_have_changed


User avatar

fabien

Posts: 190
Joined: 2019-12-03 12:51
Location: Toulouse, France
Has thanked: 13 times
Been thanked: 31 times

Re: GCC not working? undefined reference to `main’

#3

Post

by fabien » 2022-04-21 10:49

LE_746F6D617A7A69 wrote: ↑2022-04-19 21:22You can try the debsums command to verify the OS installation.

Or just dpkg —verify. Are you aware of any difference between the two commands?

debsums package description:

tool for verification of installed package files against MD5 checksums
debsums can verify the integrity of installed package files against MD5 checksums installed by the package, or generated from a .deb archive.

man 1 dpkg excerpt:

-V, —verify [package-name…]
Verifies the integrity of package-name or all packages if omitted […]
Currently the only functional check performed is an md5sum verification of the file contents against the stored value in the files database.


LE_746F6D617A7A69

Posts: 934
Joined: 2020-05-03 14:16
Has thanked: 7 times
Been thanked: 64 times

Re: GCC not working? undefined reference to `main’

#4

Post

by LE_746F6D617A7A69 » 2022-04-21 21:01

fabien wrote: ↑2022-04-21 10:49
Are you aware of any difference between the two commands?

There are differences: (my laptop running Debian 11.3)

debsums:

Code: Select all

debsums: changed file /usr/share/lightdm/lightdm.conf.d/01_debian.conf (from lightdm package)
debsums: changed file /usr/share/lightdm/lightdm-gtk-greeter.conf.d/01_debian.conf (from lightdm-gtk-greeter package)

dpkg:

Code: Select all

??5?????? c /etc/schroot/schroot.conf
??5?????? c /etc/pulse/default.pa
??5?????? c /etc/fuse.conf
??5?????? c /etc/tor/torrc
??5?????? c /etc/lightdm/lightdm-gtk-greeter.conf
??5??????   /usr/share/lightdm/lightdm-gtk-greeter.conf.d/01_debian.conf
??5?????? c /etc/xdg/xfce4/helpers.rc
??5??????   /usr/share/lightdm/lightdm.conf.d/01_debian.conf

It seems that dpkg lists a false positives — like files with changed last modification date, instead of checking just the checksum (but I can’t confirm this — I didn’t verified the source code), for sure the debsums is *right* — it lists only the files which has been really changed.

Bill Gates: «(…) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system.»
The_full_story and Nothing_have_changed


Moniboi

Posts: 8
Joined: 2021-02-01 08:50

Re: GCC not working? undefined reference to `main’

#5

Post

by Moniboi » 2022-04-23 20:14

LE_746F6D617A7A69 wrote: ↑2022-04-19 21:22

Moniboi wrote: ↑2022-04-19 08:48
I have installed build-essential, which includes gcc-multilib.

For sure the GCC is working, it’s the linker which returns a fault ;)
The build-essential package does not depend on gcc-multilib and it does not recommend installing the multilib packages — how did You get them?

Anyway, I’ve double-checked the output provided by Your gcc -v and it seems to be correct — so I can’t see a reason why it doesn’t work.
The only idea which comes to my mind is a broken system.

You can try the debsums command to verify the OS installation.

I don’t know what happened there either. A re-install seems to have fixed it, so maybe something was broken. As for how I got it, I enabled multilib and the relevant graphics drivers in accordance with Debian wiki to get Steam running and then noticed that normal GCC wasn’t working with the same linker issue. I tried installing the multilib one and the issue stayed the same. From that point on, the build-essential package for one reason or another picked the multilib version.


LE_746F6D617A7A69

Posts: 934
Joined: 2020-05-03 14:16
Has thanked: 7 times
Been thanked: 64 times

Re: [Solved] GCC not working? undefined reference to `main’

#6

Post

by LE_746F6D617A7A69 » 2022-04-23 21:06

From Debian Wiki:

Run these commands to remove runtime libraries known to cause issues with Debian:

# rm ~/.steam/debian-installation/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu/libstdc++.so.6
# rm ~/.steam/debian-installation/ubuntu12_32/steam-runtime/i386/lib/i386-linux-gnu/libgcc_s.so.1
# rm ~/.steam/debian-installation/ubuntu12_32/steam-runtime/amd64/lib/x86_64-linux-gnu/libgcc_s.so.1
# rm ~/.steam/debian-installation/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu/libstdc++.so.6
# rm ~/.steam/debian-installation/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu/libxcb.so.1
# rm ~/.steam/debian-installation/ubuntu12_32/steam-runtime/i386/lib/i386-linux-gnu/libgpg-error.so.0

I’m not using Steam, and I’m not going to install it just to verify whether this solution works or not, but it seems to be rational — have You tried it?
(of course the version numbers can be different)

Bill Gates: «(…) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system.»
The_full_story and Nothing_have_changed


Topic: undefined reference to `main’  (Read 9668 times)

Landslyde

Following a C++ tutorial, the user (using CodeBlocks) has me to add a class through the File Menu: File -> New -> Class

So now I have main.cpp, bottles.cpp and bottles.h. But, unlike his that works, mine throws an error when I try to run it:

-------------- Build: Debug in tut-002 (compiler: GNU GCC Compiler)---------------

g++ -Wall -fexceptions -g -std=c++11 -I -c /home/slyde/Desktop/CB/Tutorials/tut-002/bottles.cpp -o obj/Debug/bottles.o
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

main.cpp has a main in it.

#include <iostream>
#include "bottles.h"

//using namespace std;

int main()
{
    bottles bo;
    return 0;
}

bottles.cpp:

#include "bottles.h"
#include <iostream>

bottles::bottles()
{
    std::cout << "Am I a glass bottle? Or am I made of plastic?" << std::endl;
}

bottles.h:

#ifndef BOTTLES_H
#define BOTTLES_H

class bottles
{
    public:
        bottles();
    //protected:
    //private:
};

#endif // BOTTLES_H

And the guy in the video…he never references any necessary setting(s) to run this. Will someone tell me what do I have to do to «fix» this? T tried adding a linker option: $(LINK) -nostartfiles -g … that I got from here. But that didn’t work.

Thanks.


Logged


You have to use a project….


Logged


… to compile both your cpp-files to link both together to the final application.


Logged


Landslyde

« Last Edit: February 22, 2018, 10:47:42 am by Landslyde »


Logged


Landslyde

I fixed it. But I have no idea how or why it worked out this way.

I closed the Project/Workspace and was prompted that the Project had changed — would I like to save the changes. I did. Then, just out of curiosity, I reopened it. F9 and it compiled and ran as it shld’ve all along.

Why did it take me closing it for it to save the changes and «fix» itself?


Logged


How did you added the files?

(@devs and only for the devs: this would not have happened if we save the project before building by default ;) because without fixed (saved) project a build is not  possible, like the source files also have to be saved before build…  )


Logged


Landslyde

1) File -> New -> Project (game me main.cpp
2) File -> New-> Class (game me bottles.h and bottles.cpp)


Logged


And at the popup about selecting target you enabled the tick on both?


Logged


Landslyde


Logged


i see from your signature that you are using a 5 year old release of codeblocks. Can you try the latest release? Can you reproduce this problem?


Logged


Landslyde

Three of the Debian files won’t install. Dependencies aren’t satisfied. Ever. I wish Mint wld update their damn depository!


Logged


Have you passed all dep packages in a single command? Are you using the correct packages?


Logged

(most of the time I ignore long posts)
[strangers don’t send me private messages, I’ll ignore them; post a topic in the forum, but first read the rules!]


Landslyde

No. I haven’t tried to knock them all out in a single cmd. Here’s what I tried to use:


Logged


Landslyde

Can you reproduce this problem?

Ten times out of ten. I can reproduce this issue with my eyes closed.


Logged



Logged


lukinegor

1 / 1 / 0

Регистрация: 31.01.2020

Сообщений: 148

1

01.06.2020, 13:07. Показов 8395. Ответов 9

Метки undefined reference, ошибка (Все метки)


Написал программу для решения задачки. Компилирую, мне выдаёт Это(см. ниже). Смотрел ответы на идентичную ошибку, но они мне не подходят вроде как. Можете объяснить, почему эта ошибка может быть в таком большом разноообразии случаев? Что делать конкретно с этим?

Bash
1
2
3
4
$ g++ 1_2017_2018_A.cpp 
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

Вот сама программа, но я так думаю, что ошибка не в коде..

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
#include <fstream>
 
using namespace std;
 
void count_score(int k, int *counter, int *score);  // Функция записывающая полученные 
                                                    // штрафные очки за один раунд забега
                                                    // в score[k] (для k-ой команды).
 
bool first(int i, int *score);                      // Функция проверяюая, является ли элемент score[i]
                                                    // первым с таким значением.
 
int count_place(int N, int I, int *score);          // Функция считающая место 
                                                    // I-ой команды (команды Василия Петровича).
 
 
int main()
{
    ifstream input("input.txt");
    ofstream output("output.txt");
 
    if(input.is_open()) {} // Проверка того, что файл открылся.
    else
    {
        output << "Input.txt was not open!" << endl;
    }
 
    int N, I, outputResult; // Те же самы N и I из условия.
 
    outputResult = 0;
    input >> N >> I;
 
    int times[N][3]; // Массив с временами забегов из улсовия.
    int counter[N]; // Массив необходимый в процессе работы программы для подсчёта штрафных очков в каждом забеге.
    int score[N];   // Массив в котором в результате работы программы будут штрафные очки для каждой команды 
                    //(score[I] == кол-во штрафных очков команды Василия Петровича).
    for(int i = 0; i < N; i++)
    {
        score[i] = 0;
    }
 
    for(int i = 0; i < 3*N; i++) //Считка времён забегов в times[][].
    {
        input >> *(times + i);
    }
    
    input.close();
 
    for(int i = 0; i < 3; i++) //Для трёх раундов.
    {
        for(int k = 0; k < N; k++) //Прибавляем время текущего раунда.
        {
            counter[k] += times[k][i];
        }
 
        for(int k = 0; k < N; k++) //Считаем штрафные очки.
        {
            count_score(N, k, counter, score);
        }
    }
 
    outputResult = count_place(N, I, score);
 
    output << outputResult;
 
    output.close();
 
    return 0;
}
 
 
 
void count_score(int N, int k, int *counter, int *score)
{
    for(int i = 0; i < N; i++)
    {
        if( (i != k) && (counter[i] > counter[k]) )
        {
            score[k]++;
        }
        else
        {
            continue;
        }
    }
}
 
bool first(int i, int *score)
{
    bool result = true;
 
    for(int k = 0; k < i - 1; k++)
    {
        if(score[k] != score[i])
        {
            continue;
        }
        else
        {
            result = false;
            break;
        }
    }
 
    return result;
}
 
int count_place(int N, int I, int *score)
{
    int resultPlace; //Возвращаемое значение - ответ задачи.
 
    for(int i = 0; i < N; i++)
    {
        if( (i != I) && (score[i] > score[I]) && (first(i, score)) )
        {
            resultPlace++;
        }
        else
        {
            continue;
        }
    }
}

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



6574 / 4559 / 1843

Регистрация: 07.05.2019

Сообщений: 13,726

01.06.2020, 13:13

2

Цитата
Сообщение от lukinegor
Посмотреть сообщение

Написал программу для решения задачки. Компилирую, мне выдаёт Это(см. ниже). Смотрел ответы на идентичную ошибку, но они мне не подходят вроде как. Можете объяснить, почему эта ошибка может быть в таком большом разноообразии случаев? Что делать конкретно с этим?

А других ошибок нету? Например вот здесь

Цитата
Сообщение от lukinegor
Посмотреть сообщение

for(int i = 0; i < 3*N; i++) //Считка времён забегов в times[][].
    {
        input >> *(times + i);
    }



0



1 / 1 / 0

Регистрация: 31.01.2020

Сообщений: 148

01.06.2020, 13:16

 [ТС]

3

oleg-m1973, компилятор больше ничего не пишет(в терминал больше ничего не выводится)

Добавлено через 1 минуту
oleg-m1973, Что там может быть не так?



0



6574 / 4559 / 1843

Регистрация: 07.05.2019

Сообщений: 13,726

01.06.2020, 13:19

4

Цитата
Сообщение от lukinegor
Посмотреть сообщение

oleg-m1973, Что там может быть не так?

https://godbolt.org/z/dPp9Nf



0



lukinegor

1 / 1 / 0

Регистрация: 31.01.2020

Сообщений: 148

01.06.2020, 13:40

 [ТС]

5

oleg-m1973, спасибо большое. Мне казалось, что двумерные массивы в ++ реализованы как одномерные на самом деле…
Типа для a[n][m] элемент a[3][4] == *(a + 3*m + 4)

Добавлено через 4 минуты
oleg-m1973, все ошибки я исправил. Но мой компилятор всё тоже самое и выдаёт

Добавлено через 3 минуты
Вариант без других ошибок. Но на компиляцию выдаёт всё тоже самое

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>
#include <fstream>
 
using namespace std;
 
void count_score(int N, int k, int *counter, int *score);   // Функция записывающая полученные 
                                                    // штрафные очки за один раунд забега
                                                    // в score[k] (для k-ой команды).
 
bool first(int i, int *score);                      // Функция проверяюая, является ли элемент score[i]
                                                    // первым с таким значением.
 
int count_place(int N, int I, int *score);          // Функция считающая место 
                                                    // I-ой команды (команды Василия Петровича).
 
 
int main()
{
    ifstream input("input.txt");
    ofstream output("output.txt");
 
    if(input.is_open()) {} // Проверка того, что файл открылся.
    else
    {
        output << "Input.txt was not open!" << endl;
    }
 
    int N, I, outputResult; // Те же самы N и I из условия.
 
    outputResult = 0;
    input >> N >> I;
 
    int times[N][3]; // Массив с временами забегов из улсовия.
    int counter[N]; // Массив необходимый в процессе работы программы для подсчёта штрафных очков в каждом забеге.
    int score[N];   // Массив в котором в результате работы программы будут штрафные очки для каждой команды 
                    //(score[I] == кол-во штрафных очков команды Василия Петровича).
    for(int i = 0; i < N; i++)
    {
        score[i] = 0;
    }
 
    for(int i = 0; i < N; i++) //Считка времён забегов в times[][].
    {
        for(int j = 0; j < 3; j++)
        {
            input >> times[i][j];
        }
    }
    
    input.close();
 
    for(int i = 0; i < 3; i++) //Для трёх раундов.
    {
        for(int k = 0; k < N; k++) //Прибавляем время текущего раунда.
        {
            counter[k] += times[k][i];
        }
 
        for(int k = 0; k < N; k++) //Считаем штрафные очки.
        {
            count_score(N, k, counter, score);
        }
    }
 
    outputResult = count_place(N, I, score);
 
    output << outputResult;
 
    output.close();
 
    return 0;
}
 
 
 
void count_score(int N, int k, int *counter, int *score)
{
    for(int i = 0; i < N; i++)
    {
        if( (i != k) && (counter[i] > counter[k]) )
        {
            score[k]++;
        }
        else
        {
            continue;
        }
    }
}
 
bool first(int i, int *score)
{
    bool result = true;
 
    for(int k = 0; k < i - 1; k++)
    {
        if(score[k] != score[i])
        {
            continue;
        }
        else
        {
            result = false;
            break;
        }
    }
 
    return result;
}
 
int count_place(int N, int I, int *score)
{
    int resultPlace; //Возвращаемое значение - ответ задачи.
 
    for(int i = 0; i < N; i++)
    {
        if( (i != I) && (score[i] > score[I]) && (first(i, score)) )
        {
            resultPlace++;
        }
        else
        {
            continue;
        }
    }
}



0



oleg-m1973

6574 / 4559 / 1843

Регистрация: 07.05.2019

Сообщений: 13,726

01.06.2020, 13:46

6

Лучший ответ Сообщение было отмечено lukinegor как решение

Решение

Цитата
Сообщение от lukinegor
Посмотреть сообщение

oleg-m1973, спасибо большое. Мне казалось, что двумерные массивы в ++ реализованы как одномерные на самом деле…
Типа для a[n][m] элемент a[3][4] == *(a + 3*m + 4)

Так и реализованы. Только только чтобы так обращаться к ним, надо их преобразовывать соответствующим образом

C++
1
2
3
        int a[3][4];
        int *p = (int *)a;
        a[1][2] == *(p + 3 * 1 + 2) == p[3 * 1 + 2];

Добавлено через 2 минуты

Цитата
Сообщение от lukinegor
Посмотреть сообщение

oleg-m1973, все ошибки я исправил. Но мой компилятор всё тоже самое и выдаёт

Какая у тебя версия?

Добавлено через 6 секунд

Цитата
Сообщение от lukinegor
Посмотреть сообщение

oleg-m1973, все ошибки я исправил. Но мой компилятор всё тоже самое и выдаёт

Какая у тебя версия?

Добавлено через 2 минуты
В count_place() return не делаешь

Добавлено через 52 секунды
А 1_2017_2018_A.cpp — это точно тот файл?



0



lukinegor

1 / 1 / 0

Регистрация: 31.01.2020

Сообщений: 148

01.06.2020, 13:51

 [ТС]

7

oleg-m1973,

C++
1
2
        int a[3][4];
        a[1][2]  ?== *(a + 5);

Или так не работает?

Добавлено через 1 минуту
oleg-m1973, да, файл тот



0



6574 / 4559 / 1843

Регистрация: 07.05.2019

Сообщений: 13,726

01.06.2020, 13:55

8

Цитата
Сообщение от lukinegor
Посмотреть сообщение

Или так не работает?

*(a + 5) это a[5]

Добавлено через 2 минуты

Цитата
Сообщение от lukinegor
Посмотреть сообщение

oleg-m1973, да, файл тот

В коде ошибки с main() у тебя нет. Проблемы скорее всего где-то снаружи



0



1 / 1 / 0

Регистрация: 31.01.2020

Сообщений: 148

01.06.2020, 13:55

 [ТС]

9

oleg-m1973

Цитата
Сообщение от oleg-m1973
Посмотреть сообщение

Какая у тебя версия?

Если я правильно понял, то вот
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)



0



1 / 1 / 0

Регистрация: 31.01.2020

Сообщений: 148

01.06.2020, 14:05

 [ТС]

10

oleg-m1973, спасибо большое. Вы правильно поняли, это был файл с идентичным названием в другой папке. Ошибка нейтрализована



0



Понравилась статья? Поделить с друзьями:
  • Undefined object 7 error index primary does not exist
  • Undefined function or variable matlab как исправить
  • Undefined function matlab error
  • Undefined external error как исправить
  • Undefined external error fl studio