I have the following basic Hello World program for using OpenMP:
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/time.h>
#include<omp.h>
int main(int argc, char **argv) {
printf("This line is executed serially.\n\n");
#pragma omp parallel
int nthreads = omp_get_num_threads();
int myid = omp_get_thread_num();
printf("Hello, world! I am thread %d of %d treads\n", myid, nthreads);
return EXIT_SUCCESS;
}
I am using Microsoft Visual Studio Code as an IDE, and the code is written in c (and file therefore has a .c, not .cpp extension). When I run the code without debugging, VSC uses the following command in terminal to run the code, and the following error appears:
gcc tescript1.c -o tescript1 && "/[insert_working_directory_here]/"tescript1
Undefined symbols for architecture x86_64:
"_omp_get_num_threads", referenced from:
_main in tescript1-79e487.o
"_omp_get_thread_num", referenced from:
_main in tescript1-79e487.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Other threads including C++ Hello World Undefined symbols for architecture x86_64: seem to suggest I'm using the wrong compiler. However, in this example, their program is c++, not c, and VSC's settings are anything but clear on how to change compilers. I've ended up stuck without being able to try the suggestions I've read or 100% for sure identify the problem. Any help is appreciated.