0

I'm working on a project hosted here: https://github.com/gtorrent

Right now, we're trying to implement better Windows support. The library itself (gtorrent-core) builds fine. However, whenever we link against it, there are many undefined references to various libtorrent functions (the library we're building off of). I am currently using MSYS2 and MinGW-w64-x86_64 to build the project itself as well as all required libraries.

For the ncurses gui, our CMakeLists.txt files are as follows

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)

And here are the compiler errors (too big to post): http://pastebin.com/v3fPXXAE

Any ideas what is wrong?

thor
  • 21,418
  • 31
  • 87
  • 173
ragesalmon
  • 627
  • 1
  • 5
  • 10
  • Try to rewrite you root cmake config as: CMAKE_MINIMUM_REQUIRED(VERSION 2.8) ENABLE_LANGUAGE(CXX) PROJECT(gtorrent-ncurses) I have a trong feeling that you try to build C++ project using C – Tanuki Aug 13 '14 at 05:05

1 Answers1

0

Your are linking BOOST_LIBRARIES before LIBTORRENT_LIBRARIES. Try to switch the order, first link LIBTORRENT_LIBRARIES, then link BOOST_LIBRARIES. The linker links only those objects of an library that are actually used by the objects that have been linked before.

martin
  • 56
  • 5