0

Why am I getting the error message undefinded reference to 'omp_get_wtime' when I try to build my cpp file?

The full error message looks like this:

C:\Program Files\JetBrains\CLion 2022.2.4\bin\mingw\bin/ld.exe: 
C:\Users\Hannah\AppData\Local\Temp\ccp3nN8r.o:daxpy.cpp:(.text+0x629): undefined reference to 'omp_get_wtime'
collect2.exe: error: ld returned 1 exit status

I looked into various posts already and most of them say to link -fopenmp in the makefile, but I already did that (it was done for us students).

My Makefile looks like this:

CC=gcc
CXX=g++
CFLAGS=-O3 -fopenmp -std=c99
CXXFLAGS=-O3 -fopenmp
EXECS=daxpy

all: $(EXECS)

matmul_serial-sol: daxpy.cpp
    $(CXX) -o $@ $<  $(CXXFLAGS)

clean:
    rm -f $(EXECS) *.o

and after suggestions from the comments:

CC=gcc
CXX=g++
CFLAGS=-O3 -fopenmp -std=c99
CXXFLAGS=-O3 -fopenmp
LDFLAGS= -fopenmp
EXECS=daxpy

all: $(EXECS)

daxpy: daxpy.cpp
    $(CXX) -o $@ $<  $(CXXFLAGS)

clean:
    rm -f $(EXECS) *.o

and I did include omp.h in my file.

HeaTHeR
  • 31
  • 4
  • 1
    your Makefile does not use `fopenmp` for the `daxpy` target, just for the `matmul_serial-sol` target, which you don't seem to be using anywhere else? – Marcus Müller Dec 03 '22 at 21:02
  • 1
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Dec 03 '22 at 21:50
  • Actually, I think you should rename `matmul_serial-sol` to `daxpy` or use `EXECS=matmul_serial-sol`. Makefiles have default rules and they are certainly the root of the issue. Default rules may use the standard flags. If so, you need to add `LDFLAGS=-fopenmp` because this is also required for the link, not just the TU compilation. – Jérôme Richard Dec 03 '22 at 23:15
  • I renamed it to daxpy and added the ldflag, but it didn't change anything – HeaTHeR Dec 04 '22 at 00:00

0 Answers0