2
votes

I am working on a project that requires CGAL running on a mac and am very new to C++ in general. I installed CGAL using macports using the command

sudo port install cgal

The installation completed and the .h files were placed in

/opt/local/include/cgal

I copied the tutorial program into a .cpp file and compiled using

g++ -lcgal -I/opt/local/include/ vec.cpp

This returns the error

ld: library not found for -lcgal clang: error: linker command failed with exit code 1 (use -v to see invocation)

g++ -lcgal -v -I/opt/local/include/ vec.cpp

returns

Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) Target: x86_64-apple-darwin13.2.0 Thread model: posix "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name vec.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1 -I /opt/local/include -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/sujeath/C practice -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/tm/bgg4k0xs4v36pzwxvsrqtsb00000gn/T/vec-0a56fb.o -x c++ vec.cpp clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin13.2.0 ignoring nonexistent directory "/usr/include/c++/v1" \#include "..." search starts here: \#include search starts here: /opt/local/include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1 /usr/local/include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/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. "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -o a.out /var/folders/tm/bgg4k0xs4v36pzwxvsrqtsb00000gn/T/vec-0a56fb.o -lcgal -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/lib/darwin/libclang_rt.osx.a ld: library not found for -lcgal clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am using Mavericks BTW and gnu gcc

Thanks!

1
Look for the -L option in the doc of your compiler or linker.Marc Glisse
Is it different from -l (lower case)?fizzybear

1 Answers

0
votes

so, first of all, I'm new on stackoverflow and actually would have preferred to add a comment rather then posting an answer as I'm pretty new to the C++/Mac world too.

Stated this disclaimer I would like to point out a two things that I saw "parsing" the output you posted:

  1. You're calling g++, however, you're using clang to compile (default on OS X Mavericks) as /usr/bin/g++ points to /usr/bin/clang++
  2. I think the cgal library is not on your search path. Marc Glisse pointed you to the -L option of the ld command that let you define further search directories. Probably -L/opt/local/lib might work for you using Macports (I didn't use Macports for a long time so I'm not sure if that's the correct path for the libraries).

Hope this helps.