Opened 19 months ago
Last modified 14 months ago
#67355 assigned defect
Compiling hdf5 with +gcc12
Reported by: | jvianalopes (João Manuel Viana Parente Lopes) | Owned by: | eborisch (Eric A. Borisch) |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | ports | Version: | |
Keywords: | Cc: | mascguy (Christopher Nielsen), platipodium (Carsten Lemmen) | |
Port: | hdf5 |
Description (last modified by ryandesign (Ryan Carsten Schmidt))
I am running the last version of MacPorts and I installed with success hdf5 wiht +gcc12 +cxx.
My problem is that I need to compile a program in c++ the linking fails because it fails to find objects.
As an example:
Undefined symbols for architecture x86_64: "__ZN2H510H5Location12iterateElemsERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPiPFixPKcPvESC_", referenced from: And the compiled libhdf5_cpp.a has: __ZN2H510H5Location12iterateElemsERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEPiPFixPKcPvESD_
Compiling by hand the source with the ./configure options used in the compiled version of macports:
./configure --prefix=/opt/local --with-zlib=yes --disable-silent-rules --enable-build-mode=production --disable-fortran --enable-shared --enable-static --disable-parallel --disable-threadsafe --with-default-plugindir=/opt/local/lib/hdf5 --with-default-api-version=v110 --enable-hl --enable-cxx
generates an object that has the same problem because it uses clang to compile.
but adding CC and CXX variables:
CXX=c++-mp-12 CC=gcc-mp-12 CXXFLAGS=-std=c++17 ./configure --prefix=/opt/local --with-zlib=yes --disable-silent-rules --enable-build-mode=production --disable-fortran --enable-shared --enable-static --disable-parallel --disable-threadsafe --with-default-plugindir=/opt/local/lib/hdf5 --with-default-api-version=v110 --enable-hl --enable-cxx
It already generates a library that has the objects.
My question is how does macports fix the compiler? Because I used the variant +gcc12 but it seems that it is not the same as defining the compilers as environment variables in the configure.
Do you have suggestions to fix this problem?
Thanks in advance
João
Change History (10)
comment:1 Changed 19 months ago by ryandesign (Ryan Carsten Schmidt)
Description: | modified (diff) |
---|---|
Owner: | set to eborisch |
Status: | new → assigned |
comment:2 Changed 19 months ago by mascguy (Christopher Nielsen)
Cc: | mascguy added |
---|
comment:3 Changed 19 months ago by ryandesign (Ryan Carsten Schmidt)
comment:4 Changed 19 months ago by jvianalopes (João Manuel Viana Parente Lopes)
Thank you very much! Your suggestion was very useful. I was not using the "port configure" neither the "port logfile". Instead, I was copying the build temporary folder and inspecting the config.log.
The difference is in the flag: CXXFLAGS='-pipe -Os -stdlib=libc++ -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk -arch x86_64' removing the -stdlib=libc++ the symbols coincide. How can I remove this option with macports? I tried to edit the Portfile using the "port edit hdf5" and defining CXXFLAGS with configure.env without success. Thanks in advance João
comment:5 Changed 19 months ago by ryandesign (Ryan Carsten Schmidt)
MacPorts base sets the -stdlib
flag based on the value of the configure.cxx_stdlib
option. By default MacPorts sets this to libc++ when using clang++ and to libstdc++ when using g++. Very recently g++ gained the ability to use libc++, I think, but historically that was not possible, and I don't know if anything has been added to MacPorts relating to that yet. Similarly, clang++ cannot use libstdc++, as far as I know.
comment:6 Changed 19 months ago by jvianalopes (João Manuel Viana Parente Lopes)
Hi,
I think this option is root of my problem. In gcc12, using the -stdlib=libc++, deactivates the c++17 and as a consequence in my code I have the error:
error: 'cyl_bessel_j' is not a member of 'std'
Compiling my code with -stdlib=libstdc++ works fine until the linking with hdf5. If hdf5 was compiled with -stdlib=libc++ it is not able to link because the symbols are different. Compiling hdf5 with -stdlib=libstdc++ it links without problems.
These options is set in the CXXFLAGS. Editing the PortFile with port edit,
configure.cxx_stdlib libstdc++
Doesn't change the CXXFLAGS variable (Checked with sudo port configure hdf5 +gcc12 +cxx ; port logfile hdf5). I don't know how to change CXXFLAGS with MacPorts. Thanks in advance
comment:7 Changed 19 months ago by Dave-Allured (Dave Allured)
Cc: | Dave-Allured added |
---|
comment:8 Changed 19 months ago by jvianalopes (João Manuel Viana Parente Lopes)
I was able to change CXXFLAGS using: sudo port -v install hdf5 +gcc12 +cxx +hl configure.ldflags="-stdlib=libstdc++" configure.cxx_stdlib="libstdc++" configure.cxxflags="-std=c++17"
I was able to compile my code.
trying to install with sudo port -v install hdf5 +gcc12 +cxx +hl configure.cxx_stdlib="libstdc++"
fails to compile because to compile due Undefined symbols because LDFLAGS has "-stdlib=libc++": LDFLAGS: -L/opt/local/lib -Wl,-headerpad_max_install_names -stdlib=libc++ -Wl,-rpath,/opt/local/lib/libgcc -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk -arch x86_64
Thank you for the help! Cheers João
comment:9 Changed 19 months ago by Dave-Allured (Dave Allured)
Cc: | Dave-Allured removed |
---|
comment:10 Changed 14 months ago by platipodium (Carsten Lemmen)
Cc: | platipodium added |
---|
Replying to jvianalopes:
When you say "objects", you mean "symbols"?
These symbols, demangled, are:
H5::H5Location::iterateElems(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int*, int (*)(long long, char const*, void*), void*)
H5::H5Location::iterateElems(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, int*, int (*)(long long, char const*, void*), void*)
So they're hdf5 symbols.
This C++ program you're compiling... which compiler are you using? You'll need to use the same C++ standard library for both your program and all of the C++ libraries that it uses. So, for example, either use clang and libc++ to compile your program and hdf5 (this is very strongly recommended on macOS) or use g++ and libstdc++ to compile your program and hdf5. You can't mix and match.
You can run
sudo port configure hdf5 +gcc12 +cxx
(and you can interrupt it by pressing Control-C shortly after the---> Configuring hdf5
line is printed; you don't have to wait for the configure phase to finish) and then examine the log file (whose location is printed byport logfile hdf5
) to see exactly what configure command, flags, and environment variables MacPorts used.