0

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

Kyler
  • 23
  • 6
  • `CPLUSPLUS = g++ -ITBB_INCLUDE_PATH -LTBB_LIBRARY_PATH` is not such a good idea. I'd place the `-ITBB_INCLUDE_PATH` and `-LTBB_LIBRARY_PATH` in the rules that use them, not toss them into a variable typically used to name the compiler. That's packing too much responsibility into one place and also could be causing your bug. – user4581301 Apr 16 '20 at 19:05
  • You do not add libraries (`-ltbb`) into compile lines (`-c` lines that create object files). Libraries are only added in the link line. – MadScientist Apr 16 '20 at 19:09
  • @user4581301 Thank you both for your help, I have updated my makefile with your suggestions, but I am still getting the same error. https://www.codepile.net/pile/lDwJ445v – Kyler Apr 16 '20 at 19:40

1 Answers1

1

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.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • Great answer. Might be worth adding a bit about or a link if you've gone one (drop it myself if I had one) to what `$@` and `$^` are doing. That's some head-popping voodoo to the uninitiated. – user4581301 Apr 16 '20 at 21:24
  • Meh. Stack overflow FTW: [What do the makefile symbols $@ and $< mean?](https://stackoverflow.com/questions/3220277/what-do-the-makefile-symbols-and-mean). Why did I even try google first? – user4581301 Apr 16 '20 at 21:26
  • Thank you both once again for your help, I really appreciate it. I have updated the post with the current Makefile that I have. After reading the post that was linked, I understand the $@ $^ symbols as well. However, I am still getting the same error when attempting to link. – Kyler Apr 16 '20 at 22:25
  • 1
    Well, your variable usage is wrong. In the value of `TBB_LIBRARY_PATH` you say `-L`. Then in the link line you use `-L$(TBB_LIBRARY_PATH)`. That means what you actually get is `-L-L`. Remove the `-L` from one or the other location. My recommendation is to remove it from the `TBB_LIBRARY_PATH` variable. – MadScientist Apr 16 '20 at 22:28
  • 1
    When asking for help, it's very useful to post the actual command line that failed (the link line that make printed out before the errors). By looking at that you should be able to pretty easily see what the problem is. – MadScientist Apr 16 '20 at 22:29
  • Thank you, I have just updated it with the changes to the variables and included my output. I should be able to fix the omp errors by adding -fopenmp back into the linking line. However, the rest seem to be still related to TBB not linking correctly. – Kyler Apr 16 '20 at 22:38
  • Please don't post screenshots to SO. Just plain text (but formatted properly). Thanks. Well, those errors are not related to your makefile as far as I can see so someone else will have to help you. You should, however, follow my very first advice above and always use forward slashes not backslashes as directory separators. I'm not sure it will help here because I would expect that you'd get an error about not finding the `tbb` library, but you should do it anyway. – MadScientist Apr 16 '20 at 22:47