麻烦编译使用boost asio的项目

时间:2014-09-02 11:19:01

标签: c++ boost cmake mingw

我创建了一个使用一些boost库的项目。最初该项目是使用MinGW创建的Eclipse项目,并且工作正常。现在我正在尝试将其转换为CMake项目。

我使用CMake准备MinGW makefile并尝试编译它但得到以下错误:

In file included from D:/Krzych/usr/local/include/boost/date_time/c_time.hpp:17:0,
                 from D:/Krzych/usr/local/include/boost/date_time/time_clock.hpp:16,
                 from D:/Krzych/usr/local/include/boost/date_time/posix_time/posix_time_types.hpp:10,
                 from D:/Krzych/usr/local/include/boost/asio/time_traits.hpp:24,
                 from D:/Krzych/usr/local/include/boost/asio/deadline_timer_service.hpp:27,
                 from D:/Krzych/usr/local/include/boost/asio/basic_deadline_timer.hpp:25,
                 from D:/Krzych/usr/local/include/boost/asio.hpp:22,
                 from D:/Krzych/Projects/Picard/PicardDebugLink/include/CCommunicationAgent.h:22,
                 from D:\Krzych\Projects\Picard\PicardDebugLink\source\CCommunicationAgent.cpp:12:
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ctime:65:11: error: '::difftime' has not been declared
   using ::difftime;
           ^
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ctime:66:11: error: '::mktime' has not been declared
   using ::mktime;

time.h中引用的ctime中的每个符号重复相同类型的错误。如您所见,boost date_time库直接包含ctime

编辑 - CMake文件 -

主要CMakeLists.txt

cmake_minimum_required (VERSION 2.6)
project (PicardDebugLink)
# The version number.
set (PicardDebugLink_VERSION_MAJOR 0)
set (PicardDebugLink_VERSION_MINOR 9)

if(WIN32)
    macro(get_WIN32_WINNT version)
        if (WIN32 AND CMAKE_SYSTEM_VERSION)
            set(ver ${CMAKE_SYSTEM_VERSION})
            string(REPLACE "." "" ver ${ver})
            string(REGEX REPLACE "([0-9])" "0\\1" ver ${ver})

            set(${version} "0x${ver}" CACHE PATH "x")
        endif()
    endmacro()

    get_WIN32_WINNT(platform_code)
    add_definitions(-D_WIN32_WINNT=${platform_code})
endif()

# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
  "${PROJECT_SOURCE_DIR}/PicardDebugLinkConfig.h.in"
  "${PROJECT_BINARY_DIR}/PicardDebugLinkConfig.h"
  )

set(CMAKE_CXX_FLAGS "-std=c++11" CACHE STRING "C++2011 features are required" FORCE)

find_package (Boost REQUIRED atomic chrono date_time system timer thread)
include_directories( ${Boost_INCLUDE_DIRS} )

# add the binary tree to the search path for include files
include_directories("${PROJECT_BINARY_DIR}")
include_directories(include)
add_subdirectory(source)

get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
message(status "** inc_dirs: ${inc_dirs}")

# build a CPack driven installer package
# include (InstallRequiredSystemLibraries)
set (CPACK_PACKAGE_VERSION_MAJOR "${TreeEight_VERSION_MAJOR}")
set (CPACK_PACKAGE_VERSION_MINOR "${TreeEight_VERSION_MINOR}")
include (CPack)

source子目录的文件:

# add the executable
add_library(PicardDebugLink SHARED CCommunicationAgent.cpp
    CCommProtocol.cpp
CCreateTest.cpp
    CDataStorage.cpp
    CException.cpp
    CFlashErase.cpp
    CFlashFileIOBuff.cpp
    CFlashMemIOBuff.cpp
    CFlashWriteFile.cpp
    CFlashWriteMem.cpp
    CFrameCreator.cpp
    CIOBuff.cpp
    CSerialLink.cpp
    ErrorCategories.cpp
    FlashProtocols.cpp
    IThrowable.cpp
    ProgramFPGADataHelpers.cpp
    ProgramFPGAProtocols.cpp
    SPicardCommunicationFrame.cpp
    utilities.cpp
)

get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)

target_link_libraries(PicardDebugLink ${Boost_LIBRARIES} )

# add the install targets
install (TARGETS PicardDebugLink DESTINATION bin)
install (FILES "include/*.h" DESTINATION include)

0 个答案:

没有答案