0

I'm trying to use libtidy in my C project . I build tidy code and get *.so file. when I try to link this file to my project by cmake, receive following error message :

CMake Error at CMakeLists.txt:8 (TARGET_LINK_LIBRARIES):
 Cannot specify link libraries for target "GLBall" which is not built by
 this project.

-- Configuring incomplete, errors occurred!
See also "/root/isefa/build/CMakeFiles/CMakeOutput.log".

and here is my CMakeLists.txt :

cmake_minimum_required(VERSION 3.0.0)
project(test C CXX)
set(CMAKE_BUILD_TYPE Release)
include_directories(include)
file(GLOB SOURCES "src/*.c")
#add_library (libtidy SHARED /usr/lib)
LINK_DIRECTORIES(/usr/lib/)
TARGET_LINK_LIBRARIES(GLBall libtidy)
add_executable(test ./bin)
install (TARGETS test DESTINATION /usr/lib) 
Mahdi Akhi
  • 11
  • 8
  • You never create an executable (or other target) named `GLBall`, how can you add libraries to that nonexistent target? Did you perhaps mean `target_link_libraries(test tidy)` (which must then be placed after you create the `test` executable target)? – Some programmer dude Jan 14 '20 at 12:36

1 Answers1

0

First of all you need to find your library in Cmake ( for example, here is a snippet for Restbed) :

find_library(RESTBED_LIBRARY
         NAMES 
            restbed
         PATHS 
            ${RESTBED_ROOT}/build_release
            ${RESTBED_ROOT}/Release
)

if ( NOT RESTBED_LIBRARY )
        message( WARNING "Restbed library NOT FOUND - the respective targets won't be build")
else()
        message( STATUS "Restbed library : ${RESTBED_LIBRARY}")
endif( NOT RESTBED_LIBRARY )

I have librestbed.so in folder ${RESTBED_ROOT}/build_release.

Then you can link your target like

target_link_libraries( your_target_name ${RESTBED_LIBRARY} )

That is enough from CMake perpective.

Dmitry
  • 1,912
  • 2
  • 18
  • 29