Crushing
Crushing

Reputation: 447

CMake user built libraries; cannot specify link libraries for target

I'm building a project in Cpp that will communicate with my Java apps via rabbitmq and post updates to twitter. I'm using a few libraries from github

  1. rabbitmq-c

    Rabbit installed to /usr/local/lib64

  2. jansson - json library

    I installed this a while back for another project, went to /usr/local/lib

  3. twitcurl - C lib for Twitter API

    Got installed to /usr/local/lib

If it matters, I'm using CLion as my IDE, which displays jansson and rabbit under auto-complete when defining includes - so that's picking the libs off my system somehow

e.g.
#include <jansson.h>
#include <amqp.h>

I link them using the target_link_libraries(name libs...) and I see output saying

build$ cmake ..

CMake Error at CMakeLists.txt:30 (target_link_libraries):
  Cannot specify link libraries for target "twitcurl" which is not built by
  this project.

I set LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64

I try to set the CMAKE_LIBRARY_PATH to include usr/local/lib and lib64 but doesn't seem to have any effect. Here's my CMakeLists.txt file

#
# This is a CMake makefile.  You can find the cmake utility and
# information about it at http://www.cmake.org
#

cmake_minimum_required(VERSION 2.6)

set(PROJECT_NAME twitterUpdater)
set(SOURCE_FILES main.cpp)

set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "/usr/local/lib"
        "/usr/local/lib64")

project(${PROJECT_NAME})
find_package(X11 REQUIRED)
find_package(OpenCV REQUIRED)

IF (X11_FOUND)
    INCLUDE_DIRECTORIES(${X11_INCLUDE_DIR})
    LINK_LIBRARIES(${X11_LIBRARIES})
ENDIF ( X11_FOUND )

IF (OpenCV_FOUND)
    include_directories(${OpenCV_INCLUDE_DIRS})
    link_libraries(${OpenCV_LIBS})
ENDIF(OpenCV_FOUND)

add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${project_name} twitcurl jansson rabbitmq)

What's confusing me is another project I have uses jansson by simply adding it here TARGET_LINK_LIBRARIES(${project_name} dlib jansson)

What did I miss?? Thanks

Upvotes: 2

Views: 4861

Answers (1)

sakra
sakra

Reputation: 65751

CMake variables are case sensitive, thus the variable ${project_name} results in an empty string. Use ${PROJECT_NAME} instead, i.e.:

target_link_libraries(${PROJECT_NAME} twitcurl jansson rabbitmq)

Running CMake with the flag --warn-uninitialized helps you detect mistakes like this.

Upvotes: 3

Related Questions