<legend id='5oFed'><style id='5oFed'><dir id='5oFed'><q id='5oFed'></q></dir></style></legend>
  • <i id='5oFed'><tr id='5oFed'><dt id='5oFed'><q id='5oFed'><span id='5oFed'><b id='5oFed'><form id='5oFed'><ins id='5oFed'></ins><ul id='5oFed'></ul><sub id='5oFed'></sub></form><legend id='5oFed'></legend><bdo id='5oFed'><pre id='5oFed'><center id='5oFed'></center></pre></bdo></b><th id='5oFed'></th></span></q></dt></tr></i><div id='5oFed'><tfoot id='5oFed'></tfoot><dl id='5oFed'><fieldset id='5oFed'></fieldset></dl></div>
  • <small id='5oFed'></small><noframes id='5oFed'>

    <tfoot id='5oFed'></tfoot>

        • <bdo id='5oFed'></bdo><ul id='5oFed'></ul>

        无法使用 Boost.Filesystem 链接程序

        Can#39;t link program using Boost.Filesystem(无法使用 Boost.Filesystem 链接程序)
        <tfoot id='QEOM5'></tfoot>

        <small id='QEOM5'></small><noframes id='QEOM5'>

      1. <i id='QEOM5'><tr id='QEOM5'><dt id='QEOM5'><q id='QEOM5'><span id='QEOM5'><b id='QEOM5'><form id='QEOM5'><ins id='QEOM5'></ins><ul id='QEOM5'></ul><sub id='QEOM5'></sub></form><legend id='QEOM5'></legend><bdo id='QEOM5'><pre id='QEOM5'><center id='QEOM5'></center></pre></bdo></b><th id='QEOM5'></th></span></q></dt></tr></i><div id='QEOM5'><tfoot id='QEOM5'></tfoot><dl id='QEOM5'><fieldset id='QEOM5'></fieldset></dl></div>
          • <legend id='QEOM5'><style id='QEOM5'><dir id='QEOM5'><q id='QEOM5'></q></dir></style></legend>
                <tbody id='QEOM5'></tbody>

                  <bdo id='QEOM5'></bdo><ul id='QEOM5'></ul>
                  本文介绍了无法使用 Boost.Filesystem 链接程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 Ubuntu 12.10 上使用 boost::filesystem 的示例代码运行程序,但它不想构建.

                  I'm trying to run program, using sample code of boost::filesystem on Ubuntu 12.10, but it doesn't want to build.

                  #include <iostream>
                  #include <boost/filesystem.hpp>
                  using namespace boost::filesystem;
                  using namespace std;
                  
                  void fun(const string& dirPath);
                  int main()
                  {
                      fun("/home");
                      return 0;
                  }
                  
                  void fun(const string& dirPath)
                  {
                      path p (dirPath); 
                  
                      if (exists(p))  
                      {
                          if (is_regular_file(p))   
                              cout << p << " size is " << file_size(p) << '
                  ';
                  
                          else if (is_directory(p))    
                              cout << p << "is a directory
                  ";
                  
                          else
                              cout << p << "exists, but is neither a regular file nor a directory
                  ";
                      }
                      else
                          cout << p << "does not exist
                  ";
                  }
                  

                  和 CMake 代码:

                  And CMake code:

                  project(tttest)
                  cmake_minimum_required(VERSION 2.8)
                  aux_source_directory(. SRC_LIST)
                  add_executable(${PROJECT_NAME} ${SRC_LIST})
                  FIND_PACKAGE(Boost 1.53 COMPONENTS filesystem system REQUIRED)
                  include_directories(${Boost_INCLUDE_DIR})
                  link_directories(${Boost_LIBRARY_DIR})
                  TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${Boost_LIBRARIES})
                  

                  不幸的是它会产生错误

                  CMakeFiles/tttest.dir/main.cpp.o: In function `boost::filesystem::exists(boost::filesystem::path const&)':
                  main.cpp:(.text._ZN5boost10filesystem6existsERKNS0_4pathE[_ZN5boost10filesystem6existsERKNS0_4pathE]+0x19): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
                  CMakeFiles/tttest.dir/main.cpp.o: In function `boost::filesystem::is_directory(boost::filesystem::path const&)':
                  main.cpp:(.text._ZN5boost10filesystem12is_directoryERKNS0_4pathE[_ZN5boost10filesystem12is_directoryERKNS0_4pathE]+0x19): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
                  CMakeFiles/tttest.dir/main.cpp.o: In function `boost::filesystem::is_regular_file(boost::filesystem::path const&)':
                  main.cpp:(.text._ZN5boost10filesystem15is_regular_fileERKNS0_4pathE[_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE]+0x19): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
                  CMakeFiles/tttest.dir/main.cpp.o: In function `boost::filesystem::file_size(boost::filesystem::path const&)':
                  main.cpp:(.text._ZN5boost10filesystem9file_sizeERKNS0_4pathE[_ZN5boost10filesystem9file_sizeERKNS0_4pathE]+0x19): undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)'
                  collect2: error: ld returned 1 exit status
                  

                  这个问题的原因是什么,如何解决?

                  What is the reason of this problem and how to solve it?

                  推荐答案

                  Boost 文件系统是 Boost 库之一,由于 C++0x 或 C++11 导致的函数签名更改存在一些 ABI 问题.cf Boost 票:https://svn.boost.org/trac/boost/ticket/6779

                  Boost filesystem is one of the Boost library that have some ABI problem relative to function signature change due to C++0x or C++11. cf Boost ticket : https://svn.boost.org/trac/boost/ticket/6779

                  您有三种解决方案:

                  1. 在程序中包含的相关 Boost 头文件中使用 #include 禁止 C++11 范围的枚举(参见 http://www.ridgesolutions.ie/index.php/2013/05/30/boost-link-error-undefined-reference-to-boostfilesystemdetailcopy_file/):

                  #define BOOST_NO_CXX11_SCOPED_ENUMS
                  #include <boost/filesystem.hpp>
                  #undef BOOST_NO_CXX11_SCOPED_ENUMS
                  

                  但是这个解决方案并不是一个完整的解决方案,我读到它并不适用于所有人.

                  But this solution is not a complete one and I read it does not work for everybody.

                  使用 C++11 选项(与您的应用程序使用的选项相同)构建 BOOST:http://hnrkptrsn.github.io/2013/02/26/c11-and-boost-setup-guide

                  Build BOOST with the C++11 option (the same options you use for your application): http://hnrkptrsn.github.io/2013/02/26/c11-and-boost-setup-guide

                  我也读到它并不适合所有人.

                  I read also it does not work for everybody.

                  设置专用于您的应用程序的交叉编译器,您可以在其中在专用环境中重建所需的所有库.这确保了一致性和稳定性以及更多的可维护性,当然是推荐的解决方案.我还没有读过它是否已经过测试 - 可能是的,并且可能有效.无论如何,交叉编译现在在计算机科学中已经很好地掌握了.你会发现很多好的教程和对它的支持.在 Linux Gentoo 中,他们有很棒的 sys-devel/crossdev 包,这使它变得非常容易.

                  Set up a cross compiler dedicated to your application where you rebuild all the libraries you need in a dedicated environment. That ensures coherence plus stability plus more maintainability, and is certainly the solution to recommend. I have not read if it has been tested - probably yes, and probably it works. Anyway, cross compiling is well mastered now in computer science. You will find many good tutorials and support for it. In Linux Gentoo, they have the marvelous sys-devel/crossdev package that makes it very easy.

                  在我自己的情况下,解决方案 1 已经解决了问题.一遇到其他的就切换到方案三.所以,我还没有测试过.

                  In my own case, solution 1 has solved the problem. As soon as I encounter another one, I will switch to solution 3. So, I have not yet tested it.

                  这篇关于无法使用 Boost.Filesystem 链接程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                  Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                  How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                  What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                  Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                  How boost auto-linking makes choice?(boost自动链接如何做出选择?)

                          <tbody id='CUu9C'></tbody>

                        <small id='CUu9C'></small><noframes id='CUu9C'>

                        <tfoot id='CUu9C'></tfoot>

                            <bdo id='CUu9C'></bdo><ul id='CUu9C'></ul>
                          • <legend id='CUu9C'><style id='CUu9C'><dir id='CUu9C'><q id='CUu9C'></q></dir></style></legend>
                            <i id='CUu9C'><tr id='CUu9C'><dt id='CUu9C'><q id='CUu9C'><span id='CUu9C'><b id='CUu9C'><form id='CUu9C'><ins id='CUu9C'></ins><ul id='CUu9C'></ul><sub id='CUu9C'></sub></form><legend id='CUu9C'></legend><bdo id='CUu9C'><pre id='CUu9C'><center id='CUu9C'></center></pre></bdo></b><th id='CUu9C'></th></span></q></dt></tr></i><div id='CUu9C'><tfoot id='CUu9C'></tfoot><dl id='CUu9C'><fieldset id='CUu9C'></fieldset></dl></div>