我試圖從boost documentationgzip_decompressor在克利翁(CPP Boost庫)
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
int main()
{
using namespace std;
ifstream file("example.txt.gz", ios_base::in | ios_base::binary);
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::gzip_decompressor());
in.push(file);
boost::iostreams::copy(in, cout);
}
我$brew install boost
安裝升壓解壓使用示例代碼gzip文件未找到。 按照CLion documentation中的說明,我已經在CLion中包含了使用動態模板的增強庫。
但是,這個簡單的代碼不起作用。 (編輯錯誤信息)
libc++abi.dylib: terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::iostreams::gzip_error> >: gzip error: unspecified iostream_category error
我懷疑gzip_decompressor不能被識別。
尋找一個解決方案!
編輯:
1)這是CMakeLists.txt文件。
cmake_minimum_required(VERSION 3.7)
project(practice_cpp)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
find_package(Boost REQUIRED COMPONENTS system iostreams)
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
include_directories(${Boost_INCLUDE_DIRS})
endif()
add_executable(practice_cpp ${SOURCE_FILES})
if(Boost_FOUND)
target_link_libraries(practice_cpp ${Boost_LIBRARIES})
endif()
2)另外,我在終端上試過這個命令。
c++ -I /usr/local/Cellar/boost/1.63.0 main.cpp -lboost_iostreams -o main
其輸出
$ ./main
libc++abi.dylib: terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::iostreams::gzip_error> >: gzip error: unspecified iostream_category error
Abort trap: 6
3)這是commands_compile.json。
[
{
"directory": "/path/to/practice_cpp",
"command": "/Library/Developer/CommandLineTools/usr/bin/c++ -I/usr/local/include -g -std=gnu++11 -o CMakeFiles/practice_cpp.dir/main.cpp.o -c /path/to/practice_cpp/main.cpp",
"file": "/path/to/practice_cpp/main.cpp"
}
]
4)$使VERBOSE = ON
$ make VERBOSE=ON
/usr/local/Cellar/cmake/3.7.2/bin/cmake -H/path/to/practice_cpp -B/path/to/practice_cpp --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_progress_start /path/to/practice_cpp/CMakeFiles /path/to/practice_cpp/CMakeFiles/progress.marks
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/Makefile2 all
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/practice_cpp.dir/build.make CMakeFiles/practice_cpp.dir/depend
cd /path/to/practice_cpp && /usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_depends "Unix Makefiles" /path/to/practice_cpp /path/to/practice_cpp /path/to/practice_cpp /path/to/practice_cpp /path/to/practice_cpp/CMakeFiles/practice_cpp.dir/DependInfo.cmake --color=
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/practice_cpp.dir/build.make CMakeFiles/practice_cpp.dir/build
make[2]: Nothing to be done for `CMakeFiles/practice_cpp.dir/build'.
[100%] Built target practice_cpp
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_progress_start /path/to/practice_cpp/CMakeFiles 0
什麼是CMakeLists.txt的_actual_內容。編程不是「馴服IDE的藝術」。如果有的話,這是馴服編譯器的藝術,而IDE僅僅是一個工具[可以阻礙]。 – sehe
你必須鏈接'-lboost_iostreams'庫。請顯示你的'cmake'文件。如果它有'find_package(Boost ...'字符串,然後添加'iostreams'。例如像這樣︰'find_package(Boost REQUIRED COMPONENTS system iostreams)' – JustRufus
另外,我懷疑該平臺是OSX?嘗試傳遞'cmake -DCMAKE_EXPORT_COMPILE_COMMANDS '並檢查'compile_commands.json' – sehe