我想使用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)的评论,我运行了“make -d --trace”,它提供了很多输出,但是不幸的是,对于“ undefined symbol ...”没有什么更确定的结论。
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
[...]

最佳答案

感谢David Hammen的评论及其中的链接:

Link OSX Homebrew Gfortran against libc++

我能够解决此问题:

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

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

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

  • LDLIBS + = $(如果$(call eq,$(OSTYPE),Darwin),-lgfortran -lc++ -lgcc
    -lgcc_eh -lSystem -nodefaultlibs,)
  • Makefile_lib:更改第57和62行(在if子句中检查Darwin = MACOS),也将-lstdc++替换为-lc++

    像苍蝇一样工作:)

    关于gcc - MacOS High Sierra上的链接错误: “Undefined symbols for architecture x86_64” std::__1,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50084214/

  • 10-11 21:55