Raspian/Debian: referencia indefinida “timer_create” incluso con -lrt

1 minuto de lectura

Estoy usando timer_create en un programa C++ con Cmake. Sin embargo, en Raspian (¿= Debian?) el enlazador me dice
CppTimer.cpp:(.text+0xd8): undefined reference to timer_create’`

En Opensuse funciona.

He buscado y se menciona que la opción -lrt irá después de los archivos fuente. ¿Cómo puedo obligar a cmake a configurar la biblioteca al final de la línea de comando CC?

El CmakeLists.txt se ve así:

cmake_minimum_required(VERSION 3.0)
# include(FindPkgConfig)
# pkg_check_modules(CURLPP REQUIRED curlpp)

set(CMAKE_CXX_STANDARD 17) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11

project(energycons)

find_library(CURLPP curlpp)
find_library(CURL curl)
find_library(TZ date-tz)

add_executable(energycons main.cpp 
    CppTimer.h CppTimer.cpp CppTimerCallback.h
   ....)

add_link_options(-lrt)

TARGET_LINK_LIBRARIES(energycons ${CURL} ${CURLPP} ${TZ})

install(TARGETS energycons RUNTIME DESTINATION bin)

Ya intenté colocar add_link_options(-lrt) en diferentes lugares.

  • add_link_options(-lrt) es impar. Agregar rt en TARGET_LINK_LIBRARIES

    – 273K

    4 de febrero a las 15:31


¿Ha sido útil esta solución?