Undefined symbols error related to “__mpf_struct” for OS X 10.10.2

让人想犯罪 __ 提交于 2019-12-10 20:40:50

问题


I am trying to compile a program from

https://github.com/davidsd/sdpb

with gcc-4.9, boost 1.57.0, gmp-6.0.0a, and mpfr-3.1.2 on OS X 10.10.2, but I keep getting errors seemingly related to the gmp and mpfr packages. I know somebody who successfully compiled on 10.9.5. Can anybody suggest a fix?


Undefined symbols for architecture x86_64: "operator<<(std::basic_ostream >&, __mpf_struct const*)", referenced from:

  operator<<(std::basic_ostream<char, std::char_traits<char> >&, Matrix const&) in Matrix.o
  operator<<(std::basic_ostream<char, std::char_traits<char> >&, SDPSolverParameters const&) in SDPSolverIO.o
  SDPSolver::saveSolution(SDPSolverTerminateReason, boost::filesystem::path const&)  in SDPSolverIO.o
  std::basic_ostream<char, std::char_traits<char> >& operator<< <__gmp_expr<__mpf_struct [1], __mpf_struct [1]> >(std::basic_ostream<char, std::char_traits<char> >&, std::vector<__gmp_expr<__mpf_struct [1], __mpf_struct [1]>, std::allocator<__gmp_expr<__mpf_struct [1], __mpf_struct [1]> > > const&) in SDPSolverIO.o
  void boost::serialization::save<boost::archive::text_oarchive>(boost::archive::text_oarchive&, __gmp_expr<__mpf_struct [1], __mpf_struct [1]> const&, unsigned int) in SDPSolverIO.o
  solveSDP(boost::filesystem::path const&, boost::filesystem::path const&, boost::filesystem::path const&, SDPSolverParameters) in main.o
  boost::detail::lexical_converter_impl<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, __gmp_expr<__mpf_struct [1], __mpf_struct [1]> >::try_convert(__gmp_expr<__mpf_struct [1], __mpf_struct [1]> const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&) in main.o
  ...

"operator>>(std::basic_istream >&, __mpf_struct*)", referenced from:

  void boost::program_options::validate<__gmp_expr<__mpf_struct [1], __mpf_struct [1]>, char>(boost::any&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, __gmp_expr<__mpf_struct [1], __mpf_struct [1]>*, long) in main.o

ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status make: *** [sdpb] Error 1


回答1:


On my (linux) system the linker command line ends up being

g++ -g -O2 -Wall -ansi -L/home/dsd/lib -Isrc/mpack -I/home/dsd/include -I/home/dsd/include/boost -fopenmp -D___MPACK_BUILD_WITH_GMP___ -MMD -lgomp -lgmp -lgmpxx -lboost_serialization -lboost_system -lboost_filesystem -lboost_timer -lboost_program_options -o sdpb obj/BlockDiagonalMatrix.o obj/main.o obj/Matrix.o obj/parse.o obj/SDP.o obj/SDPSolver.o obj/SDPSolverIO.o obj/mpack/iMlaenv.o obj/mpack/iRamax.o obj/mpack/Mlsame.o obj/mpack/Mxerbla.o obj/mpack/Raxpy.o obj/mpack/Rcopy.o obj/mpack/Rdot.o obj/mpack/Rgemm.o obj/mpack/RgemmParallel.o obj/mpack/Rgemv.o obj/mpack/Rger.o obj/mpack/Rgetf2.o obj/mpack/Rgetrf.o obj/mpack/Rgetrs.o obj/mpack/Rlae2.o obj/mpack/Rlaev2.o obj/mpack/Rlamch.o obj/mpack/Rlanst.o obj/mpack/Rlansy.o obj/mpack/Rlapy2.o obj/mpack/Rlarfb.o obj/mpack/Rlarf.o obj/mpack/Rlarfg.o obj/mpack/Rlarft.o obj/mpack/Rlartg.o obj/mpack/Rlascl.o obj/mpack/Rlaset.o obj/mpack/Rlasr.o obj/mpack/Rlasrt.o obj/mpack/Rlassq.o obj/mpack/Rlaswp.o obj/mpack/Rlatrd.o obj/mpack/Rnrm2.o obj/mpack/Rorg2l.o obj/mpack/Rorg2r.o obj/mpack/Rorgql.o obj/mpack/Rorgqr.o obj/mpack/Rorgtr.o obj/mpack/Rpotf2.o obj/mpack/Rpotf2Stabilized.o obj/mpack/Rpotrf.o obj/mpack/RpotrfStabilized.o obj/mpack/Rrot.o obj/mpack/Rrotg.o obj/mpack/Rscal.o obj/mpack/Rsteqr.o obj/mpack/Rsterf.o obj/mpack/Rswap.o obj/mpack/Rsyev.o obj/mpack/Rsymv.o obj/mpack/Rsyr2.o obj/mpack/Rsyr2k.o obj/mpack/Rsyrk.o obj/mpack/Rsytd2.o obj/mpack/Rsytrd.o obj/mpack/Rtrmm.o obj/mpack/Rtrmv.o obj/mpack/Rtrsm.o obj/mpack/Rtrsv.o obj/tinyxml2/tinyxml2.o

Looks like the ordering is wrong. The libraries should follow the object files

When I fixed it to

g++ -g -O2 -Wall -ansi -L/home/dsd/lib -Isrc/mpack -I/home/dsd/include -I/home/dsd/include/boost -fopenmp -D___MPACK_BUILD_WITH_GMP___ -MMD obj/BlockDiagonalMatrix.o obj/main.o obj/Matrix.o obj/parse.o obj/SDP.o obj/SDPSolver.o obj/SDPSolverIO.o obj/mpack/iMlaenv.o obj/mpack/iRamax.o obj/mpack/Mlsame.o obj/mpack/Mxerbla.o obj/mpack/Raxpy.o obj/mpack/Rcopy.o obj/mpack/Rdot.o obj/mpack/Rgemm.o obj/mpack/RgemmParallel.o obj/mpack/Rgemv.o obj/mpack/Rger.o obj/mpack/Rgetf2.o obj/mpack/Rgetrf.o obj/mpack/Rgetrs.o obj/mpack/Rlae2.o obj/mpack/Rlaev2.o obj/mpack/Rlamch.o obj/mpack/Rlanst.o obj/mpack/Rlansy.o obj/mpack/Rlapy2.o obj/mpack/Rlarfb.o obj/mpack/Rlarf.o obj/mpack/Rlarfg.o obj/mpack/Rlarft.o obj/mpack/Rlartg.o obj/mpack/Rlascl.o obj/mpack/Rlaset.o obj/mpack/Rlasr.o obj/mpack/Rlasrt.o obj/mpack/Rlassq.o obj/mpack/Rlaswp.o obj/mpack/Rlatrd.o obj/mpack/Rnrm2.o obj/mpack/Rorg2l.o obj/mpack/Rorg2r.o obj/mpack/Rorgql.o obj/mpack/Rorgqr.o obj/mpack/Rorgtr.o obj/mpack/Rpotf2.o obj/mpack/Rpotf2Stabilized.o obj/mpack/Rpotrf.o obj/mpack/RpotrfStabilized.o obj/mpack/Rrot.o obj/mpack/Rrotg.o obj/mpack/Rscal.o obj/mpack/Rsteqr.o obj/mpack/Rsterf.o obj/mpack/Rswap.o obj/mpack/Rsyev.o obj/mpack/Rsymv.o obj/mpack/Rsyr2.o obj/mpack/Rsyr2k.o obj/mpack/Rsyrk.o obj/mpack/Rsytd2.o obj/mpack/Rsytrd.o obj/mpack/Rtrmm.o obj/mpack/Rtrmv.o obj/mpack/Rtrsm.o obj/mpack/Rtrsv.o obj/tinyxml2/tinyxml2.o -lgomp -lgmp -lgmpxx -lboost_serialization -lboost_system -lboost_filesystem -lboost_timer -lboost_program_options -o sdpb 

It linked without error on my system

So in the Makefile, change the link command to

$(RESULT): $(OBJECTS)
    $(CC) $(CFLAGS) -o $@ $^ $(LIBS)


来源:https://stackoverflow.com/questions/28889744/undefined-symbols-error-related-to-mpf-struct-for-os-x-10-10-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!