【问题标题】:Link errors on MacOS High Sierra: "Undefined symbols for architecture x86_64" std::__1MacOS High Sierra 上的链接错误:“架构 x86_64 的未定义符号”std::__1
【发布时间】:2018-04-29 07:08:45
【问题描述】:

我想玩一下 MAD-X(有条不紊的加速器设计;http://madx.web.cern.ch/madx/)的代码。我必须承认我对 c、c++、编译等完全是新手。

我从 Mad-X git 存储库 (https://github.com/MethodicalAcceleratorDesign/MAD-X) 将源代码下载到了我的 MacBook Pro(2016 年,英特尔),第一步我想在不修改的情况下编译代码。为此,我运行

make madx-macosx64-gnu

在编译过程中运行并带有一些警告,但链接失败并出现许多错误:

*** Compiling madx_ptc_track_run.f90
*** Compiling madx_ptc_trackcavs.f90
*** Compiling ptc_export_xml.f90
*** Compiling St_pointers.f90
*** Compiling madx_ptc_twiss.f90
*** Compiling user2_photon.f90
*** Compiling madx_ptc_normal.f90
*** Compiling wrap.f90
*** Linking build/madx-macosx64-gnu
Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const", referenced from:
      SeqElList::sbend_from_rbend(element const*) in mad_mkthin.o
  "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
      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 mad_6track_name_mangler.o
      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> > > >::vector(unsigned long) in mad_mkthin.o
      void std::__1::vector<element*, std::__1::allocator<element*> >::__push_back_slow_path<element* const&>(element* const&) in mad_mkthin.o
      void std::__1::vector<OneElementWithSlices*, std::__1::allocator<OneElementWithSlices*> >::__push_back_slow_path<OneElementWithSlices* const&>(OneElementWithSlices* const&) in mad_mkthin.o
      void std::__1::vector<sequence*, std::__1::allocator<sequence*> >::__push_back_slow_path<sequence* const&>(sequence* const&) in mad_mkthin.o
  "std::__1::__basic_string_common<true>::__throw_length_error() const", referenced from:
      _NameMangler_mangle in mad_6track_name_mangler.o
      _NameMangler_demangle in mad_6track_name_mangler.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(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 mad_6track_name_mangler.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(char, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mad_6track_name_mangler.o
      slice_sequence(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, sequence*) in mad_mkthin.o
      ElementListWithSlices::find_slice(element const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mad_mkthin.o
      SeqElList::sbend_from_rbend(element const*) in mad_mkthin.o
      ...
  "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from
[...]

你能给我建议如何编译它吗?例如,有几个 Makefile,一个用于 MacOS,但我不确定如何正确使用它们。

基于 Ulrich Eckhardt 的 cmets,我运行了“make -d --trace”,它提供了很多输出,但不幸的是,在“未定义的符号...”上没有更多结论性的东西

MANY LINES BEFORE        
Pruning file 'Sl_family.o'.
        Pruning file 'So_fitting.o'.
        Pruning file 'm_real_polymorph.o'.
        Pruning file 'k_tpsalie_analysis.o'.
   Finished prerequisites of target file 'build/madx64'.
  Must remake target 'build/madx64'.
make/linker.rules:28: update target 'build/madx64' due to: mad_elem.o mad_plot.o mad_write.o mad_dict.o mad_elemerr.o mad_str.o mad_survey.o mad_macro.o mad_option.o mad_emit.o mad_name.o mad_beam.o mad_match.o mad_cmdpar.o mad_sdds.o mad_const.o mad_array.o mad_node.o mad_cmdin.o mad_aper.o mad_vec.o mad_track.o mad_gvar.o mad_parse.o mad_ibs.o mad_time.o mad_cmd.o mad_table.o mad_twiss.o mad_main.o mad_6track.o mad_spch.o mad_ptcknobs.o mad_core.o mad_mem.o mad_sxf.o mad_util.o mad_eval.o mad_ptc.o mad_gcst.o mad_stream.o mad_exec.o mad_var.o mad_touschek.o mad_gxx11c.o mad_orbit.o mad_expr.o mad_regex.o mad_api.o mad_dynap.o mad_seq.o mad_inter.o mad_sodd.o mad_match2.o mad_select.o mad_rand.o mad_err.o mad_range.o mad_synrad.o mad_rplot.o mad_mkthin.o mad_6track_name_mangler.o touschek.o wrap.o trrun.o matchjc.o matchlib.o twiss.o madx_ptc_module.o dynap.o emit.o madx_ptc_track_run.o gxx11.o madx_ptc_script.o ibsdb.o madx_ptc_normal.o match.o orbf.o plot.o madx_ptc_trackcavs.o survey.o user2_photon.o madx_ptc_knobs.o matchlib2.o matchsa.o madx_ptc_twiss.o sodd.o madx_ptc_distrib.o util.o resindex.o madx_ptc_setcavs.o madx_ptc_eplacement.o ptc_export_xml.o madx_ptc_intstate.o mad_inif_f.o Sc_euclidean.o cc_dabnew.o b_da_arrays_all.o Spb_fake_gino_sub.o Se_status.o Sb_sagan_pol_arbitrary.o Si_def_element.o Sm_tracking.o Sd_frame.o Sf_def_all_kinds.o Sp_keywords.o Sr_spin.o cb_da_arrays_all.o Sq_orbit_ptc.o St_pointers.o Sg_sagan_wiggler.o d_lielib.o Sma0_beam_beam_ptc.o Sn_mad_like.o c_dabnew_berz.o h_definition.o Ci_tpsa.o Sh_def_kind.o a_scratch_size.o Sra_fitting.o j_tpsalie.o Sa_extend_poly.o Sma_multiparticle.o n_complex_polymorph.o Sk_link_list.o l_complex_taylor.o c_dabnew.o o_tree_element.o i_tpsa.o Sl_family.o So_fitting.o m_real_polymorph.o k_tpsalie_analysis.o
echo "*** Linking build/madx64"
Putting child 0x7f93f354ff60 (build/madx64) PID 34699 on the chain.
Live child 0x7f93f354ff60 (build/madx64) PID 34699 
*** Linking build/madx64
Reaping winning child 0x7f93f354ff60 PID 34699 
gfortran -m64 -O3 -fmax-stack-var-size=65536 -Wl,-no_compact_unwind -Wl,-no_pie -o build/madx64 build/Darwin64/mad_elem.o build/Darwin64/mad_plot.o build/Darwin64/mad_write.o build/Darwin64/mad_dict.o build/Darwin64/mad_elemerr.o build/Darwin64/mad_str.o build/Darwin64/mad_survey.o build/Darwin64/mad_macro.o build/Darwin64/mad_option.o build/Darwin64/mad_emit.o build/Darwin64/mad_name.o build/Darwin64/mad_beam.o build/Darwin64/mad_match.o build/Darwin64/mad_cmdpar.o build/Darwin64/mad_sdds.o build/Darwin64/mad_const.o build/Darwin64/mad_array.o build/Darwin64/mad_node.o build/Darwin64/mad_cmdin.o build/Darwin64/mad_aper.o build/Darwin64/mad_vec.o build/Darwin64/mad_track.o build/Darwin64/mad_gvar.o build/Darwin64/mad_parse.o build/Darwin64/mad_ibs.o build/Darwin64/mad_time.o build/Darwin64/mad_cmd.o build/Darwin64/mad_table.o build/Darwin64/mad_twiss.o build/Darwin64/mad_main.o build/Darwin64/mad_6track.o build/Darwin64/mad_spch.o build/Darwin64/mad_ptcknobs.o build/Darwin64/mad_core.o build/Darwin64/mad_mem.o build/Darwin64/mad_sxf.o build/Darwin64/mad_util.o build/Darwin64/mad_eval.o build/Darwin64/mad_ptc.o build/Darwin64/mad_gcst.o build/Darwin64/mad_stream.o build/Darwin64/mad_exec.o build/Darwin64/mad_var.o build/Darwin64/mad_touschek.o build/Darwin64/mad_gxx11c.o build/Darwin64/mad_orbit.o build/Darwin64/mad_expr.o build/Darwin64/mad_regex.o build/Darwin64/mad_api.o build/Darwin64/mad_dynap.o build/Darwin64/mad_seq.o build/Darwin64/mad_inter.o build/Darwin64/mad_sodd.o build/Darwin64/mad_match2.o build/Darwin64/mad_select.o build/Darwin64/mad_rand.o build/Darwin64/mad_err.o build/Darwin64/mad_range.o build/Darwin64/mad_synrad.o build/Darwin64/mad_rplot.o build/Darwin64/mad_mkthin.o build/Darwin64/mad_6track_name_mangler.o build/Darwin64/touschek.o build/Darwin64/wrap.o build/Darwin64/trrun.o build/Darwin64/matchjc.o build/Darwin64/matchlib.o build/Darwin64/twiss.o build/Darwin64/madx_ptc_module.o build/Darwin64/dynap.o build/Darwin64/emit.o build/Darwin64/madx_ptc_track_run.o build/Darwin64/gxx11.o build/Darwin64/madx_ptc_script.o build/Darwin64/ibsdb.o build/Darwin64/madx_ptc_normal.o build/Darwin64/match.o build/Darwin64/orbf.o build/Darwin64/plot.o build/Darwin64/madx_ptc_trackcavs.o build/Darwin64/survey.o build/Darwin64/user2_photon.o build/Darwin64/madx_ptc_knobs.o build/Darwin64/matchlib2.o build/Darwin64/matchsa.o build/Darwin64/madx_ptc_twiss.o build/Darwin64/sodd.o build/Darwin64/madx_ptc_distrib.o build/Darwin64/util.o build/Darwin64/resindex.o build/Darwin64/madx_ptc_setcavs.o build/Darwin64/madx_ptc_eplacement.o build/Darwin64/ptc_export_xml.o build/Darwin64/madx_ptc_intstate.o build/Darwin64/mad_inif_f.o build/Darwin64/Sc_euclidean.o build/Darwin64/cc_dabnew.o build/Darwin64/b_da_arrays_all.o build/Darwin64/Spb_fake_gino_sub.o build/Darwin64/Se_status.o build/Darwin64/Sb_sagan_pol_arbitrary.o build/Darwin64/Si_def_element.o build/Darwin64/Sm_tracking.o build/Darwin64/Sd_frame.o build/Darwin64/Sf_def_all_kinds.o build/Darwin64/Sp_keywords.o build/Darwin64/Sr_spin.o build/Darwin64/cb_da_arrays_all.o build/Darwin64/Sq_orbit_ptc.o build/Darwin64/St_pointers.o build/Darwin64/Sg_sagan_wiggler.o build/Darwin64/d_lielib.o build/Darwin64/Sma0_beam_beam_ptc.o build/Darwin64/Sn_mad_like.o build/Darwin64/c_dabnew_berz.o build/Darwin64/h_definition.o build/Darwin64/Ci_tpsa.o build/Darwin64/Sh_def_kind.o build/Darwin64/a_scratch_size.o build/Darwin64/Sra_fitting.o build/Darwin64/j_tpsalie.o build/Darwin64/Sa_extend_poly.o build/Darwin64/Sma_multiparticle.o build/Darwin64/n_complex_polymorph.o build/Darwin64/Sk_link_list.o build/Darwin64/l_complex_taylor.o build/Darwin64/c_dabnew.o build/Darwin64/o_tree_element.o build/Darwin64/i_tpsa.o build/Darwin64/Sl_family.o build/Darwin64/So_fitting.o build/Darwin64/m_real_polymorph.o build/Darwin64/k_tpsalie_analysis.o -L/usr/X11/lib -lX11 -lstdc++ -lm
Live child 0x7f93f354ff60 (build/madx64) PID 34700 
Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const", referenced from:
      SeqElList::sbend_from_rbend(element const*) in mad_mkthin.o
  "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
      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> > > >::vector(unsigned long) in mad_mkthin.o
      void std::__1::vector<element*, std::__1::allocator<element*> >::__push_back_slow_path<element* const&>(element* const&) in mad_mkthin.o
      void std::__1::vector<OneElementWithSlices*, std::__1::allocator<OneElementWithSlices*> >::__push_back_slow_path<OneElementWithSlices* const&>(OneElementWithSlices* const&) in mad_mkthin.o
      void std::__1::vector<sequence*, std::__1::allocator<sequence*> >::__push_back_slow_path<sequence* const&>(sequence* const&) in mad_mkthin.o
      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 mad_6track_name_mangler.o
  "std::__1::__basic_string_common<true>::__throw_length_error() const", referenced from:
      slice_sequence(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, sequence*) in mad_mkthin.o
      ElementListWithSlices::find_slice(element const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mad_mkthin.o
      SeqElList::sbend_from_rbend(element const*) in mad_mkthin.o
      my_dump_command(command const*) in mad_mkthin.o
      SeqElList::create_thick_slice(element*, int)  in mad_mkthin.o
      SeqElList::slice_this_node()      in mad_mkthin.o
      create_bend_dipedge_element(element*, bool) in mad_mkthin.o
[...]

【问题讨论】:

  • 我认为如果你运行make-v,它会给你它执行的实际命令,因为这是重要的信息。无论如何,简而言之,该错误意味着C++标准库的某些部分无法找到。
  • 您好,乌尔里希,感谢您的提示。 “make -v”似乎是“版本”命令。根据您的提示,我使用选项“-d”运行 make ,它为编译生成更多输出,但链接输出相同:(
  • 尝试使用--trace
  • 这是一条评论,因为我看到了问题,但没有看到解决方案。问题在于gfortran-lstdc++ 选项。这就是 gnu c++ 标准库。缺少对 std::__1::basic_string 之类的引用意味着您的某些代码已被编译为调用 LLVM c++ 标准库而不是 GNU c++ 标准库。混合和匹配这两个标准库是一个非常糟糕的主意。猫狗,生活在一起,...

标签: gcc makefile compiler-errors g++ gfortran


【解决方案1】:

感谢David Hammen的cmets和里面的链接:

Link OSX Homebrew Gfortran against libc++

我能够解决这个问题:

我在文件中搜索了所有出现的“-lstdc++”,并在以下文件中找到了命中:

  • linker.g95(无需编辑...)
  • linker.gfortran:从第 44 行更改

    LDLIBS += $(if $(call eq,$(OSTYPE),Darwin),-lgfortran -lstdc++ -lgcc -lgcc_eh -lSystem -nodefaultlibs,)

  • LDLIBS += $(if $(call eq,$(OSTYPE),Darwin),-lgfortran -lc++ -lgcc -lgcc_eh -lSystem -nodefaultlibs,)

  • Makefile_lib:更改第 57 和 62 行(在 if 子句中检查 Darwin = MACOS)并将 -lstdc++ 也替换为 -lc++

像苍蝇一样工作:)

【讨论】:

    猜你喜欢
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-03
    • 2017-12-23
    相关资源
    最近更新 更多