[Filesystem] problems with g++ -std=c++0x

Hi, getting my feet wet with variadic templates, I switched on c++0x support in gcc. Unfortunately, I am experiencing a linker error for the following minimal program: ------------------ #define BOOST_FILESYSTEM_VERSION 3 #define BOOST_FILESYSTEM_NO_DEPRECATED #include <boost/filesystem.hpp> int main() { boost::filesystem::copy_file("a", "b"); } ------------------ rbock@rbock:~/temp/test$ g++ File.cpp -std=c++0x -I boost/1.44/include -L boost/1.44/lib -l boost_filesystem -l boost_system /tmp/ccwkcQpq.o: In function `boost::filesystem3::copy_file(boost::filesystem3::path const&, boost::filesystem3::path const&)': File.cpp:(.text._ZN5boost11filesystem39copy_fileERKNS0_4pathES3_[boost::filesystem3::copy_file(boost::filesystem3::path const&, boost::filesystem3::path const&)]+0x2a): undefined reference to `boost::filesystem3::detail::copy_file(boost::filesystem3::path const&, boost::filesystem3::path const&, boost::filesystem3::copy_option, boost::system::error_code*)' collect2: ld returned 1 exit status Experienced on Ubuntu-10.4, 64bit, gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3 Other boost libraries seem to work fine, other functions within Boost.Filesystem work fine, too. When I rebuild boost with -std=c++0x, then the linking problem is gone, but I experience crashes in the boost::thread constructor :-( Any ideas? Thanks and regards, Roland

Other boost libraries seem to work fine, other functions within Boost.Filesystem work fine, too. When I rebuild boost with -std=c++0x, then the linking problem is gone, but I experience crashes in the boost::thread constructor :-(
Any ideas?
Boost is not ABI stable library, any changes in flags or even in constants may make library ABI uncompatible, so you need to compile all Boost you use with same flags especially such important as -std=c++0x Artyom

On 08/25/2010 09:53 PM, Artyom wrote:
Other boost libraries seem to work fine, other functions within Boost.Filesystem work fine, too. When I rebuild boost with -std=c++0x, then the linking problem is gone, but I experience crashes in the boost::thread constructor :-(
Any ideas?
Boost is not ABI stable library, any changes in flags or even in constants may make library ABI uncompatible, so you need to compile all Boost you use with same flags especially such important as -std=c++0x
That's why I rebuilt boost with -std=c++0x and yes, the linking problem was gone. But instead I got crashes in boost::thread (still need to shrink that into a small enough example).

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 This problem seems to arise from the expansion of the BOOST_SCOPED_ENUM macros in Boost.Filesystem. In <boost/filesystem/v3/operations.hpp> line 115, we have: BOOST_SCOPED_ENUM_START(copy_option) {fail_if_exists, overwrite_if_exists}; BOOST_SCOPED_ENUM_END In g++ 4.5.1, this expands to the following when compiling without - --std=c++0x: struct copy_option { enum enum_type {fail_if_exists, overwrite_if_exists}; }; However, when compiling with -std=c++0x, it expands to: enum class copy_option {fail_if_exists, overwrite_if_exists}; The macro BOOST_SCOPED_ENUM is used in the function copy_file; without - --std=c++0x, the forward declaration for boost::filesystem3::detail::copy_file in operations.hpp (line 138) expands to: void copy_file(const path& from, const path& to, copy_option::enum_type option, system::error_code* ec=0); With --std=c++0x, however, it expands to: void copy_file(const path& from, const path& to, copy_option option, system::error_code* ec=0); Thus creating our problem - if you've compiled Boost.Filesystem without turning on C++0x support, and then you turn on C++0x support in a program that links to Boost.Filesystem, the forward declaration of Boost.Filesystem functions using BOOST_SCOPED_ENUM to expand their parameters will expand incorrectly. - - Bryce Lelbach -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkx1zxcACgkQO/fqqIuE2t6LmQCg6jS8hflO2haqVFUeLTM19zTt vHkAoMtL/ETez1jbIwtBrPct/f9v8aEO =BcGm -----END PGP SIGNATURE-----

On 08/26/2010 04:19 AM, Bryce Lelbach aka wash wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
This problem seems to arise from the expansion of the BOOST_SCOPED_ENUM macros in Boost.Filesystem. In<boost/filesystem/v3/operations.hpp> line 115, we have:
[...] Wow, thanks for finding that! Since the -std=c++0x option turns on so many features at once (and different ones with each new version of gcc), I think I'll refrain from using it by default for the time being. The idea of having to recompile boost for every new version of gcc seems horrible (and was not necessary when switching from gcc-4.2 to gcc-4.4 for the libraries I am using). Also there still is the problem of the segfault in Boost.Thread with -std=c++0x. In the meantime, I found that variadic templates work just fine in gcc-4.4, even without the -std=c++0x option, but they emit warnings. According to the gcc mailing list, these cannot be suppressed (except by turning on said option). So maybe, I'll turn on that option for those parts of the code which actually need the variadic templates and turn it off otherwise... Thanks again and regards, Roland

On Thu, Aug 26, 2010 at 8:43 AM, Roland Bock <rbock@eudoxos.de> wrote: [...]
In the meantime, I found that variadic templates work just fine in gcc-4.4, even without the -std=c++0x option, but they emit warnings. According to the gcc mailing list, these cannot be suppressed (except by turning on said option). So maybe, I'll turn on that option for those parts of the code which actually need the variadic templates and turn it off otherwise...
Completely untested, so I have no idea if it actually works, but... did you try putting the GCC __extension__ keyword on the offending line? -- gpd

On 08/26/2010 04:25 PM, Giovanni Piero Deretta wrote:
On Thu, Aug 26, 2010 at 8:43 AM, Roland Bock<rbock@eudoxos.de> wrote: [...]
In the meantime, I found that variadic templates work just fine in gcc-4.4, even without the -std=c++0x option, but they emit warnings. According to the gcc mailing list, these cannot be suppressed (except by turning on said option). So maybe, I'll turn on that option for those parts of the code which actually need the variadic templates and turn it off otherwise...
Completely untested, so I have no idea if it actually works, but...
did you try putting the GCC __extension__ keyword on the offending line?
Just tried that, but no, no effect.

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
In the meantime, I found that variadic templates work just fine in gcc-4.4, even without the -std=c++0x option, but they emit warnings. According to the gcc mailing list, these cannot be suppressed (except by turning on said option).
I took a look at the gcc source - there's definitely no flag to disable that warning, but #pragma GCC system_header will do the trick (recent versions of libstdc++ use variadic templates with or without c++0x support enabled). It won't work in C++ source files, just in headers; adding #pragma GCC system_header will tell GCC to treat everything from the pragma to the end of the file as a system header. Note that this will disable a boatload of other warnings. - - Bryce Lelbach -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkx2tf8ACgkQO/fqqIuE2t7w+wCdHhymnm2RQfA/gvbH7ZSluA9I K1AAn12iFtvkbEk94wLskkayjiHdG+Yq =ye1V -----END PGP SIGNATURE-----

On 08/26/2010 08:44 PM, Bryce Lelbach aka wash wrote:
In the meantime, I found that variadic templates work just fine in gcc-4.4, even without the -std=c++0x option, but they emit warnings. According to the gcc mailing list, these cannot be suppressed (except by turning on said option).
I took a look at the gcc source - there's definitely no flag to disable that warning, but #pragma GCC system_header will do the trick (recent versions of libstdc++ use variadic templates with or without c++0x support enabled). It won't work in C++ source files, just in headers; adding #pragma GCC system_header will tell GCC to treat everything from the pragma to the end of the file as a system header. Note that this will disable a boatload of other warnings.
Bryce, yeah, the system_header pragma or the -isystem option are pretty cool if you know for sure that all warnings can be safely ignored. But when developing something new, this is rarely the case. So what I am doing now (seems to work fine): Most of the time, I compile without -std=c++0x, because most of the time, I don't use those new features. But there are some rather isolated classes that use variadic templates for a type-safe communication layer for postgresql. Those classes are compiled with -std=c++0x. Thanks and regards, Roland
participants (4)
-
Artyom
-
Bryce Lelbach aka wash
-
Giovanni Piero Deretta
-
Roland Bock