boutproject / BOUT-dev

BOUT++: Plasma fluid finite-difference simulation code in curvilinear coordinate systems
http://boutproject.github.io/
GNU Lesser General Public License v3.0
182 stars 95 forks source link

Linking fails for tests on Mac OS (CMake, homebrew) #2419

Open akrause2014 opened 3 years ago

akrause2014 commented 3 years ago

I'm trying to compile BOUT++ and run the tests on MacOS.

I installed the dependencies using homebrew and the compilation with CMake completes successfully.

When I run the target check-unit-tests it fails with the following error:

cmake --build build_dev -j 2 --target check-unit-tests
Consolidate compiler generated dependencies of target pvode
[  1%] Building CXX object tests/unit/externalpackages/googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[  5%] Built target pvode
Consolidate compiler generated dependencies of target pvpre
[  6%] Built target pvpre
Consolidate compiler generated dependencies of target bout++
[ 70%] Built target bout++

[ ... ]

[100%] Linking CXX executable serial_tests
ld: can't map file, errno=22 file '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/System/Library/Frameworks/CoreFoundation.framework' for architecture x86_64
collect2: error: ld returned 1 exit status
make[3]: *** [tests/unit/serial_tests] Error 1
make[2]: *** [tests/unit/CMakeFiles/serial_tests.dir/all] Error 2
make[1]: *** [CMakeFiles/check-unit-tests.dir/rule] Error 2
make: *** [check-unit-tests] Error 2

From a quick search it seems that the problem is that .framework is a directory not a library file so it needs to be linked with "-L". However I'm not sure if that is the root of the problem, given that I installed g++ with homebrew should it be linking the XCode frameworks at all? Or could the path be fixed in CMake (I'm not an expert)?

Any help would be appreciated.

dschwoerer commented 3 years ago

I don't use macOS, so I can only guess. It would be useful to have CMakeCache.txt to be able to guess how that folder got there.

Besides that, I can recommend Linux, for example Fedora, which is much better tested. On Fedora you can install BOUT++ with sudo dnf '*bout++*'. If you don't want to switch completely to Linux, you could dual boot or use containers (docker, podman, charliecloud, ... - again, not sure which work on macOS)

ZedThree commented 3 years ago

Hi @akrause2014, I think I've possibly worked this out: it looks like it's coming from how we link against Libuuid.

Please could you set -DBOUT_USE_UUID_SYSTEM_GENERATOR=off when you configure BOUT++ using CMake, and try that?

akrause2014 commented 3 years ago

Thanks @ZedThree - that got me a little further. Now I'm getting lots of these errors (still target check-unit-tests):

[100%] Linking CXX executable serial_tests
Undefined symbols for architecture x86_64:
  "__ZN6netCDF6NcFileC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS0_8FileModeE", referenced from:
      __ZN4bout12experimental13OptionsNetCDF4readEv in libbout++.a(options_netcdf.cxx.o)
      __ZN4bout12experimental13OptionsNetCDF5writeERK7Options in libbout++.a(options_netcdf.cxx.o)
      __ZN5Ncxx45openrEPKc in libbout++.a(ncxx4.cxx.o)
      __ZN5Ncxx45openwEPKcb in libbout++.a(ncxx4.cxx.o)
  "__ZNK6netCDF5NcAtt9getValuesERNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
      __ZN12_GLOBAL__N_19readGroupERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKN6netCDF7NcGroupER7Options in libbout++.a(options_netcdf.cxx.o)
      __ZN5Ncxx412getAttributeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_RS5_ in libbout++.a(ncxx4.cxx.o)
  "__ZNK6netCDF5NcVar6getAttERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
      __ZN5Ncxx412getAttributeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_RS5_ in libbout++.a(ncxx4.cxx.o)
      __ZN5Ncxx412getAttributeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_Ri in libbout++.a(ncxx4.cxx.o)
      __ZN5Ncxx412getAttributeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_Rd in libbout++.a(ncxx4.cxx.o)
  "__ZNK6netCDF5NcVar6getVarERKSt6vectorImSaImEES5_Pc", referenced from:
      __ZN5Ncxx44readEPcPKci in libbout++.a(ncxx4.cxx.o)
      __ZN5Ncxx48read_recEPcPKci in libbout++.a(ncxx4.cxx.o)
  "__ZNK6netCDF5NcVar6getVarERKSt6vectorImSaImEES5_Pd", referenced from:
      __ZN5Ncxx44readEPdPKciii in libbout++.a(ncxx4.cxx.o)
      __ZN5Ncxx49read_perpEPdRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEii in libbout++.a(ncxx4.cxx.o)
      __ZN5Ncxx48read_recEPdPKciii in libbout++.a(ncxx4.cxx.o)
      __ZN5Ncxx413read_rec_perpEPdRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEii in libbout++.a(ncxx4.cxx.o)
  "__ZNK6netCDF5NcVar6getVarERKSt6vectorImSaImEES5_Pi", referenced from:
      __ZN5Ncxx44readEPiPKciii in libbout++.a(ncxx4.cxx.o)
      __ZN5Ncxx48read_recEPiPKciii in libbout++.a(ncxx4.cxx.o)
  "__ZNK6netCDF5NcVar6putAttERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_6NcTypeEd", referenced from:
      __ZN12_GLOBAL__N_115NcPutAttVisitorclIdEEvRKT_ in libbout++.a(options_netcdf.cxx.o)
      __ZN5Ncxx412setAttributeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_d in libbout++.a(ncxx4.cxx.o)
  "__ZNK6netCDF5NcVar6putAttERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_6NcTypeEf", referenced from:
      __ZN12_GLOBAL__N_115NcPutAttVisitorclIfEEvRKT_ in libbout++.a(options_netcdf.cxx.o)
  "__ZNK6netCDF5NcVar6putAttERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_6NcTypeEi", referenced from:
      __ZN12_GLOBAL__N_115NcPutVarVisitorclI9FieldPerpEEvRKT_ in libbout++.a(options_netcdf.cxx.o)
      __ZN12_GLOBAL__N_115NcPutAttVisitorclIbEEvRKT_ in libbout++.a(options_netcdf.cxx.o)
      __ZN12_GLOBAL__N_115NcPutAttVisitorclIiEEvRKT_ in libbout++.a(options_netcdf.cxx.o)
      __ZN5Ncxx412setAttributeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_i in libbout++.a(ncxx4.cxx.o)

.
.
.
ZedThree commented 3 years ago

These are all symbols from the netCDF C++ API, e.g. netCDF::NcFile::NcFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, netCDF::NcFile::FileMode). You're successfully compiling it, so the headers must be available, but something's going wrong in the linking.

Please could you build with the --verbose flag, something like cmake --build build --verbose, and post the linking command?

akrause2014 commented 3 years ago

Is this what you're after?

[ 98%] Linking CXX static library lib/libbout++.a
/usr/local/Cellar/cmake/3.21.2/bin/cmake -P CMakeFiles/bout++.dir/cmake_clean_target.cmake
/usr/local/Cellar/cmake/3.21.2/bin/cmake -E cmake_link_script CMakeFiles/bout++.dir/link.txt --verbose=1
/usr/bin/ar qc lib/libbout++.a CMakeFiles/bout++.dir/src/bout++.cxx.o CMakeFiles/bout++.dir/src/bout++-time.cxx.o CMakeFiles/bout++.dir/src/field/field.cxx.o CMakeFiles/bout++.dir/src/field/field2d.cxx.o CMakeFiles/bout++.dir/src/field/field3d.cxx.o CMakeFiles/bout++.dir/src/field/field_data.cxx.o CMakeFiles/bout++.dir/src/field/field_factory.cxx.o CMakeFiles/bout++.dir/src/field/fieldgenerators.cxx.o CMakeFiles/bout++.dir/src/field/fieldgroup.cxx.o CMakeFiles/bout++.dir/src/field/fieldperp.cxx.o CMakeFiles/bout++.dir/src/field/generated_fieldops.cxx.o CMakeFiles/bout++.dir/src/field/globalfield.cxx.o CMakeFiles/bout++.dir/src/field/initialprofiles.cxx.o CMakeFiles/bout++.dir/src/field/vecops.cxx.o CMakeFiles/bout++.dir/src/field/vector2d.cxx.o CMakeFiles/bout++.dir/src/field/vector3d.cxx.o CMakeFiles/bout++.dir/src/field/where.cxx.o CMakeFiles/bout++.dir/src/fileio/datafile.cxx.o CMakeFiles/bout++.dir/src/fileio/dataformat.cxx.o CMakeFiles/bout++.dir/src/fileio/formatfactory.cxx.o CMakeFiles/bout++.dir/src/fileio/impls/hdf5/h5_format.cxx.o CMakeFiles/bout++.dir/src/fileio/impls/netcdf/nc_format.cxx.o CMakeFiles/bout++.dir/src/fileio/impls/netcdf4/ncxx4.cxx.o CMakeFiles/bout++.dir/src/fileio/impls/pnetcdf/pnetcdf.cxx.o CMakeFiles/bout++.dir/src/invert/fft_fftw.cxx.o CMakeFiles/bout++.dir/src/invert/lapack_routines.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/impls/cyclic/cyclic_laplace.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/impls/multigrid/multigrid_alg.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/impls/multigrid/multigrid_laplace.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/impls/multigrid/multigrid_solver.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/impls/mumps/mumps_laplace.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/impls/naulin/naulin_laplace.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/impls/pdd/pdd.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/impls/petsc/petsc_laplace.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/impls/serial_band/serial_band.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/impls/serial_tri/serial_tri.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/impls/shoot/shoot_laplace.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/impls/spt/spt.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/invert_laplace.cxx.o CMakeFiles/bout++.dir/src/invert/laplace/laplacefactory.cxx.o CMakeFiles/bout++.dir/src/invert/laplacexy/laplacexy.cxx.o CMakeFiles/bout++.dir/src/invert/laplacexz/impls/cyclic/laplacexz-cyclic.cxx.o CMakeFiles/bout++.dir/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx.o CMakeFiles/bout++.dir/src/invert/laplacexz/laplacexz.cxx.o CMakeFiles/bout++.dir/src/invert/parderiv/impls/cyclic/cyclic.cxx.o CMakeFiles/bout++.dir/src/invert/parderiv/invert_parderiv.cxx.o CMakeFiles/bout++.dir/src/invert/parderiv/parderiv_factory.cxx.o CMakeFiles/bout++.dir/src/mesh/boundary_factory.cxx.o CMakeFiles/bout++.dir/src/mesh/boundary_region.cxx.o CMakeFiles/bout++.dir/src/mesh/boundary_standard.cxx.o CMakeFiles/bout++.dir/src/mesh/coordinates.cxx.o CMakeFiles/bout++.dir/src/mesh/data/gridfromfile.cxx.o CMakeFiles/bout++.dir/src/mesh/data/gridfromoptions.cxx.o CMakeFiles/bout++.dir/src/mesh/difops.cxx.o CMakeFiles/bout++.dir/src/mesh/fv_ops.cxx.o CMakeFiles/bout++.dir/src/mesh/impls/bout/boutmesh.cxx.o CMakeFiles/bout++.dir/src/mesh/index_derivs.cxx.o CMakeFiles/bout++.dir/src/mesh/interpolation.cxx.o CMakeFiles/bout++.dir/src/mesh/interpolation/bilinear.cxx.o CMakeFiles/bout++.dir/src/mesh/interpolation/hermite_spline.cxx.o CMakeFiles/bout++.dir/src/mesh/interpolation/interpolation_factory.cxx.o CMakeFiles/bout++.dir/src/mesh/interpolation/lagrange_4pt.cxx.o CMakeFiles/bout++.dir/src/mesh/interpolation/monotonic_hermite_spline.cxx.o CMakeFiles/bout++.dir/src/mesh/mesh.cxx.o CMakeFiles/bout++.dir/src/mesh/meshfactory.cxx.o CMakeFiles/bout++.dir/src/mesh/parallel/fci.cxx.o CMakeFiles/bout++.dir/src/mesh/parallel/identity.cxx.o CMakeFiles/bout++.dir/src/mesh/parallel/shiftedmetric.cxx.o CMakeFiles/bout++.dir/src/mesh/parallel_boundary_op.cxx.o CMakeFiles/bout++.dir/src/mesh/parallel_boundary_region.cxx.o CMakeFiles/bout++.dir/src/mesh/surfaceiter.cxx.o CMakeFiles/bout++.dir/src/physics/gyro_average.cxx.o CMakeFiles/bout++.dir/src/physics/physicsmodel.cxx.o CMakeFiles/bout++.dir/src/physics/smoothing.cxx.o CMakeFiles/bout++.dir/src/physics/snb.cxx.o CMakeFiles/bout++.dir/src/physics/sourcex.cxx.o CMakeFiles/bout++.dir/src/solver/impls/adams_bashforth/adams_bashforth.cxx.o CMakeFiles/bout++.dir/src/solver/impls/arkode/arkode.cxx.o CMakeFiles/bout++.dir/src/solver/impls/cvode/cvode.cxx.o CMakeFiles/bout++.dir/src/solver/impls/euler/euler.cxx.o CMakeFiles/bout++.dir/src/solver/impls/ida/ida.cxx.o CMakeFiles/bout++.dir/src/solver/impls/imex-bdf2/imex-bdf2.cxx.o CMakeFiles/bout++.dir/src/solver/impls/karniadakis/karniadakis.cxx.o CMakeFiles/bout++.dir/src/solver/impls/petsc/petsc.cxx.o CMakeFiles/bout++.dir/src/solver/impls/power/power.cxx.o CMakeFiles/bout++.dir/src/solver/impls/pvode/pvode.cxx.o CMakeFiles/bout++.dir/src/solver/impls/rk3-ssp/rk3-ssp.cxx.o CMakeFiles/bout++.dir/src/solver/impls/rk4/rk4.cxx.o CMakeFiles/bout++.dir/src/solver/impls/rkgeneric/impls/cashkarp/cashkarp.cxx.o CMakeFiles/bout++.dir/src/solver/impls/rkgeneric/impls/rk4simple/rk4simple.cxx.o CMakeFiles/bout++.dir/src/solver/impls/rkgeneric/impls/rkf34/rkf34.cxx.o CMakeFiles/bout++.dir/src/solver/impls/rkgeneric/impls/rkf45/rkf45.cxx.o CMakeFiles/bout++.dir/src/solver/impls/rkgeneric/rkgeneric.cxx.o CMakeFiles/bout++.dir/src/solver/impls/rkgeneric/rkscheme.cxx.o CMakeFiles/bout++.dir/src/solver/impls/rkgeneric/rkschemefactory.cxx.o CMakeFiles/bout++.dir/src/solver/impls/slepc/slepc.cxx.o CMakeFiles/bout++.dir/src/solver/impls/snes/snes.cxx.o CMakeFiles/bout++.dir/src/solver/impls/split-rk/split-rk.cxx.o CMakeFiles/bout++.dir/src/solver/solver.cxx.o CMakeFiles/bout++.dir/src/solver/solverfactory.cxx.o CMakeFiles/bout++.dir/src/sys/bout_types.cxx.o CMakeFiles/bout++.dir/src/sys/boutcomm.cxx.o CMakeFiles/bout++.dir/src/sys/boutexception.cxx.o CMakeFiles/bout++.dir/src/sys/derivs.cxx.o CMakeFiles/bout++.dir/src/sys/expressionparser.cxx.o CMakeFiles/bout++.dir/src/sys/msg_stack.cxx.o CMakeFiles/bout++.dir/src/sys/options.cxx.o CMakeFiles/bout++.dir/src/sys/options/options_ini.cxx.o CMakeFiles/bout++.dir/src/sys/options/options_netcdf.cxx.o CMakeFiles/bout++.dir/src/sys/optionsreader.cxx.o CMakeFiles/bout++.dir/src/sys/output.cxx.o CMakeFiles/bout++.dir/src/sys/petsclib.cxx.o CMakeFiles/bout++.dir/src/sys/range.cxx.o CMakeFiles/bout++.dir/src/sys/slepclib.cxx.o CMakeFiles/bout++.dir/src/sys/timer.cxx.o CMakeFiles/bout++.dir/src/sys/type_name.cxx.o CMakeFiles/bout++.dir/src/sys/utils.cxx.o
ZedThree commented 2 years ago

Sorry @akrause2014, I thought I had replied the other day, but my comment seems to have vanished into the ether.

Please could you also post the link line for serial_tests?

Somewhere in that line it should print the location of libnetcdf_c++4.so that it's using -- could you then run nm -D <location of libnetcdf_c++> | grep NcFile and post the results?

If that file isn't in the link line then something is going very wrong!

akrause2014 commented 2 years ago

It prints the location of /usr/local/Cellar/netcdf/4.8.0_2/lib/libnetcdf-cxx4.dylib and then

nm: error: /usr/local/Cellar/netcdf/4.8.0_2/lib/libnetcdf-cxx4.dylib: File format has no dynamic symbol table.
ZedThree commented 2 years ago

Ah, looks like we need different flags for .dylib files. Please try nm -a or nm -g