0

I'm trying to load OpenCV Libraries in CMakeFile.txt but it always ends with this error:

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

I've searched on the Internet but have got no solution.

   cmake_minimum_required(VERSION 3.8)

   set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/KotlinCMakeModule)

   project(untitled1 Kotlin)

   find_package(OpenCV REQUIRED)


   IF (OpenCV_FOUND)
      include_directories(/usr/local/Cellar/opencv/3.4.0_1/include)
      link_libraries(/usr/local/Cellar/opencv/3.4.0_1/lib)
   ENDIF(OpenCV_FOUND)


  konanc_executable(
        NAME HelloWorld
       SOURCES hello.kt
  )

  target_link_libraries(HelloWorld
         /usr/local/Cellar/opencv/3.4.0_1/lib
         )

Someone can help me? I think it's not working because on the use of konanc_executable instead of add_executable but I need to use Kotlin so I cannot use the add_executable command.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • Not an expert in kotlin, but the [first definition](https://github.com/JetBrains/kotlinconf-spinner/blob/master/kotlin-native/samples/fullstack/KotlinCMakeModule/CMakeKotlinInformation.cmake#L162) of function `konanc_executable` I have found, uses `${KONANC_NAME}.kexe` as the target name of the "actual" executable. In you case the target name would be `HelloWorld.kexe`. Not sure whether you may link the executable with a "native" library, but you may try. – Tsyvarev Feb 21 '18 at 19:35
  • No more errors but I'm not quite sure it's ok because it gives me: WARNING: Target "HelloWorld.kexe" requests linking to directory "/usr/local/Cellar/opencv/3.4.0_1/lib". Targets may link only to libraries. CMake is dropping the item. – Andrea Zichittella Feb 21 '18 at 20:41
  • 1
    Yes, the warning is correct: you need to link (`link_libraries`) with **libraries** (`.a`, `.so` or other files), not with *directories*. – Tsyvarev Feb 21 '18 at 21:17

0 Answers0