LINK : fatal error LNK1104 in cmake project when using relative paths for IMPORTED_IMPLIB and IMPORTED_LOCATION

119 views Asked by At
cmake_minimum_required(VERSION 3.25)

project(GarbageCollector C)

set(CMAKE_C_STANDARD 23)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)

add_library(collections SHARED IMPORTED)

set_target_properties(collections PROPERTIES
        IMPORTED_IMPLIB "lib/Release/Collections.lib"
        IMPORTED_LOCATION "bin/Debug/Collections.dll")
add_executable(gc ./main.c)

target_link_libraries(gc collections)

LINK : fatal error LNK1104. says that cant open Collections.lib

when i try to cmake --build build i get LINK : fatal error LNK1104.

1

There are 1 answers

0
starball On

Both IMPORTED_IMPLIB and IMPORTED_LOCATION require full (absolute) paths.

If you want to anchor the paths you have to something, see the following variables and use whichever one suits the needs in your context:

Ex.

set_target_properties(collections PROPERTIES
    IMPORTED_IMPLIB "${PROJECT_SOURCE_DIR}/lib/Release/Collections.lib"
    IMPORTED_LOCATION "${PROJECT_SOURCE_DIR}/bin/Debug/Collections.dll"
)