এখানে একটি ডেমো যা ভবিষ্যতে কারও পক্ষে সহায়ক হতে পারে:
env: el6
,gcc/5.5.0
#include <iostream>
#include <string>
#include <experimental/filesystem>
int main()
{
std::string path = std::experimental::filesystem::current_path();
std::cout << "path = " << path << std::endl;
}
নিম্নলিখিত সংকলন এবং পরীক্ষা করা হয়। পতাকাগুলি হ'ল -std=c++17
-lstdc++fs
:
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/apps/gcc-5.5.0/bin/../libexec/gcc/x86_64-unknown-linux-gnu/5.5.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/apps/gcc-5.5.0 --disable-multilib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-languages=all
Thread model: posix
gcc version 5.5.0 (GCC)
$ ls -lrt /apps/gcc-5.5.0/lib64 | grep libstdc
-rwxr-xr-x. 1 root root 11272436 Jun 25 10:51 libstdc++.so.6.0.21
-rw-r--r--. 1 root root 2419 Jun 25 10:51 libstdc++.so.6.0.21-gdb.py
-rwxr-xr-x. 1 root root 976 Jun 25 10:51 libstdc++.la
-rwxr-xr-x. 1 root root 11272436 Jun 25 10:51 libstdc++.so
-rw-r--r--. 1 root root 10581732 Jun 25 10:51 libstdc++fs.a
-rw-r--r--. 1 root root 28985412 Jun 25 10:51 libstdc++.a
-rwxr-xr-x. 1 root root 916 Jun 25 10:51 libstdc++fs.la
-rwxr-xr-x. 1 root root 11272436 Jun 25 10:51 libstdc++.so.6
$ g++ filesystem-testing.cpp -lstdc++fs -std=c++17
$ ./a.out
$ g++ -std=c++17 filesystem-testing.cpp -lstdc++fs
$ ./a.out
path = /home/userid/projects-c++/filesystem-testing
এটি পতাকাগুলির সাথেও কাজ করে: -std=c++11
$ g++ -std=c++11 filesystem-testing.cpp -lstdc++fs
$ ./a.out
path = /home/userid/projects-c++/filesystem-testing
নিম্নলিখিতগুলিতে সংকলন ত্রুটি ছিল _ZNSt12experimental10filesystem2v112current_pathB5cxx11Ev
$ g++ -std=c++17 -lstdc++fs filesystem-testing.cpp
/tmp/ccA6Q9oF.o: In function `main':
filesystem-testing.cpp:(.text+0x11): undefined reference to `_ZNSt12experimental10filesystem2v112current_pathB5cxx11Ev'
collect2: error: ld returned 1 exit status