C++17 std::fs #20460

issue MarcoFalke opened this issue on November 23, 2020
  1. MarcoFalke commented at 10:58 AM on November 23, 2020: member

    C++17 std::fs would be useful for a stronger rename method (#20435) and dropping boost fs in favor of the stdlib (#20744).

    However, we currently use bionic to compile gitian binaries, which uses gcc-7 by default. If we are ok switching to gcc-8 on bionic for our gitian builds and everyone compiling from source on bionic, we could start using std::fs

  2. MarcoFalke added the label Brainstorming on Nov 23, 2020
  3. MarcoFalke added the label Build system on Nov 23, 2020
  4. vasild commented at 11:25 AM on November 23, 2020: member

    If this would require just one more package to the apt-get install ... line which users already execute, then I don't see why not go forward with this.

    apt-get install foo bar ... gcc-8
    export CC=gcc8 CXX=g++8
    ... compile as usual ...
    
  5. kiminuo commented at 11:35 AM on November 23, 2020: contributor

    @vasild I believe, you need to add -lstdc++fs for gcc-8 to make it work.

    It seems it is important where the flag is placed (at least on my Ubuntu 18.04 & gcc-8):

    // This is simple "main.cpp" file to test compiling of a program with std::filesystem on gcc-8.
    
    // Ubuntu 18.04
    // works:         g++-8 --std=c++17 main.cpp -lstdc++fs 
    // does not work: g++-8 --std=c++17 -lstdc++fs main.cpp 
    
    #include <string>
    #include <iostream>
    #include <filesystem>
    namespace fs = std::filesystem;
    
    int main()
    {
        std::string path = "C:\\cpp_filesystem";
        for (auto & p : fs::directory_iterator(path))
            std::cout << p << std::endl;
    }
    

    It would be great if somebody could verify my claim though.

    Some resources:

  6. promag commented at 11:44 AM on November 23, 2020: member

    I've verified @kiminuo claim:

    docker run --rm -it ubuntu:bionic
    apt update && apt install gcc-8 g++-8
    # build above example
    

    Edit: @kiminuo however it shouldn't matter here, as we compile and link separately.

  7. promag commented at 11:45 AM on November 23, 2020: member

    Concept ACK.

  8. kiminuo commented at 12:51 PM on November 23, 2020: contributor

    @promag I was unlucky to go through link phase when doing:

    ./autogen.sh && ./configure CC=gcc-8 CXX="g++-8" LDFLAGS="-lstdc++fs" --with-incompatible-bdb && make -j10

    on kiminuo:feature/2020-06-replace-boost-filesystem-with-cpp17-filesystem git branch (#19245).

    It would be great help resolving this.

    Note: It has helped me to add manually in the generated makefile -lstdc++fs as follows:

    bitcoin-cli$(EXEEXT): $(bitcoin_cli_OBJECTS) $(bitcoin_cli_DEPENDENCIES) $(EXTRA_bitcoin_cli_DEPENDENCIES)	[@rm](/bitcoin-bitcoin/contributor/rm/) -f bitcoin-cli$(EXEEXT)
    	$(AM_V_CXXLD)$(bitcoin_cli_LINK) $(bitcoin_cli_OBJECTS) $(bitcoin_cli_LDADD) $(LIBS) -lstdc++fs
    
  9. promag commented at 1:00 PM on November 23, 2020: member

    @kiminuo oh it also happens just linking.

  10. practicalswift commented at 2:54 PM on November 23, 2020: contributor

    Concept ACK

  11. vasild commented at 1:54 PM on November 24, 2020: member

    Concept ACK

    I gather gcc 9 does not require -lstdc++fs. Is it as available as gcc 8 on the relevant platforms?

  12. kiminuo commented at 2:05 PM on December 15, 2020: contributor

    @vasild

    I gather gcc 9 does not require -lstdc++fs. Is it as available as gcc 8 on the relevant platforms?

    gcc-9 is not supported on Ubuntu 18.04 as far as I know. Ubuntu 20.04 (focal) has gcc-9 package (https://packages.ubuntu.com/search?suite=focal&arch=any&searchon=names&keywords=gcc-9). So answer is probably no.

  13. fanquake commented at 7:23 AM on December 17, 2020: member

    I will put together some changes for this 📁 .

  14. jonatack commented at 9:42 PM on March 2, 2021: member

    Concept ACK

  15. MarcoFalke added this to the milestone 23.0 on Mar 3, 2021
  16. MarcoFalke commented at 7:27 AM on March 3, 2021: member

    We've had reports of people unable to compile because of outdated compilers that can't handle the C++17 in our master branch. Once the 22.0 release is out, we might get more complaints about that. I think bumping the compiler versions even higher for the 22.0 release might be a bit too aggressive and rushed.

    Assigned 23.0 for now, so that we can collect some feedback after the 22.0 release.

  17. MarcoFalke commented at 1:43 PM on October 21, 2021: member

    Any further discussion can be done in the pull

  18. MarcoFalke closed this on Oct 21, 2021

  19. DrahtBot locked this on Oct 30, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-17 06:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me