Kyler
Kyler

Reputation: 43

G++ Library Not Found

I am trying to compile a TBB and OpenMp comparison program that I made. It is compiling fine with the default visual studio compiler. So, I know that TBB is installed correctly. However, I would like to use g++ instead. I have created a Makefile, and from what I read the -ltbb flag is needed.

My error is, "c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -ltbb".

I am not an expert when it comes to making sure I have everything linked correctly and am still trying to learn.

This is my current Makefile

CPLUSPLUS = g++ 
OPTFLAGS = -O3
TBB_INCLUDE_PATH = C:\tbb-2020.1-win\tbb\include
TBB_LIBRARY_PATH = C:\tbb\tbb\lib\intel64\vc14

all: pps

pps: avl.o main.o parPlaneSweep.o
    $(CPLUSPLUS) -I$(TBB_INCLUDE_PATH) -L$(TBB_LIBRARY_PATH) $(OPTFLAGS) -o $@ $^ -ltbb

avl.o: avl.h avl.c
    $(CC) -c $(OPTFLAGS) -fPIC avl.c

main.o: main.cpp parPlaneSweep.h
    $(CPLUSPLUS) -c $(OPTFLAGS) -fopenmp main.cpp 

parPlaneSweep.o: parPlaneSweep.h parPlaneSweep.cpp
    $(CPLUSPLUS) -c $(OPTFLAGS)  -fPIC -fopenmp parPlaneSweep.cpp

clean:
    rm *.o
    rm pps

enter image description here

enter image description here

Upvotes: 0

Views: 302

Answers (1)

MadScientist
MadScientist

Reputation: 100781

Please update your question rather than pointing people at other websites.

First, you should never use backslashes in makefiles, even on Windows (there are exceptions to this on Windows but they're very rare). Always use forward slashes as directory separators.

Second, you define the variables TBB_INCLUDE_PATH and TBB_LIBRARY_PATH but then you never use them. Just mentioning the name of the variable doesn't use the variable. You have to include it in $(...) to use it, like $(TBB_INCLUDE_PATH).

Finally, all common linkers are single-pass linkers, which means the order in which you put the libraries and object files on the link line is critically important. You should always put the object files first, and the libraries last. If you have multiple libraries the order in which they appear may be important as well. Your link line should be something like this:

pps: avl.o main.o parPlaneSweep.o
        $(CPLUSPLUS) -I$(TBB_INCLUDE_PATH) -L$(TBB_LIBRARY_PATH) $(OPTFLAGS) -o $@ $^ -ltbb

If you want to know what $@ and $^ mean, you can read about automatic variables.

Upvotes: 1

Related Questions