2017-12-14 18 views
0

cygwinでファイルシステムを使用している間にブーストに固執しました。エラーコードのこの単純な部分で発生します。cygwinディレクトリのイテレータでファイルシステムをブーストします

#define BOOST_NO_CXX11_SCOPED_ENUMS 
#include <fstream> 
#include <boost/filesystem/operations.hpp> 
#include <boost/filesystem/fstream.hpp> 
#include <iostream> 
using namespace boost::filesystem; 

int main(int argc, char **argv) 

{ 
    path targetDir("/cygdrive/d/Repositories/testmodels/"); 

    if (exists(targetDir)) { 
     cout << "directory exists!" << endl; 
     directory_iterator end_itr; // default construction yields past-the-end 
     for (directory_iterator itr(targetDir); itr != end_itr; ++itr) 
     { 
      cout << *itr << endl; 
     } 
    } 
} 

次のエラーがリンク時に発生します。

CMakeFiles/test.dir/main.cpp.o:main.cpp:(.text+0x4d3): undefined reference to `boost::filesystem::detail::dir_itr_close(void*&)' 
CMakeFiles/test.dir/main.cpp.o:main.cpp:(.text+0x4d3): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::dir_itr_close(void*&)' 
CMakeFiles/test.dir/main.cpp.o:main.cpp:(.text$_ZN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEE7disposeEv[_ZN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEE7disposeEv]+0x18): undefined reference to `boost::filesystem::detail::dir_itr_close(void*&)' 
CMakeFiles/test.dir/main.cpp.o:main.cpp:(.text$_ZN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEE7disposeEv[_ZN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEE7disposeEv]+0x18): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::dir_itr_close(void*&)' 
collect2: fout: ld gaf exit-status 1 terug 
make[2]: *** [test/CMakeFiles/test.dir/build.make:454: test/test.exe] Error 1 
make[2]: Directory '/cygdrive/d/Repositories/test/build' exited 
make[1]: *** [CMakeFiles/Makefile2:144: test/CMakeFiles/test.dir/all] Error 2 
make[1]: Directory '/cygdrive/d/Repositories/test/build' exited 
make: *** [Makefile:98: all] Error 2 

私はそれが32/64ビットの問題だと仮定し、私はそれを解決する方法がわかりません...

PSいいえ。 1

CMakeも先に問題を警告しました(エラーはありません)。ここでは、関連する抽出物があります:

-- The CXX compiler identification is GNU 6.4.0 
CMake Warning at /usr/share/cmake-3.6.2/Modules/Platform/CYGWIN.cmake:15 (message): 
CMake no longer defines WIN32 on Cygwin! 
(1) If you are just trying to build this project, ignore this warning or 
quiet it by setting CMAKE_LEGACY_CYGWIN_WIN32=0 in your environment or in 
the CMake cache. If later configuration or build errors occur then this 
project may have been written under the assumption that Cygwin is WIN32. 
In that case, set CMAKE_LEGACY_CYGWIN_WIN32=1 instead. 
(2) If you are developing this project, add the line 
set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required 
at the top of your top-level CMakeLists.txt file or set the minimum 
required version of CMake to 2.8.4 or higher. Then teach your project to 
build on Cygwin without WIN32. 

は、だから私はcmake -DCMAKE_LEGACY_CYGWIN_WIN32=0 ..を再実行し、警告メッセージが消えますが、エラーがまだ発生します。

PS番号2

上記のコードでforループをコメントアウトすると、リンクエラーが消えます。どのようにこのことが起こるかわからない...

何か提案がありますか?

UPDATE: BoostはCygwinインストーラーとともにインストールされました。私はCygwinとCygwin64の両方でこれを試しました。 CMakeLists.txtが下に追加されます(実行ファイルは、src /サブディレクトリ内の別のCMakeListsファイルに作成されますが、これは重要ではありません)。

CMakeLists.txt:

# Project 
project(test) 

set(CMAKE_LEGACY_CYGWIN_WIN32 0) 
set(CMAKE_VERBOSE_MAKEFILE ON) 
# Version Number 
set(VERSION_MAJOR 0) 
set(VERSION_MINOR 0) 

# CMAKE version 
cmake_minimum_required(VERSION 2.8) 

# C++11 support 
if(WIN32) 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 
else() 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") 
endif(WIN32) 

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/bin") 

set(CMAKE_BUILD_TYPE Debug) 

# Malloc & Unistd 
INCLUDE (CheckIncludeFiles) 
CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H) 
add_definitions(-DHAVE_MALLOC_H) 
CHECK_INCLUDE_FILES (unistd.h HAVE_UNISTD_H) 
add_definitions(-DHAVE_UNISTD_H) 

# General include, for third party header files. 
message(STATUS "Including /include") 
include_directories(${PROJECT_SOURCE_DIR}/include) 

find_package(Boost COMPONENTS filesystem REQUIRED) 

# Subdirectories 
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src") 
add_subdirectory(src) 

答えて

0

は、Cygwinのターミナルでブーストライブラリをインストールするか、Cygwinのインストーラ(簡単に)を経由してブーストをインストールしようとするようにしてください。 助けにならない場合は、CMakeListsファイルを表示してください。

+0

実際にBoostはCygwinインストーラによってインストールされました。私は多分、次の行を追加することに役立つ追加CMakeLists.txt – user2416984

+0

と私のポストを更新: '場合(Boost_FOUND) include_directories($ {Boost_INCLUDE_DIRS}) target_link_libraries(テスト$ {Boost_LIBRARIES}) ENDIFを()' –

関連する問題