问题
I ran brew install tbb on my mac os sierra device. After running this i should be able to include #include into my c++ projects right? For some reason when I compile these files are not found. Help would be appreciated
回答1:
A few things...
Check the options on packages
Before you install any homebrew
packages, get in the habit of checking the available options rather than just accepting the default ones. It often gives you insights into features that are available which you are unaware of. So, for tbb
:
brew options tbb
Output
--c++11
Build using C++11 mode
So, it is probably worth using:
brew install tbb --c++11
or
brew reinstall tbb --c++11
Find the include files and libraries yourself first
If you are trying to include a header file, try looking for it yourself first, using find
:
find /usr /opt concurrent_queue.h
Output
/usr/local/Cellar/tbb/4.4-20160916/include/tbb/concurrent_queue.h
So there is only one concurrent_queue.h
on my system. Now we need to tell the compiler how to find it. If you look in /usr/local/include
, which is where homebrew
puts headers, you will see this:
ls -l /usr/local/include | grep tbb
lrwxr-xr-x 1 mark admin 38 5 Oct 09:10 tbb -> ../Cellar/tbb/4.4-20160916/include/tbb
So, the tbb
headers are in /usr/local/include/tbb
(which is a symlink to homebrew
's Cellar), so you need to make sure your compiler is looking in /usr/local/include
.
g++-6 -I/usr/local/include ...
Remember you can check where your compiler is looking by using -v
, like this:
g++-6 -v ...
Once you helped the compiler find the header files (#includes), you will then need to help the linker find the libraries, so your command will become:
g++-6 -I/usr/local/include program.cpp -o program -L /usr/local/lib -ltbb
来源:https://stackoverflow.com/questions/39866845/need-help-getting-intel-tbb-working