1

I am new to Cmake, and I am having trouble linking an external library (libtiff). I have installed libtiff and it is in my /usr/local/include. Then I used include_directories() and target_linked_libraries() in my Cmake. However, it still gives me

ld: library not found for -ltiff

main.c:

#include <stdio.h>
#include "tiffio.h"

int main() {
    printf("Hello, World!\n");
    return 0;
}

cmake file:

cmake_minimum_required(VERSION 3.13)

project(test2 C)

set(CMAKE_C_STANDARD 99)

include_directories(/usr/local/include)

add_executable(test2 main.c)

target_link_libraries(test2 tiff)

I would really appreciate if you can help! Thanks in advance!

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
Yafei Mao
  • 11
  • 1
  • 2

1 Answers1

1

Import library instead of link directory.

# Your-external "mylib", add GLOBAL if the imported library is located in directories above the current.
    add_library( mylib SHARED IMPORTED )
    # You can define two import-locations: one for debug and one for release.
    set_target_properties( mylib PROPERTIES IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/res/mylib.so ) 

Link the library like this

TARGET_LINK_LIBRARIES(GLBall mylib)

see this link for import libaray https://cmake.org/cmake/help/v2.8.8/cmake.html#command:add_library

MIH
  • 125
  • 1
  • 14