|
|
Ganado wrote: |
---|
If you're talking about boost's source code, no, a compiled executable has no use for the source code used to create it. This applies whether it's your own source code, or the source/object code of another library you're using. |
Ganado wrote: |
---|
What platform/version of g++ are you using? https://stackoverflow.com/questions/45867379/why-does-gcc-not-seem-to-have-the-filesystem-standard-library It sounds like you're on Windows, so unfortunately I would assume that your version of MinGW doesn't have the latest features of <filesystem> implemented. You can try <experimental/filesystem>, but not sure if the latest builds support it, you would need to check changelogs of wherever your'e downloading from. If that's too much of a pain, then yep you can use boost. |
g++ --version
says: g++ (Ubuntu 7.4.0-1ubuntu1~18.04) 7.4.0. And as mentioned in my original post, I tried the experimental version but it gave errors unfortunately.sudo apt-get install gcc-8
|
|
|
|
/tmp/cceHHbnF.o: In function `openRecipes(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)': Main.cpp:(.text+0x284): undefined reference to `std::experimental::filesystem::v1::__cxx11::directory_iterator::operator*() co Main.cpp:(.text+0x2cd): undefined reference to `std::experimental::filesystem::v1::__cxx11::directory_iterator::operator++()' /tmp/cceHHbnF.o: In function `std::experimental::filesystem::v1::__cxx11::directory_iterator::directory_iterator(std::experime Main.cpp:(.text._ZNSt12experimental10filesystem2v17__cxx1118directory_iteratorC2ERKNS2_4pathE[_ZNSt12experimental10filesystem2 perimental::filesystem::v1::__cxx11::directory_iterator::directory_iterator(std::experimental::filesystem::v1::__cxx11::path c /tmp/cceHHbnF.o: In function `std::experimental::filesystem::v1::__cxx11::path::path<std::__cxx11::basic_string<char, std::cha ath>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': Main.cpp:(.text._ZNSt12experimental10filesystem2v17__cxx114pathC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES3_EERKT ar_traitsIcESaIcEEES3_EERKT_]+0x70): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts( collect2: error: ld returned 1 exit status |
Ganado wrote: |
---|
"g++" might still be pointing to your older, original version of g++. What happens if you do "gcc-8 --version" or "g++-8 --version"? |
gcc-8 (Ubuntu 8.3.0-6ubuntu1~18.04) 8.3.0 |
Ganado wrote: |
---|
I can't test out this with ubuntu myself right now, sorry. But what happens if, on 7.4, you #include <experimental/filesystem> , and use std::experimental::filesystem instead of just std::filesystem? |
|
|
/tmp/cckcOOPt.o: In function `openRecipes(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)': Main.cpp:(.text+0x284): undefined reference to `std::experimental::filesystem::v1::__cxx11::directory_iterator::operator*() co Main.cpp:(.text+0x2cd): undefined reference to `std::experimental::filesystem::v1::__cxx11::directory_iterator::operator++()' /tmp/cckcOOPt.o: In function `std::experimental::filesystem::v1::__cxx11::directory_iterator::directory_iterator(std::experime Main.cpp:(.text._ZNSt12experimental10filesystem2v17__cxx1118directory_iteratorC2ERKNS2_4pathE[_ZNSt12experimental10filesystem2 perimental::filesystem::v1::__cxx11::directory_iterator::directory_iterator(std::experimental::filesystem::v1::__cxx11::path c /tmp/cckcOOPt.o: In function `std::experimental::filesystem::v1::__cxx11::path::path<std::__cxx11::basic_string<char, std::cha ath>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': Main.cpp:(.text._ZNSt12experimental10filesystem2v17__cxx114pathC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES3_EERKT ar_traitsIcESaIcEEES3_EERKT_]+0x70): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts( collect2: error: ld returned 1 exit status |
jlb wrote: |
---|
You may need to link with the -lstdc++fs library as well, depending on the compiler version. Also depending on version you may not need to use "experimental". Check the documentation for your particular compiler to be sure. |
/tmp/ccsaa224.o: In function `openRecipes(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)': Main.cpp:(.text+0x284): undefined reference to `std::experimental::filesystem::v1::__cxx11::directory_iterator::operator*() co Main.cpp:(.text+0x2cd): undefined reference to `std::experimental::filesystem::v1::__cxx11::directory_iterator::operator++()' /tmp/ccsaa224.o: In function `std::experimental::filesystem::v1::__cxx11::directory_iterator::directory_iterator(std::experime Main.cpp:(.text._ZNSt12experimental10filesystem2v17__cxx1118directory_iteratorC2ERKNS2_4pathE[_ZNSt12experimental10filesystem2 perimental::filesystem::v1::__cxx11::directory_iterator::directory_iterator(std::experimental::filesystem::v1::__cxx11::path c /tmp/ccsaa224.o: In function `std::experimental::filesystem::v1::__cxx11::path::path<std::__cxx11::basic_string<char, std::cha ath>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': Main.cpp:(.text._ZNSt12experimental10filesystem2v17__cxx114pathC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES3_EERKT ar_traitsIcESaIcEEES3_EERKT_]+0x70): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts( collect2: error: ld returned 1 exit status |
|
|
g++ -std=c++17 Main.cpp
|
|
g++ (Ubuntu 8.3.0-6ubuntu1~18.04) 8.3.0
jlb wrote: |
---|
Is there a reason you selected gcc 8.3.0 instead of 9.1, your program seems to work if using 9.1. |
g++-9
in bash. The result was:Command 'g++-9' not found, did you mean: command 'g++-6' from deb g++-6 command 'g++-7' from deb g++-7 command 'g++-8' from deb g++-8 command 'g++-5' from deb g++-5 Try: sudo apt install <deb name> |
sudo apt install g++-9
and put in my password. Then it said:Reading package lists... Done Building dependency tree Reading state information... Done Note, selecting 'libconfig9' for regex 'g++9' Note, selecting 'librope-ocaml-dev-ig916' for regex 'g++9' Note, selecting 'libjpeg9-dbg' for regex 'g++9' Note, selecting 'libjpeg9-dev' for regex 'g++9' Note, selecting 'librope-ocaml-ig916' for regex 'g++9' Note, selecting 'libjpeg9' for regex 'g++9' Note, selecting 'libgettext-ocaml-dev-0xdg9' for regex 'g++9' Note, selecting 'libgettext-ocaml-0xdg9' for regex 'g++9' Note, selecting 'golang-github-xiang90-probing-dev' for regex 'g++9' Note, selecting 'libnppig9.1' for regex 'g++9' Note, selecting 'libgettext-ocaml' instead of 'libgettext-ocaml-0xdg9' Note, selecting 'libgettext-ocaml-dev' instead of 'libgettext-ocaml-dev-0xdg9' Note, selecting 'librope-ocaml' instead of 'librope-ocaml-ig916' Note, selecting 'librope-ocaml-dev' instead of 'librope-ocaml-dev-ig916' golang-github-xiang90-probing-dev is already the newest version (0.0.1-1). libconfig9 is already the newest version (1.5-0.4). libgettext-ocaml is already the newest version (0.3.7-1build2). libgettext-ocaml-dev is already the newest version (0.3.7-1build2). libjpeg9 is already the newest version (1:9b-2). libjpeg9-dbg is already the newest version (1:9b-2). libjpeg9-dev is already the newest version (1:9b-2). librope-ocaml is already the newest version (0.6-1). librope-ocaml-dev is already the newest version (0.6-1). libnppig9.1 is already the newest version (9.1.85-3ubuntu1). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. |
g++-9
still doesn't work.
|
|
|
|
update-alternatives: error: alternative path /usr/bin/gcc-9 doesn't exist |
sudo apt install gcc-9
Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package gcc9 |
g++ -v
Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 8.3.0-6ubuntu1~18.04' --with-bugurl=file: ///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix= /usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-share d --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --lib dir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libs tdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --ena ble-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-ob jc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m 32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-dri ver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1~18.04) |
mbozzi wrote: |
---|
You need to pass -lstdc++fs to link the C++ filesystem library. Consider fs::path over std::string. fs::path is like std::string, except that it has special support for manipulating filesystem paths. |
g++ -std=c++17 -lstdc++fs Main.cpp
/tmp/ccmCklwv.o: In function `openRecipes(std::__cxx11::basic_string<char, std::char_traits<char>, std:: allocator<char> >&)': Main.cpp:(.text+0x187): undefined reference to `std::filesystem::__cxx11::directory_iterator::operator*( ) const' Main.cpp:(.text+0x1d0): undefined reference to `std::filesystem::__cxx11::directory_iterator::operator++ ()' /tmp/ccmCklwv.o: In function `std::filesystem::__cxx11::path::path(std::__cxx11::basic_string<char, std: :char_traits<char>, std::allocator<char> >&&, std::filesystem::__cxx11::path::format)': Main.cpp:(.text._ZNSt10filesystem7__cxx114pathC2EONSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS 1_6formatE[_ZNSt10filesystem7__cxx114pathC5EONSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS1_6fo rmatE]+0x4f): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()' /tmp/ccmCklwv.o: In function `std::filesystem::__cxx11::path::operator+=(std::__cxx11::basic_string<char , std::char_traits<char>, std::allocator<char> > const&)': Main.cpp:(.text._ZNSt10filesystem7__cxx114pathpLERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[ _ZNSt10filesystem7__cxx114pathpLERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x2b): undefine d reference to `std::filesystem::__cxx11::path::_M_split_cmpts()' /tmp/ccmCklwv.o: In function `std::filesystem::__cxx11::directory_iterator::directory_iterator(std::file system::__cxx11::path const&)': Main.cpp:(.text._ZNSt10filesystem7__cxx1118directory_iteratorC2ERKNS0_4pathE[_ZNSt10filesystem7__cxx1118 directory_iteratorC5ERKNS0_4pathE]+0x26): undefined reference to `std::filesystem::__cxx11::directory_it erator::directory_iterator(std::filesystem::__cxx11::path const&, std::filesystem::directory_options, st d::error_code*)' collect2: error: ld returned 1 exit status |
|
|
g++ -lstdc++fs Main.cpp
Main.cpp:7:21: error: ‘filesystem’ is not a namespace-name namespace fs = std::filesystem; // Shortens the amount I need to type below. ^~~~~~~~~~ Main.cpp:7:31: error: expected namespace-name before ‘;’ token namespace fs = std::filesystem; // Shortens the amount I need to type below. ^ Main.cpp: In function ‘void openRecipes(std::__cxx11::string&)’: Main.cpp:13:5: error: ‘fs’ has not been declared fs::path rPath = "../recipes/" + ver + '/'; ^~ Main.cpp:14:5: error: ‘rPath’ was not declared in this scope rPath += ver; ^~~~~ Main.cpp:14:5: note: suggested alternative: ‘rpmatch’ rPath += ver; ^~~~~ rpmatch Main.cpp:16:30: error: ‘fs’ has not been declared for (const auto &entry : fs::directory_iterator(rPath)) { ^~ |
I looked it up and it said I needed to use v8 or higher for it to work. And if I recall correctly it said 8 was the highest Ubuntu supports, but I guess that post was outdated. |
jlb wrote: |
---|
Do you know that you can compile gcc (practically any version) from source yourself? |
tar xzf gcc-9.1.0.tar.gz cd gcc-9.1.0 ./contrib/download_prerequisites cd .. mkdir objdir cd objdir ../gcc-9.1.0/configure --prefix=/opt/gcc-9.1.0 make -j 8 make install |
Now, we are ready to build GCC, you typically want to pass twice the number of your computer cores to the make command in order to speed up the build. I have a quad-core system, so I will use 8 parallel jobs to build GCC: |
jlb wrote: | ||
---|---|---|
Be careful trying to compile gcc, you don't want to overwrite the "system gcc" so you need to be sure to specify the prefix flag to some other directory. I usually place it in the opt/gcc-Whateverversion directory. This is what I've used to compile gcc (after downloading the source in tar.gz format: Replace the file name with the file you downloaded.
Notes: Notice you need to build the compiler from a directory outside the source directory. The download_prerequisites command retrieves and downloads everything that is needed to compile the source. Notice the creation of the object directory and that you moved into that download directory. Here you run configure with whatever option you select. Run make on the source:
|
../gcc-9.1.0/configure --prefix=/opt/gcc-9.1.0
. I will try that line you mentioned next.Step 0: tar xzf gcc-9.1.0.tar.gz Step 1: cd gcc-9.1.0 Step 2: ./contrib/download_prerequisites Step 3: cd .. Step 4: mkdir objdir Step 5: cd objdir Step 6: $PWD/../gcc-9.1.0/configure --prefix=$HOME/GCC-9.1.0 --enable-languages=c,c++,fortran,go Step 7: make -j 6 (Can never get to the "make install" step without errors). Will use -j 12 next time. Step 8: make install |
make[1]: Entering directory '/mnt/c/Users/Tom/Downloads/gcc/objdir' /bin/bash /mnt/c/Users/Tom/Downloads/gcc/objdir/../gcc-9.1.0/mkinstalldirs /GCC-9.1.0 /GCC-9.1.0 mkdir -p -- /GCC-9.1.0 /GCC-9.1.0 make[2]: Entering directory '/mnt/c/Users/Tom/Downloads/gcc/objdir/fixincludes' make[2]: *** No rule to make target 'install'. Stop. make[2]: Leaving directory '/mnt/c/Users/Tom/Downloads/gcc/objdir/fixincludes' Makefile:3815: recipe for target 'install-fixincludes' failed make[1]: *** [install-fixincludes] Error 2 make[1]: Leaving directory '/mnt/c/Users/Tom/Downloads/gcc/objdir' Makefile:2382: recipe for target 'install' failed make: *** [install] Error 2 |
mbozzi wrote: |
---|
At very least, you probably only want to build the C and C++ compilers. And you most likely don't want to 3-stage bootstrap, though you can, if you wish. |
../gcc-9.1.0/configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --prefix=/usr/local/gcc-9.1 --enable-checking=release --enable-languages=c,c++,fortran --disable-multilib --program-suffix=-9.1
it gave an error msg saying it didn't exist or something. Then I tried following your instructions jlb and got another error: https://pastebin.com/wy1NykK9.mbozzi wrote: |
---|
Bootstrapping is a build process: Step 1. Build the GCC sources with the system compiler Step 2. Build the GCC sources again with the newest GCC compiled; Step 3. Build the GCC sources again with the newest GCC compiled; Finally, compare the results of stage 2 and stage 3 for equality. See the section entitled "Building a native compiler" https://gcc.gnu.org/install/build.html To disable it (and build everything just once with the system GCC), pass --disable-bootstrap to the configure script. |
mbozzi wrote: |
---|
Whoops, I didn't notice your prior reply, so this is about building the filesystem example with GCC 8: You tried g++ -std=c++17 -lstdc++fs Main.cpp, but linking order matters. Say g++ -std=c++17 Main.cpp -lstdc++fs instead. The linker looks at code in the order specified on the command line (the link line). As it goes, it records references to any symbols whose definition it hasn't encountered yet (i.e., undefined references or unresolved (external) symbols). If a library later on in the sequence provides that symbol, that symbol is considered resolved, or defined. Since Main.cpp depends on functions defined in stdc++fs, stdc++fs must go after Main.cpp on the command line. I don't know how familiar you are with linkers, but if you need an introduction, see here: http://www.lurklurk.org/linkers/linkers.html |
g++ -std=c++17 Main.cpp -lstdc++fs
works! I've updated my files (for reminders). The linker looks at code in the order specified on the command line (the link line). As it goes, it records references to any symbols whose definition it hasn't encountered yet (i.e., undefined references or unresolved (external) symbols). If a library later on in the sequence provides that symbol, that symbol is considered resolved, or defined. Since Main.cpp depends on functions defined in stdc++fs, stdc++fs must go after Main.cpp on the command line. I don't know how familiar you are with linkers, but if you need an introduction, see here: http://www.lurklurk.org/linkers/linkers.html |