0

I've been dealing with this problem day and night for a week. I've read every page on Google, Stackoverflow and Github.

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(EDKPOC)

add_library(BCXConfiguration STATIC IMPORTED)

set_target_properties(BCXConfiguration PROPERTIES
        IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/main/liBCXConfiguration.a"
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/main/include")

link_directories(${CMAKE_CURRENT_LIST_DIR})

target_link_libraries(EDKPOC BCXConfiguration)

It gives this error when I run CMake:

CMake Error at CMakeLists.txt:20 (target_link_libraries):
  Cannot specify link libraries for target "EDKPOC" which is not built
  by this project.
Kevin
  • 16,549
  • 8
  • 60
  • 74
Mesut A.
  • 1,618
  • 1
  • 10
  • 11
  • What is this file meant to do? `add_library` builds a library, but then you try to link that library to something else? – scatter Sep 13 '19 at 12:36
  • While the [duplicate question](https://stackoverflow.com/questions/25909943/getting-a-cmake-error-cannot-specify-link-libraries-for-target-which-is-not-bui) *initially* did't contain the answer to your problem, I have added that answer. Having different problems with the **same error message** under the single title (in the **single question**) would help future visitors to find resolution for their problem more quickly. – Tsyvarev Sep 13 '19 at 12:48

1 Answers1

1

The target_link_libraries() command is used to link a given target with its dependent targets. You specify EDKPOC as the first argument to the command; this is your project name, but it is not a valid target. The only target you've specified in your example CMake file is BCXConfiguration. If you want to link this static library to another target (e.g. MyOtherLibraryTarget) elsewhere in your CMake project, your syntax could look something like this:

target_link_libraries(MyOtherLibraryTarget PUBLIC BCXConfiguration)

If you don't have other targets in your CMake hierarchy, then this command is unnecessary and can be left out.

Kevin
  • 16,549
  • 8
  • 60
  • 74
  • thanks but this brought me another error. when I use this linked BCXConfiguration.a file. I've referenced BCXConfiguration.h file and use class in this file and BEDK::BCXConfiguration *bcx = new BEDK::BCXConfiguration(); and give undefined reference error – Mesut A. Sep 13 '19 at 14:05
  • 1
    @MesutA.: Please, update the question post with description of the new problem. This description should include your updated `CMakeLists.txt`. It is difficult to catch the error in the file we don't see. – Tsyvarev Sep 13 '19 at 14:38