boost copy_file() undefined reference

Hello. I'm struggling to use liboost in order to copy files. In reference there is:
1
2
3
4
void copy_file(const path& from, const path& to);
void copy_file(const path& from, const path& to, system::error_code& ec);
void copy_file(const path& from, const path& to, copy_option option);
void copy_file(const path& from, const path& to, copy_option option, system::error_code& ec);


How the compiler knows whether I want to use the first function or the last? Because if I do something like this:
boost::filesystem3::detail::copy_file(path1, path2);
or
boost::filesystem3::detail::copy_file(path1, path2, boost::filesystem3::copy_option::overwrite_if_exists
It says too few arguments or undefined reference.

I want to use it like this:
1
2
3
4
5
6
7
#include <boost/filesystem.hpp> 
int main() {
boost::filesystem3::path const& path1="/home/test";
boost::filesystem3::path const& path2="/home/testcopy";
boost::filesystem3::detail::copy_file(path1, path2, boost::filesystem3::copy_option::overwrite_if_exists);
return 0;
}


But compiler says:
$ g++ file.cpp -lboost_system
/tmp/ccW14mMD.o: In function `main':
file.cpp:(.text+0x51): undefined reference to `boost::filesystem3::detail::copy_file(boost::filesystem3::path const&, 
boost::filesystem3::path const&, boost::filesystem3::copy_option::enum_type, boost::system::error_code*)'
collect2: error: ld returned 1 exit status
Last edited on
You need to link against boost filesystem as well: g++ file.cpp -lboost_system -lboost_filesystem works for me.
Thank you it works.
Topic archived. No new replies allowed.