Question

I have Windows 8 64bit operating system.

I wanted to experiment with following C code for OpenMP functionality:

hello.c program

#include <stdio.h>
#include <stdlib.h>
#include<omp.h>

int main()
{
    #pragma omp parallel
    printf("Hello world!\n");
    return 0;
}

While I tried to run the program from command prompt using: gcc -fopenmp hello.c

I got the following error:

c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot fin
d -lpthread
collect2.exe: error: ld returned 1 exit status

I have C:\MinGW in my path with gcc 4.8.1.

What is it I am missing?

Was it helpful?

Solution

Thanks osgx,

As I am newbie I couldn't make out what these pthreads meant. But after all I found solution to my problem. I installed gcc 4.8.2 64 bit on my machine from http://www.equation.com/servlet/equation.cmd?fa=fortran. It changed the environment variable (in path) itself. After finishing installation, I restarted my computer and when I typed:

gcc -fopenmp hello.c

for the above code in command line, the code worked.

OTHER TIPS

The other trick is to use docker container with gcc.

Steps:

  1. Install docker
  2. In the docker terminal: docker pull gcc
  3. Then run a terminal and mount a host folder where your C scripts are inside the gcc container by typing: docker run -it -v /hostfolder:/folderincontainer gcc /bin/bash
  4. Then execute the script in the terminal.

Its simple. No need to worry about the specifics of OS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top