How to let g++ search for library directory /opt/local/lib/

Jason Swails jason.swails at
Sat Mar 16 08:52:47 PDT 2013

On Sat, Mar 16, 2013 at 11:40 AM, Peng Yu <pengyu.ut at> wrote:

> Hi,
> g++ does not search /opt/local/lib/ by default. Does anybody know how
> to let it search /opt/local/lib/ by default?
> ~/linux/test/cpp/library/pcrecpp$ port select gcc
> Available versions for gcc:
>         apple-gcc42 (active)
>         llvm-gcc42
>         mp-gcc45
>         mp-gcc47
>         none
> ~/linux/test/cpp/library/pcrecpp$ g++ main.o -lpcrecpp  -o main
> -L/opt/local/lib/
> ~/linux/test/cpp/library/pcrecpp$ g++ main.o -lpcrecpp  -o main
> ld: library not found for -lpcrecpp
> collect2: ld returned 1 exit status

You should activate one of the MacPorts compilers instead of the apple
version.  mp-gcc47 and mp-gcc45 should automatically search in
/opt/local/lib for libraries.

Alternatively, you can add /opt/local/lib to LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=/opt/local/lib:$LD_LIBRARY_PATH
g++ main.o -lpcrecpp -o main

Good luck,

Jason M. Swails
Quantum Theory Project,
University of Florida
Ph.D. Candidate
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the macports-users mailing list