I have the program Ex_04.cpp which has this code:
#include <iterator>
#include <iostream>
#include <vector>
#include <boost/filesystem/fstream.hpp>
#define BOOST_NO_CXX11_SCOPED_ENUMS
#include <boost/filesystem.hpp>
#undef BOOST_NO_CXX11_SCOPED_ENUMS
namespace fs = boost::filesystem;
int write_to_file()
{
const auto dir = "Test.txt";
fs::path pp{dir};
try{
if( create_directory(pp) ){
rename(pp, dir);
}
}catch(fs::filesystem_error &e){
std::cerr << e.what() << std::endl;
}
return 0;
}
int main()
{
std::cout << "Hello world!" << std::endl;
return 0;
}
My settings.json file looks like this:
{
"code-runner.executorMap": {
"cpp": "cd $dir && g++ -L'C:\\boost_1_81_0\\boost_installed\\lib' -I'C:\\boost_1_81_0\\boost_installed\\include\\boost-1_81' -Werror -Wall -Wextra -Wpedantic -o $fileNameWithoutExt *.cpp && ./$fileNameWithoutExt.exe"
},
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "googletest.failed",
"settings": {
"foreground": "#f00"
}
},
{
"scope": "googletest.passed",
"settings": {
"foreground": "#0f0"
}
},
{
"scope": "googletest.run",
"settings": {
"foreground": "#0f0"
}
}
]
}
}
I have not changed the files tasks.json, launch.json and c_cpp_properties.json.
The error I get when I try to compile is:
C:/msys64/mingw64/x86_64-w64-mingw32/bin/ld.exe: C:\Users\tvmendes\AppData\Local\Temp\cc1GfM0X.o:Ex_04.cpp:
(.text$_ZN5boost10filesystem16create_directoryERKNS0_4pathE[_ZN5boost10filesystem16create_directoryERKNS0_4pathE]+0x1f): undefined reference toboost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::filesystem::path const*, boost::system::error_code*)
C:/msys64/mingw64/x86_64-w64-mingw32/bin/ld.exe: C:\Users\tvmendes\AppData\Local\Temp\cc1GfM0X.o:Ex_04.cpp:
(.text$ZN5boost10filesystem6renameERKNS0_4pathES3[ZN5boost10filesystem6renameERKNS0_4pathES3]+0x22): undefined reference toboost::filesystem::detail::rename(boost::filesystem::path const&, boost::filesystem::path const&, boost::system::error_code*)
C:/msys64/mingw64/x86_64-w64-mingw32/bin/ld.exe: C:\Users\tvmendes\AppData\Local\Temp\cc1GfM0X.o:Ex_04.cpp:
(.text$_ZNK5boost10filesystem4path9assign_opclIcEEvPKT_S6_PKSt7codecvtIwciE[_ZNK5boost10filesystem4path9assign_opclIcEEvPKT_S6_PKSt7codecvtIwciE]+0x44): undefined reference toboost::filesystem::detail::path_traits::convert(char const*, char const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, int> const*)
collect2.exe: error: ld returned 1 exit status
I tried to change the settings.json file by adding the flag -l like this:
"cd $dir && g++ -L'C:\\boost_1_81_0\\boost_installed\\lib' -I'C:\\boost_1_81_0\\boost_installed\\include\\boost-1_81' -l'C:\\boost_1_81_0\\boost_installed\\lib' -Werror -Wall -Wextra -Wpedantic -o $fileNameWithoutExt *.cpp && ./$fileNameWithoutExt.exe"
to link the library filesystem but I always get the error:
C:/msys64/mingw64/x86_64-w64-mingw32/bin/ld.exe: cannot find -lC:\boost_1_81_0\boost_installed\lib: Invalid argument
collect2.exe: error: ld returned 1 exit status
I have checked and the filesystem library exists at that directory.
My operation system is Microsoft Windows 10 Enterprise.