我正在尝试为项目构建boost FileSystem库。 当我尝试构建库时,出现以下错误:
In file included from /usr/include/boost/filesystem/convenience.hpp:22:0,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/libs/filesystem/src/convenience.cpp:17:
/usr/include/boost/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);}
^
/home/slendorm/Documents/ASPECT/boost_1_33_1/libs/filesystem/src/convenience.cpp:38:18: erreur: ‘not_directory_error’ was not declared in this scope
not_directory_error ) );
^
/home/slendorm/Documents/ASPECT/boost_1_33_1/libs/filesystem/src/convenience.cpp: In function ‘std::string boost::filesystem::extension(const boost::filesystem::path&)’:
/home/slendorm/Documents/ASPECT/boost_1_33_1/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 /home/slendorm/Documents/ASPECT/boost_1_33_1/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)
^
/home/slendorm/Documents/ASPECT/boost_1_33_1/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();
^
/home/slendorm/Documents/ASPECT/boost_1_33_1/libs/filesystem/src/convenience.cpp: In function ‘std::string boost::filesystem::basename(const boost::filesystem::path&)’:
/home/slendorm/Documents/ASPECT/boost_1_33_1/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 /home/slendorm/Documents/ASPECT/boost_1_33_1/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)
^
/home/slendorm/Documents/ASPECT/boost_1_33_1/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();
这看起来更像是代码问题,而不是链接错误,我无法理解。
首先,我以为我正在使用的GCC(4.8.5)版本是我尝试构建Boost 1.33时遇到的问题。但是,我使用了最新版本的boost测试它,但仍然出现类似的错误。
此外,这是文件Convenience.cpp中的代码,它似乎是错误的根源:
// 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
这是我正在使用的makefile。 (请注意,这里使用了一些环境变量。这些变量已经被分配并且具有正确的值。
###########################################################################
# 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/ASPECT/boost_1_33_1
###########################################################################
# Sources for /home/slendorm/ASPECT/boost_1_33_1/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
[编辑]
我得到的makefile有一个错误的包含誓言。显然,这引起了一些问题。但是,现在我解决了它,我遇到了不同的错误。这次看起来这些与我正在使用的编译器有关,但是我仍然不确定。 我发现人们似乎有一个类似的问题,他们说可以通过将#elsif替换为#else来解决。
在这里
In file included from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/apply.hpp:23:0,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/iterator/iterator_facade.hpp:34,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/filesystem/path.hpp:16,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/filesystem/convenience.hpp:16,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/libs/filesystem/src/convenience.cpp:17:
/home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/apply_wrap.hpp:81:31: erreur: missing binary operator before token "("
#elif BOOST_PP_ITERATION_DEPTH() == 1
^
/home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/apply_wrap.hpp:173:31: erreur: missing binary operator before token "("
#elif BOOST_PP_ITERATION_DEPTH() == 2
^
In file included from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/bind.hpp:27:0,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/lambda.hpp:18,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/apply.hpp:25,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/iterator/iterator_facade.hpp:34,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/filesystem/path.hpp:16,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/filesystem/convenience.hpp:16,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/libs/filesystem/src/convenience.cpp:17:
/home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/apply_wrap.hpp:81:31: erreur: missing binary operator before token "("
#elif BOOST_PP_ITERATION_DEPTH() == 1
^
/home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/apply_wrap.hpp:173:31: erreur: missing binary operator before token "("
#elif BOOST_PP_ITERATION_DEPTH() == 2
^
In file included from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/lambda.hpp:18:0,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/apply.hpp:25,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/iterator/iterator_facade.hpp:34,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/filesystem/path.hpp:16,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/filesystem/convenience.hpp:16,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/libs/filesystem/src/convenience.cpp:17:
/home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/bind.hpp:364:31: erreur: missing binary operator before token "("
#elif BOOST_PP_ITERATION_DEPTH() == 1
^
/home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/bind.hpp:531:31: erreur: missing binary operator before token "("
#elif BOOST_PP_ITERATION_DEPTH() == 2
^
In file included from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/lambda.hpp:22:0,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/apply.hpp:25,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/iterator/iterator_facade.hpp:34,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/filesystem/path.hpp:16,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/filesystem/convenience.hpp:16,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/libs/filesystem/src/convenience.cpp:17:
/home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/aux_/full_lambda.hpp:230:31: erreur: missing binary operator before token "("
#elif BOOST_PP_ITERATION_DEPTH() == 1
^
In file included from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/iterator/iterator_facade.hpp:34:0,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/filesystem/path.hpp:16,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/boost/filesystem/convenience.hpp:16,
from /home/slendorm/Documents/ASPECT/boost_1_33_1/libs/filesystem/src/convenience.cpp:17:
/home/slendorm/Documents/ASPECT/boost_1_33_1/boost/mpl/apply.hpp:138:31: erreur: missing binary operator before token "("
#elif BOOST_PP_ITERATION_DEPTH() == 1
答案 0 :(得分:0)
您似乎混合了不同版本的boost。一个来自/usr/include
,另一个来自/home/slendorm/Documents/ASPECT/boost_1_33_1/
。您需要确保boost包含文件仅来自/home/slendorm/Documents/ASPECT/boost_1_33_1/
。
答案 1 :(得分:0)
我找到了解决问题的方法。 首先,正如Maxim Egorushkin所说,makefile内的include路径存在错误,导致来自两个不同地方的boost包含都出现了。
其次,我在每个预处理器上都遇到了问题 包含在.hpp中的 #elif 。
我通过用 #else 和 #if 替换 #elseif 解决了这个问题。
文件结构已从:
#if !defined(BOOST_MPL_PREPROCESSING_MODE)
...
...
#elif BOOST_PP_ITERATION_DEPTH() == 1
...
...
#endif
收件人:
#if !defined(BOOST_MPL_PREPROCESSING_MODE)
...
...
#else
#if BOOST_PP_ITERATION_DEPTH() == 1
...
...
#endif
#endif
但是我不知道为什么这样做。