Zac Schulwolf
Zac Schulwolf

Reputation: 59

C++ libraries on mac not compiling with g++ my_program.cpp -o my_program

I have recently attempted to download (using Homebrew) Eigen (a C++ library) and compile the example program on Eigen's website https://eigen.tuxfamily.org/dox/GettingStarted.html.

I get a error in terminal that is:

EigenExample1.cpp:10:10: fatal error: 'Eigen/Dense' file not found #include < Eigen/Dense >

I have double checked to make sure homebrew was updated and the eigen3 folder does exist in /usr/local/include. In addition I do have command line tools installed and cpp -v returns:

Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 274.2 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0 -I /usr/include -fdebug-compilation-dir /Users/name/MNISTNeuralNetwork/Eigen -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -traditional-cpp -o - -x c -
clang -cc1 version 8.0.0 (clang-800.0.42.1) default target x86_64-apple-darwin16.3.0
ignoring duplicate directory "/usr/include"
  as it is a non-system directory that duplicates a system directory
\#include "..." search starts here:
\#include <...> search starts here:
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.

Upvotes: 1

Views: 387

Answers (1)

johnsyweb
johnsyweb

Reputation: 141810

When you install using Homebrew, the Eigen directory is nested inside include/eigen3. You should be able to compile with the following flags:

g++ -I "$(brew --prefix eigen)/include/eigen3" my_program.cpp -o my_program

Indeed, this is how the Homebrew installation is tested.

Upvotes: 2

Related Questions