ld library path not working under OS X 10.9

后端 未结 3 1539
执笔经年
执笔经年 2021-01-23 06:03

I\'ve been trying to figure out why g++ cannot link a program with the armadillo library. The problem is simple:

macbook-pro:arma-xc jmlopez$ g++-4.         


        
3条回答
  •  [愿得一人]
    2021-01-23 06:39

    It is likely that your homebrew g++ was compiled with a custom prefix. The prefix for gcc is usually /usr, meaning that it will look for binaries in /usr/bin, headers in /usr/include and libraries in /usr/lib. If you've compiled with a custom prefix (/usr/local/Cellar/gcc/4.9.1/ in this case, it seems) the it won't look in /usr/lib.

    LD_LIBRARY_PATH is how you tell the runtime linker where to look for libraries. So if you had linked to /usr/my/bizarre/lib/path/libmylib.so, then you run it like this:

    > LD_LIBRARY_PATH=/usr/my/bizarre/lib/path myprog
    

    To tell g++ where to find libraries, you use the -L command-line option. So your command-line should look like this:

    g++-4.9 inputs-arma.cpp -L/usr/lib -larmadillo
    

提交回复
热议问题