CMake不链接指定的库

时间:2014-08-12 20:27:09

标签: c++ cmake mingw-w64 msys2

我正在处理此处托管的项目:https://github.com/gtorrent

目前,我们正在尝试实施更好的Windows支持。图书馆本身(gtorrent-core)构建得很好。但是,每当我们链接它时,对各种libtorrent函数(我们正在构建的库)有许多未定义的引用。我目前正在使用MSYS2和MinGW-w64-x86_64来构建项目本身以及所有必需的库。

对于ncurses gui,我们的CMakeLists.txt文件如下

gtorrent-ncurses的/的CMakeLists.txt:

###############
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(gtorrent-ncurses)

SET(gtorrent-ncurses_VERSION_MAJOR 0)
SET(gtorrent-ncurses_VERSION_MINOR 0)
SET(gtorrent-ncurses_VERSION_PATCH 1)
###############

# Configure version into Version.hpp
SET (VERSION ${gtorrent-ncurses_VERSION_MAJOR}.${gtorrent-ncurses_VERSION_MINOR}.${gtorrent-ncurses_VERSION_PATCH})
CONFIGURE_FILE (src/utils/Version.hpp.in Version.hpp @ONLY)

# Set compiler options
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -Wall")

# Set Cmake to build runtime in cwd
SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})

# Find Boost
SET (Boost_USE_STATIC_LIBS ON)
SET (Boost_USE_MULTITHREADED ON)
SET (Boost_USE_STATIC_RUNTIME OFF)
FIND_PACKAGE(Boost COMPONENTS system REQUIRED)

# Find libtorrent
INCLUDE (FindPkgConfig)
PKG_SEARCH_MODULE (LIBTORRENT REQUIRED libtorrent-rasterbar)

# Find ncurses
INCLUDE(CheckLibraryExists)
PKG_SEARCH_MODULE (NCURSESPP REQUIRED ncurses++w)
PKG_SEARCH_MODULE (NCURSES REQUIRED ncursesw)
PKG_SEARCH_MODULE (NCURSESPANEL REQUIRED panelw)

# To find version
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})

ADD_DEFINITIONS (
    ${LIBTORRENT_CFLAGS}
    )

ADD_SUBDIRECTORY(gtorrent-core)
ADD_SUBDIRECTORY(src)

gtorrent-ncurses的/ SRC /的CMakeLists.txt

INCLUDE_DIRECTORIES (
  ${Boost_INCLUDE_DIRS}
  ${LIBTORRENT_INCLUDE_DIRS}
  ${NCURSESPP_INCLUDE_DIRS}
  ${NCURSES_INCLUDE_DIRS}
  ${CMAKE_SOURCE_DIR}/gtorrent-core/include
  )

ADD_DEFINITIONS (
  ${LIBTORRENT_CFLAGS}
  )

ADD_EXECUTABLE ( gtorrent-ncurses
  main.cpp
  Application.cpp
  MainWindow.cpp
  TorrentView.cpp
  StatusView.cpp
  AddTorrent.cpp
  )

ADD_DEPENDENCIES (gtorrent-ncurses
  gtorrent
  )

LINK_DIRECTORIES (
  ${Boost_LIBRARY_DIRS}
  ${LIBTORRENT_LIBRARY_DIRS}
  )

TARGET_LINK_LIBRARIES ( gtorrent-ncurses
  ${CMAKE_BINARY_DIR}/gtorrent-core/src/libgtorrent.a
  ${Boost_LIBRARIES}
  ${LIBTORRENT_LIBRARIES}
  ${NCURSESPP_LIBRARIES}
  ${NCURSES_LIBRARIES}
  ${NCURSESPANEL_LIBRARIES}
  )

INSTALL (TARGETS gtorrent-ncurses RUNTIME DESTINATION ${PREFIX}/bin/ PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

以下是编译器错误(太大而无法发布):http://pastebin.com/v3fPXXAE

任何想法有什么不对?

1 个答案:

答案 0 :(得分:0)

您在LIBTORRENT_LIBRARIES之前链接BOOST_LIBRARIES。尝试切换顺序,首先链接LIBTORRENT_LIBRARIES,然后链接BOOST_LIBRARIES。链接器仅链接那些之前已链接过的对象实际使用的库对象。