fortran - Link OSX Homebrew Gfortran against libc++ -


i have project large c++ component able compile clang on osx (apple llvm version 6.1.0 (clang-602.0.49) (based on llvm 3.6.0svn). since osx not provide fortran compiler installed gfortran via homebrew.

compilation works fine, can not link compiled fortran code against c++ code compiled earlier: following error:

$ make fortran undefined symbols architecture x86_64:   "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(char const*) const", referenced from:       datafieldinfo::fromjson(jsonnode const&) in [...]   "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:       std::__1::vector<char, std::__1::allocator<char> >::allocate(unsigned long) in [...]       void std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::__push_back_slow_path<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in [...]       void std::__1::vector<jsonnode, std::__1::allocator<jsonnode> >::__push_back_slow_path<jsonnode const>(jsonnode const&) in [...] [...] 

which indicates me i'm having linking problem between fortran , c++ part.

how link fortran part libc++? possible gfortran provided homebrew? best course of action solve issue? should try linking clang++?

you need explictly tell gfortran link against clangs c++ library (it default gnu c++ library).

for example, if have fortran , c++ file, each compiled respective compilers (note: gfortran-mp-5 gnu fortran 5.1 provided macports)

gfortran-mp-5 -c gfortest.f90 clang++ -c clangtest.cc 

you can link resulting objects gfortran follows:

gfortran-mp-5 -lc++ -o test-f gfortest.o clangtest.o 

the -lc++ flag tells gfortran link in libc++, resolve undefined symbols.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -