invalid conversion from 'bool

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_at_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
closed account (S6k9GNh0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#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]));
		path dst = complete(path(argv[2]));
		                    copy_file(src, dst);
	}
	catch (exception& e)
	{
		cerr << e.what() << endl;
	}

	return(EXIT_SUCCESS);
}


What is the native in your code supposed to be?
If I follow your suggestion to take off native, I got more compile error
-----------------------------------------------
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$
---------------------------------------------------------
if there are any need to do compile time parameter/link, please specify, otherwise I assume is
g++ Example10-10.cpp
only in my system
looking to hear from any experts and thanks a lot in advance again
Eric
closed account (S6k9GNh0)
Those are linker errors. You need to link to the filesystem library.
g++ -lboost_system Example10-10.cpp


You seem to have specify the linker option but how about the folder location to those boost.h related files ? Check LD_LIBRARY_PATH environment variable or if you want to be explicit specify -L/usr/local/include assuming they reside in this folder.
closed account (S6k9GNh0)
No, he has not linked to boost_filesystem anywhere on his command line. He just needs to link to it.
Last edited on
Topic archived. No new replies allowed.