K
K
kill942015-10-03 20:18:44
C++ / C#
kill94, 2015-10-03 20:18:44

How to fix collect2.exe: error: ld returned 1 exit status?

#include <iostream>
#include <ctime>
#include <omp.h>
#include <stdlib.h>
#include "stdio.h"

using namespace std;

const int MAX_RAND = 100;

int **OutMass(int N){
  int **Mas = new int*[N];
  for (int i = 0; i < N; i++)
    Mas[i] = new int[N];
  for (int i = 0; i < N; i++)
  for (int j = 0; j < N; j++)
    Mas[i][j]=rand();
  return Mas;
}

int main(int argc, char* argv[])
{
  srand(time(NULL));
  omp_set_num_threads(4);
  int N = argc != 0 ? atol(argv[1]) : 10; 
  int **A = OutMass(N);
  int **B = OutMass(N);
  int **C = new int*[N];
  for (int i = 0; i < N; i++)
    C[i] = new int[N];
  double t1 = omp_get_wtime();
#pragma omp parallel for
  for (int i = 0; i < N; ++i)
  {
    for (int j = 0; j < N; ++j)
    {
      C[i][j] = 0;
      for (int k = 0; k < N; ++k)
        C[i][j] += A[i][k] * B[k][j];
    }
  }
  double t2 = omp_get_wtime();
  printf("Execution time   : %.5f s\n", t2 - t1);
  printf("Timer resolution : %.5f s\n", omp_get_wtick());

  return 0;
}

batch file:
PATH=%PATH%;c:\MinGW\bin
g++ -fopenmp test.cpp -o test.exe
pause
what's the problem? when run, it gives an error
collect2.exe: error: ld returned 1 exit status

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
ssv32, 2019-06-02
@ssv32

Such an error can be if what you compile and run is already running

M
Mercury13, 2015-10-03
@Mercury13

On a rather old version of mingw that I had, it turned out to be done like this - by running the compiler and the linker separately.

PATH %PATH%;d:\MinGW\x86\bin
g++ -fopenmp -c main.cpp -o main.o
g++ -o test.exe main.o -lgomp
pause

At the same time, I had to download pthreads for win32, by default there are libraries (*.a), but no dll.
And in general, it depends on the MinGW build. On fresh builds of mingw-w64 - both with Win32- and posix-streams - everything worked exactly your way. And pthreads was found.
PATH %PATH%;d:\MinGW\i686-5.2.0-win32-dwarf-rt_v4-rev0\mingw32\bin\
g++ -fopenmp main.cpp -o test.exe
pause

And, of course, you did not indicate WHY the linker came out with code 1. But I already understood this myself, having experimented.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question