Dear Advanced c/g++ on boost programers: I have copied and testd a simple (Copy a file with Boost) program from page 372, Example10-10, book(C++ cookbook) but I got compile error ----------------------------- eric@eric-laptop:~/cppcookbook/ch10$ g++ Example10-10.cpp Example10-10.cpp: In function ‘int main(int, char**)’: Example10-10.cpp:17:47: error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘boost::enable_if_c<true, void>::type*’ Example10-10.cpp:17:47: error: initializing argument 2 of ‘boost::filesystem3::path::path(const Source&, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type*) [with Source = char*, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type = void]’ Example10-10.cpp:18:47: error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘boost::enable_if_c<true, void>::type*’ Example10-10.cpp:18:47: error: initializing argument 2 of ‘boost::filesystem3::path::path(const Source&, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type*) [with Source = char*, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type = void]’ Example10-10.cpp:18:48: error: expected ‘)’ before ‘;’ token ----------------------------- This is my program, you can download and test by your self from http://examples.oreilly.com/9780596007614/ ----------------------------------------------------- // Example 10-10. Copying a file with Boost #include <iostream> #include <string> #include <boost/filesystem/operations.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/filesystem/path.hpp> using namespace std; using namespace boost::filesystem; int main(int argc, char** argv) { // Parameter checking... try { // Turn the args into absolute paths using native formatting path src = complete(path(argv[1], native)); path dst = complete(path(argv[2], native); copy_file(src, dst); } catch (exception& e) { cerr << e.what() << endl; } return(EXIT_SUCCESS); } ---------------------------------------------------------------------------- I ever check around web, there is some suggestion ask me to get rid native, but in my test/system, it only generate more errors. my boost version probably is 1.46.1 and I am on g++ 4.5.2 and Ubuntu10.04/linuxKernel2.6.35-25 Need and thanks your help a lot in advance, Eric
2011/7/19 Eric Lin <kingdavid1@w.cn>
Dear Advanced c/g++ on boost programers:
I have copied and testd a simple (Copy a file with Boost) program from page 372, Example10-10, book(C++ cookbook) but I got compile error ----------------------------- eric@eric-laptop:~/cppcookbook/ch10$ g++ Example10-10.cpp Example10-10.cpp: In function ‘int main(int, char**)’: Example10-10.cpp:17:47: error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘boost::enable_if_c<true, void>::type*’ Example10-10.cpp:17:47: error: initializing argument 2 of ‘boost::filesystem3::path::path(const Source&, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type*) [with Source = char*, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type = void]’ Example10-10.cpp:18:47: error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘boost::enable_if_c<true, void>::type*’ Example10-10.cpp:18:47: error: initializing argument 2 of ‘boost::filesystem3::path::path(const Source&, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type*) [with Source = char*, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type = void]’ Example10-10.cpp:18:48: error: expected ‘)’ before ‘;’ token ----------------------------- This is my program, you can download and test by your self from http://examples.oreilly.com/9780596007614/ ----------------------------------------------------- // Example 10-10. Copying a file with Boost #include <iostream> #include <string> #include <boost/filesystem/operations.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/filesystem/path.hpp>
using namespace std; using namespace boost::filesystem;
int main(int argc, char** argv) {
// Parameter checking...
try { // Turn the args into absolute paths using native formatting path src = complete(path(argv[1], native)); path dst = complete(path(argv[2], native); copy_file(src, dst); } catch (exception& e) { cerr << e.what() << endl; }
return(EXIT_SUCCESS); }
---------------------------------------------------------------------------- I ever check around web, there is some suggestion ask me to get rid native, but in my test/system, it only generate more errors. my boost version probably is 1.46.1 and I am on g++ 4.5.2 and Ubuntu10.04/linuxKernel2.6.35-25 Need and thanks your help a lot in advance, Eric
Removing the "native" does work well for me, what are the errors you saw then? Link errors? You must link against the boost filesystem & system lib.
________________________________
Date: Tue, 19 Jul 2011 13:48:16 +0800 From: tongari95@gmail.com To: boost-users@lists.boost.org Subject: Re: [Boost-users] invalid conversion from 'bool
2011/7/19 Eric Lin <kingdavid1@w.cn<mailto:kingdavid1@w.cn>>
Dear Advanced c/g++ on boost programers:
I have copied and testd a simple (Copy a file with Boost) program from page 372, Example10-10, book(C++ cookbook) but I got compile error ----------------------------- eric@eric-laptop:~/cppcookbook/ch10$ g++ Example10-10.cpp Example10-10.cpp: In function ‘int main(int, char**)’: Example10-10.cpp:17:47: error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘boost::enable_if_c<true, void>::type*’ Example10-10.cpp:17:47: error: initializing argument 2 of ‘boost::filesystem3::path::path(const Source&, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type*) [with Source = char*, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type = void]’ Example10-10.cpp:18:47: error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘boost::enable_if_c<true, void>::type*’ Example10-10.cpp:18:47: error: initializing argument 2 of ‘boost::filesystem3::path::path(const Source&, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type*) [with Source = char*, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type = void]’
----------------------------- This is my program, you can download and test by your self from http://examples.oreilly.com/9780596007614/ ----------------------------------------------------- // Example 10-10. Copying a file with Boost #include <iostream> #include <string> #include <boost/filesystem/operations.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/filesystem/path.hpp>
using namespace std; using namespace boost::filesystem;
int main(int argc, char** argv) {
// Parameter checking...
try { // Turn the args into absolute paths using native formatting path src = complete(path(argv[1], native)); path dst = complete(path(argv[2], native)); copy_file(src, dst); } catch (exception& e) { cerr << e.what() << endl; }
return(EXIT_SUCCESS); } ---------------------------------------------------------------------------- I ever check around web, there is some suggestion ask me to get rid native, but in my test/system, it only generate more errors. my boost version probably is 1.46.1 and I am on g++ 4.5.2 and Ubuntu10.04/linuxKernel2.6.35-25 Need and thanks your help a lot in advance, Eric
Removing the "native" does work well for me, what are the errors you saw then? Link errors? You must link against the boost filesystem & system lib.
Thanks your reply, but how to (link against the boost filesystem & system lib)? I am on linux/g++ these are errors I got, after I eliminate native ---------------- eric@eric-laptop:~/cppcookbook/ch10$ g++ -lboost_system Example10-10.cpp /tmp/ccF2cJsO.o: In function `boost::filesystem3::path::codecvt()': Example10-10.cpp:(.text._ZN5boost11filesystem34path7codecvtEv[boost::filesystem3::path::codecvt()]+0x7): undefined reference to `boost::filesystem3::path::wchar_t_codecvt_facet()' /tmp/ccF2cJsO.o: In function `boost::filesystem3::complete(boost::filesystem3::path const&)': Example10-10.cpp:(.text._ZN5boost11filesystem38completeERKNS0_4pathE[boost::filesystem3::complete(boost::filesystem3::path const&)]+0x2d): undefined reference to `boost::filesystem3::absolute(boost::filesystem3::path const&, boost::filesystem3::path const&)' /tmp/ccF2cJsO.o: In function `boost::filesystem3::copy_file(boost::filesystem3::path const&, boost::filesystem3::path const&)': Example10-10.cpp:(.text._ZN5boost11filesystem39copy_fileERKNS0_4pathES3_[boost::filesystem3::copy_file(boost::filesystem3::path const&, boost::filesystem3::path const&)]+0x24): 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*)' /tmp/ccF2cJsO.o: In function `boost::filesystem3::initial_path()': Example10-10.cpp:(.text._ZN5boost11filesystem312initial_pathEv[boost::filesystem3::initial_path()]+0x18): undefined reference to `boost::filesystem3::detail::initial_path(boost::system::error_code*)' collect2: ld returned 1 exit status eric@eric-laptop:~/cppcookbook/ch10$ ------------------- looking to see any expert's help again and thank a lot in advance, Eric
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks your reply, but how to (link against the boost filesystem & system lib)? I am on linux/g++ these are errors I got, after I eliminate native ---------------- eric@eric-laptop:~/cppcookbook/ch10$ g++ -lboost_system Example10-10.cpp /tmp/ccF2cJsO.o: In function `boost::filesystem3::path::codecvt()': Example10-10.cpp:(.text._ZN5boost11filesystem34path7codecvtEv[boost::filesystem3::path::codecvt()]+0x7): undefined reference to `boost::filesystem3::path::wchar_t_codecvt_facet()' /tmp/ccF2cJsO.o: In function `boost::filesystem3::complete(boost::filesystem3::path const&)': Example10-10.cpp:(.text._ZN5boost11filesystem38completeERKNS0_4pathE[boost::filesystem3::complete(boost::filesystem3::path const&)]+0x2d): undefined reference to `boost::filesystem3::absolute(boost::filesystem3::path const&, boost::filesystem3::path const&)' /tmp/ccF2cJsO.o: In function `boost::filesystem3::copy_file(boost::filesystem3::path const&, boost::filesystem3::path const&)': Example10-10.cpp:(.text._ZN5boost11filesystem39copy_fileERKNS0_4pathES3_[boost::filesystem3::copy_file(boost::filesystem3::path const&, boost::filesystem3::path const&)]+0x24): 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*)' /tmp/ccF2cJsO.o: In function `boost::filesystem3::initial_path()': Example10-10.cpp:(.text._ZN5boost11filesystem312initial_pathEv[boost::filesystem3::initial_path()]+0x18): undefined reference to `boost::filesystem3::detail::initial_path(boost::system::error_code*)' collect2: ld returned 1 exit status eric@eric-laptop:~/cppcookbook/ch10$ ------------------- looking to see any expert's help again and thank a lot in advance, Eric
You need to link to Boost.Filesystem as well as Boost.System. That is, in addition to -lboost_system, you should be passing -lboost_filesystem to the compiler. Regards, Nate.
Dear Advanced c/g++ on boost programers:
I have copied and testd a simple (Copy a file with Boost) program from page 372, Example10-10, book(C++ cookbook) but I got compile error ----------------------------- eric@eric-laptop:~/cppcookbook/ch10$ g++ Example10-10.cpp Example10-10.cpp: In function ‘int main(int, char**)’: Example10-10.cpp:17:47: error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘boost::enable_if_c<true, void>::type*’ Example10-10.cpp:17:47: error: initializing argument 2 of ‘boost::filesystem3::path::path(const Source&, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type*) [with Source = char*, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type = void]’ Example10-10.cpp:18:47: error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘boost::enable_if_c<true, void>::type*’ Example10-10.cpp:18:47: error: initializing argument 2 of ‘boost::filesystem3::path::path(const Source&, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type*) [with Source = char*, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type = void]’ Example10-10.cpp:18:48: error: expected ‘)’ before ‘;’ token ----------------------------- This is my program, you can download and test by your self from http://examples.oreilly.com/9780596007614/ ----------------------------------------------------- // Example 10-10. Copying a file with Boost #include <iostream> #include <string> #include <boost/filesystem/operations.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/filesystem/path.hpp>
using namespace std; using namespace boost::filesystem;
int main(int argc, char** argv) {
// Parameter checking...
try { // Turn the args into absolute paths using native formatting path src = complete(path(argv[1], native)); path dst = complete(path(argv[2], native); copy_file(src, dst); } catch (exception& e) { cerr << e.what() << endl; }
return(EXIT_SUCCESS); }
The Boost Filesystem library underwent an upgrade, from v2 in Boost 1.45 and before, to v3 in Boost 1.46 and after. This was a breaking change, so code that worked with v2 won't necessarily work with v3. The code from the C++ Cookbook works well with Filesystem v2, but not with Filesystem v3. You can either: 1) Compile your code with Filesystem v2 (it's still around in Boost 1.46, it's just not the default). You can do this by adding #define BOOST_FILESYSTEM_VERSION 2 at the top of your file, or passing the flag -DBOOST_FILESYSTEM_VERSION=2 to your compiler. 2) Correct the code to work with Filesystem v3, by removing the second parameter ("native") from the path constructors. If you are getting further errors after doing either of these steps, you have a different (additional) problem and you'll need to post the new errors for us to help you with it. Regards, Nate.
participants (3)
-
Eric Lin
-
Nathan Ridge
-
TONGARI