简体   繁体   中英

Boost compilation error when building from scratch

I am trying to build the boost FileSystem library for a project. When i try to build the library, i get theses errors:

In file included from filesystem/convenience.hpp:22:0,
                 from filesystem/src/convenience.cpp:17:
filesystem/operations.hpp:399:8: erreur: ‘bool boost::filesystem::create_directories(const boost::filesystem::path&)’ previously defined here
   bool create_directories(const path& p) {return detail::create_directories(p);}
        ^
libs/filesystem/src/convenience.cpp:38:18: erreur: ‘not_directory_error’ was not declared in this scope
                  not_directory_error ) );
                  ^
libs/filesystem/src/convenience.cpp: In function ‘std::string boost::filesystem::extension(const boost::filesystem::path&)’:
libs/filesystem/src/convenience.cpp:49:39: erreur: redefinition of ‘std::string boost::filesystem::extension(const boost::filesystem::path&)’
     BOOST_FILESYSTEM_DECL std::string extension(const path& ph)
                                       ^
In file included from libs/filesystem/src/convenience.cpp:17:0:
/usr/include/boost/filesystem/convenience.hpp:34:24: erreur: ‘std::string boost::filesystem::extension(const boost::filesystem::path&)’ previously defined here
     inline std::string extension(const path & p)
                        ^
libs/filesystem/src/convenience.cpp:51:34: erreur: conversion from ‘boost::filesystem::path’ to non-scalar type ‘std::string {aka std::basic_string<char>}’ requested
       std::string leaf = ph.leaf();
                                  ^
libs/filesystem/src/convenience.cpp: In function ‘std::string boost::filesystem::basename(const boost::filesystem::path&)’:
libs/filesystem/src/convenience.cpp:60:39: erreur: redefinition of ‘std::string boost::filesystem::basename(const boost::filesystem::path&)’
     BOOST_FILESYSTEM_DECL std::string basename(const path& ph)
                                       ^
In file included from libs/filesystem/src/convenience.cpp:17:0:
/usr/include/boost/filesystem/convenience.hpp:39:24: erreur: ‘std::string boost::filesystem::basename(const boost::filesystem::path&)’ previously defined here
     inline std::string basename(const path & p)
                        ^
libs/filesystem/src/convenience.cpp:62:34: erreur: conversion from ‘boost::filesystem::path’ to non-scalar type ‘std::string {aka std::basic_string<char>}’ requested
       std::string leaf = ph.leaf();

This does look more like a problem with the code than a link error, which i can not understand.

First i thought that the version of GCC (4.8.5) i am using was the problem as i am trying to build boost 1.33. However, i tested it with a more recent version of boost and i still got similar errors.

Also, here is the code from the file Convenience.cpp which seems to be the source of the errors:


// define BOOST_FILESYSTEM_SOURCE so that <boost/filesystem/config.hpp> knows
// the library is being built (possibly exporting rather than importing code)
#define BOOST_FILESYSTEM_SOURCE 

#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/throw_exception.hpp>

#include <boost/config/abi_prefix.hpp> // must be the last header

namespace boost
{
  namespace filesystem
  {

//  create_directories (contributed by Vladimir Prus)  -----------------------//

     BOOST_FILESYSTEM_DECL bool create_directories(const path& ph)
     {
         if (ph.empty() || exists(ph))
         {
           if ( !ph.empty() && !is_directory(ph) )
               boost::throw_exception( filesystem_error(
                 "boost::filesystem::create_directories",
                 ph, "path exists and is not a directory",
                 not_directory_error ) );
           return false;
         }

         // First create branch, by calling ourself recursively
         create_directories(ph.branch_path());
         // Now that parent's path exists, create the directory
         create_directory(ph);
         return true;
     }

    BOOST_FILESYSTEM_DECL std::string extension(const path& ph)
    {
      std::string leaf = ph.leaf();

      std::string::size_type n = leaf.rfind('.');
      if (n != std::string::npos)
        return leaf.substr(n);
      else
        return std::string();
    }

    BOOST_FILESYSTEM_DECL std::string basename(const path& ph)
    {
      std::string leaf = ph.leaf();

      std::string::size_type n = leaf.rfind('.');
      return leaf.substr(0, n);
    }

    BOOST_FILESYSTEM_DECL path change_extension(const path& ph, const std::string& new_extension)
    {
      return ph.branch_path() / (basename(ph) + new_extension);
    }


  } // namespace filesystem
} // namespace boost

here is the makefile i am using. (note that there are a few environement variables used here. those are already assigned and at the correct values.

###########################################################################
#              Definition of the compiler and it's options
###########################################################################

CCC = ${PRJ_SOLVER} ${PRJ_DEBUG}
CC = ${PRJ_SOLVER_C} ${PRJ_DEBUG}
LD = ${PRJ_LINK} ${PRJ_DEBUG}

###########################################################################
#              Definition of the external includes
###########################################################################

INCLUDE_EXT = -I${HOME}/Documents/boost_1_33_1

###########################################################################
#              Sources for libs/filesystem
###########################################################################

DIR_1 =  ${PRJ_MOD_COUR_REP}/src

SRC_1 =  \
    ${DIR_1}/convenience.cpp \
    ${DIR_1}/exception.cpp \
    ${DIR_1}/operations_posix_windows.cpp \
    ${DIR_1}/path_posix_windows.cpp

OBJ_1 =  \
    ${PRJ_LIB_COUR_REP}/convenience.o \
    ${PRJ_LIB_COUR_REP}/exception.o \
    ${PRJ_LIB_COUR_REP}/operations_posix_windows.o \
    ${PRJ_LIB_COUR_REP}/path_posix_windows.o

###########################################################################

###########################################################################
#              Includes and object files pour current directory
###########################################################################

INCLUDE_COUR = -I$(DIR_1)

OBJ_COUR = $(OBJ_1)

###########################################################################
#              default compilation
###########################################################################

all: lib

###########################################################################
#              dependancies rules for the sources of the current directory
###########################################################################

${PRJ_LIB_COUR_REP}/convenience.o : $(DIR_1)/convenience.cpp
    @echo "Compilation en C++: $(DIR_1)/convenience.cpp"
    $(CCC) -c $(DIR_1)/convenience.cpp -o ${PRJ_LIB_COUR_REP}/convenience.o ${INCLUDE_COUR} ${INCLUDE_EXT}

${PRJ_LIB_COUR_REP}/exception.o : $(DIR_1)/exception.cpp
    @echo "Compilation en C++: $(DIR_1)/exception.cpp"
    $(CCC) -c $(DIR_1)/exception.cpp -o ${PRJ_LIB_COUR_REP}/exception.o ${INCLUDE_COUR} ${INCLUDE_EXT}

${PRJ_LIB_COUR_REP}/operations_posix_windows.o : $(DIR_1)/operations_posix_windows.cpp
    @echo "Compilation en C++: $(DIR_1)/operations_posix_windows.cpp"
    $(CCC) -c $(DIR_1)/operations_posix_windows.cpp -o ${PRJ_LIB_COUR_REP}/operations_posix_windows.o ${INCLUDE_COUR} ${INCLUDE_EXT}

${PRJ_LIB_COUR_REP}/path_posix_windows.o : $(DIR_1)/path_posix_windows.cpp
    @echo "Compilation en C++: $(DIR_1)/path_posix_windows.cpp"
    $(CCC) -c $(DIR_1)/path_posix_windows.cpp -o ${PRJ_LIB_COUR_REP}/path_posix_windows.o ${INCLUDE_COUR} ${INCLUDE_EXT}

###########################################################################
#              cleaning object files
###########################################################################

clean:
    @echo ""
    @echo "Nettoyage des fichiers objets associes a BoostFileSystem"
    rm -rf $(PRJ_LIB_COUR_REP)/*
    rm -f $(PRJ_LIB_COUR_REP)/.make.state
    @echo ""

###########################################################################
#              creation of static library .a
###########################################################################

lib: ${OBJ_COUR}
    @echo ""
    @echo "Creation de la librairie de BoostFileSystem"
    ar -r $(PRJ_LIB_COUR_REP)/libBoostFileSystem.a $(OBJ_COUR)
    @echo ""

###########################################################################
#              miscelanious
###########################################################################

.INIT:
.DONE:
.SILENT:
${PRJ_KEEP_STATE}:
.SUFFIXES: .o .cc .c

[Edit]

The makefile i was given had an include oath that was wrong. Obviously that caused some problems. however now that i fixed it, i am getting different errors. This time it looks like these are related to the compiler i am using i am still not sure though. i found people who seemed to have a simiar problem which they say they solved by replacing the #elsif by a #else.

here they are

In file included from boost/mpl/apply.hpp:23:0,
                 from boost/iterator/iterator_facade.hpp:34,
                 from boost/filesystem/path.hpp:16,
                 from boost/filesystem/convenience.hpp:16,
                 from libs/filesystem/src/convenience.cpp:17:
boost/mpl/apply_wrap.hpp:81:31: erreur: missing binary operator before token "("
 #elif BOOST_PP_ITERATION_DEPTH() == 1
                               ^
boost/mpl/apply_wrap.hpp:173:31: erreur: missing binary operator before token "("
 #elif BOOST_PP_ITERATION_DEPTH() == 2
                               ^
In file included from boost/mpl/bind.hpp:27:0,
                 from boost/mpl/lambda.hpp:18,
                 from boost/mpl/apply.hpp:25,
                 from boost/iterator/iterator_facade.hpp:34,
                 from boost/filesystem/path.hpp:16,
                 from boost/filesystem/convenience.hpp:16,
                 from libs/filesystem/src/convenience.cpp:17:
boost/mpl/apply_wrap.hpp:81:31: erreur: missing binary operator before token "("
 #elif BOOST_PP_ITERATION_DEPTH() == 1
                               ^
boost/mpl/apply_wrap.hpp:173:31: erreur: missing binary operator before token "("
 #elif BOOST_PP_ITERATION_DEPTH() == 2
                               ^
In file included from boost/mpl/lambda.hpp:18:0,
                 from boost/mpl/apply.hpp:25,
                 from boost/iterator/iterator_facade.hpp:34,
                 from boost/filesystem/path.hpp:16,
                 from boost/filesystem/convenience.hpp:16,
                 from libs/filesystem/src/convenience.cpp:17:
boost/mpl/bind.hpp:364:31: erreur: missing binary operator before token "("
 #elif BOOST_PP_ITERATION_DEPTH() == 1
                               ^
boost/mpl/bind.hpp:531:31: erreur: missing binary operator before token "("
 #elif BOOST_PP_ITERATION_DEPTH() == 2
                               ^
In file included from boost/mpl/lambda.hpp:22:0,
                 from boost/mpl/apply.hpp:25,
                 from boost/iterator/iterator_facade.hpp:34,
                 from boost/filesystem/path.hpp:16,
                 from boost/filesystem/convenience.hpp:16,
                 from libs/filesystem/src/convenience.cpp:17:
boost/mpl/aux_/full_lambda.hpp:230:31: erreur: missing binary operator before token "("
 #elif BOOST_PP_ITERATION_DEPTH() == 1
                               ^
In file included from boost/iterator/iterator_facade.hpp:34:0,
                 from boost/filesystem/path.hpp:16,
                 from boost/filesystem/convenience.hpp:16,
                 from libs/filesystem/src/convenience.cpp:17:
boost/mpl/apply.hpp:138:31: erreur: missing binary operator before token "("
 #elif BOOST_PP_ITERATION_DEPTH() == 1

It looks like you mix different versions of boost. One from /usr/include and another from /home/slendorm/Documents/ASPECT/boost_1_33_1/ . You need to make sure that boost include files come from /home/slendorm/Documents/ASPECT/boost_1_33_1/ only.

I found the solution to my problem. First, as Maxim Egorushkin said, there was an error in the include path inside the makefile which led to boost includes comming from two differents places.

Secondly, I had a problem with the preprocessor on every #elif that was present in the .hpp that were included.

I solved this problem by replacing the #elseif by #else and #if .

the file structure was changed from:

#if !defined(BOOST_MPL_PREPROCESSING_MODE)
...
...
#elif BOOST_PP_ITERATION_DEPTH() == 1
...
...
#endif

to:

#if !defined(BOOST_MPL_PREPROCESSING_MODE)
...
...
#else
#if BOOST_PP_ITERATION_DEPTH() == 1
...
...
#endif
#endif

I have however no idea why this is working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM