c++ - Setting a System Wide path in Mac Yosemite -


i have installed boost libraries. using eclipse make simple boost project.

#include <stdio.h> #include <boost/filesystem.hpp>  int main() {     boost::filesystem::path path("/users/schoen"); // random pathname    bool result = boost::filesystem::is_directory(path);     printf("path directory : %d\n", result);     return 0; } 

i have set path of include folder , library folder in properties of project. getting runtime error: dyld: library not loaded: libboost_system.dylib. solve problem, went run configuration , set environment variable dyld_library_path /users/myname/documents/softwares/boost_1_59_0/stage/lib. has solved problem.

what need: don't want set environment variable each boost-based project. therefore, tried set .bash_profile. wrote following lines in .bash_profile.

# following lines boost library dyld_library_path=/users/myname/documents/softwares/boost_1_59_0/stage/lib export dyld_library_path 

problem: setting variable in .bash_profile, able run program through terminal. program runs if open ide (e.g. eclipse) via terminal , run application. apparently, .bash_profile can set variable terminal applications. how can set path windowed applications too?

ps: path setting problem not boost only, have similar things other libraries (such opencv build/installed in local directory).

rather adding system wide path this, should add rpath libraries applications depend on boost. add rpath option, project properties -> c/c++ build -> settings -> miscellaneous , in linker flags add:

-wl,-rpath,/users/myname/documents/softwares/boost_1_59_0/stage/lib 

(this if linker g++ or clang++, example)

if linker ld explicitly, option is

-rpath /users/myname/documents/softwares/boost_1_59_0/stage/lib 

although may need add -macos_version_min 10.5 (or newer - 10.8 - depends on os you're building on).

this cause applications built search there libraries default locations.

although location me looks bit volatile

turns out boost builds without setting library name include @rpath in install name, means when set -rpath in build, because libraries aren't mentioned in @rpath, won't find them @ run time. workaround explicitly set install name boost libraries, , internal references own libraries:

#!/bin/bash -p   in *.dylib;      # set rpath      install_name_tool -id @rpath/$i $i      lib in $(otool -l $i | grep libboost | awk '{print $1}');          if [[ -f $lib ]];              install_name_tool -change $lib @rpath/$lib $i          fi      done  done  

this means binaries linked these boost libraries respect rpath setting.

you can repeat similar process other libraries ensure respect rpath. key element install_name_tool -id "@rpath/libstuff.dylib" libstuff.dylib, says when link library record reference @rpath/libstuff.dylib. if libraries don't have set.

secondly, internal references dependent libraries, -change option alters references absolute name rpath relative name e.g. install_name_tool -change "libstuff.dylib" "@rpath/libstuff.dylib" libdependsonlibstuff.dylib. can performed on linked binary.

if still want set environment variable, there options available should getting solution works in case.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -