# Problems linking

**URL:** <https://discourse.cmake.org/t/problems-linking/12885>\
**Category:** Code\
**Created:** [November 2, 2024, 10:23am UTC](https://discourse.cmake.org/t/problems-linking/12885 "2024-11-02T10:23:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![perdrix](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Post date:** [November 2, 2024, 10:23am UTC](https://discourse.cmake.org/t/problems-linking/12885/1 "2024-11-02T10:23:26Z")

</div>

My project uses some prebuilt lib files which are stored in

```auto
C:\Users\amonra\Documents\GitHub\DSS\libs\Win64\DebugLibs
  and
C:\Users\amonra\Documents\GitHub\DSS\libs\Win64\ReleaseLibs

```

so for example exiv2d.lib is in the DebugLibs folder above.

So I put this in my CMakeLists.txt file:

```auto
link_directories(
	../libraw/$<CONFIG>
	../libtiff/$<CONFIG>
	../ZClass/$<CONFIG>	
	"$<$<CONFIG:Debug>:C:/Users/amonra/Documents/GitHub/DSS/libs/Win64/DebugLibs>"
	"$<$<CONFIG:Release>:C:/Users/amonra/Documents/GitHub/DSS/libs/Win64/ReleaseLibs>"
	"$<$<CONFIG:Debug>:C:/Program Files (x86)/Visual Leak Detector/lib/Win64>"
	)
	
    ... stuff omitted

set(ADDITIONAL_LIBRARY_DEPENDENCIES
    "$<$<CONFIG:Debug>:"
        "exiv2d;"
        "libexpatd;"
        "zlibstaticd"
    ">"
    "$<$<CONFIG:Release>:"
        "exiv2;"
        "libexpat;"
        "zlibstatic"
    ">"
    "user32;"
    "psapi;"
    "$(Qt_LIBS_);"
    "htmlhelp;"
    "cfitsio"
)
target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES}")

```

but when I build the project created from that I get:

```auto
7>LINK : fatal error LNK1181: cannot open input file 'exiv2d.lib'

```

Clearly I did that wrong, but what did I mess up?

Thanks, David

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [November 2, 2024, 11:21am UTC](https://discourse.cmake.org/t/problems-linking/12885/2 "2024-11-02T11:21:39Z")

</div>

Each generator expression **must be** expressed as one string, not multiple strings. So the definition of variable `ADDITIONAL_LIBRARY_DEPENDENCIES` seems problematic. Moreover, your usage of semicolon is not judicious. I suggest the following:

```cmake
set(DEBUG_DEPENDENCIES exiv2d libexpatd zlibstaticd)
set(RELEASE_DEPENDENCIES exiv2 libexpat zlibstatic)

set(ADDITIONAL_LIBRARY_DEPENDENCIES
    "$<$<CONFIG:Debug>:${DEBUG_DEPENDENCIES}>"
    "$<$<CONFIG:Release>:${RELEASE_DEPENDENCIES}>"
    "user32"
    "psapi"
    "$(Qt_LIBS_)"
    "htmlhelp"
    "cfitsio"
)

target_link_libraries(${PROJECT_NAME} PRIVATE ${ADDITIONAL_LIBRARY_DEPENDENCIES})

```

The `set()` command naturally build a list when multiple items are specified (not need to specify semicolon). And evaluate the variable `ADDITIONAL_LIBRARY_DEPENDENCIES`, as part of `target_link_libraries()` command, without quotes to get the list.

To finish, what is the goal of `$(Qt_LIBS_)`? Clearly not a `CMake` variable evaluation.

---

<div class="post-metadata">

**Author:** ![perdrix](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Post date:** [November 2, 2024, 1:40pm UTC](https://discourse.cmake.org/t/problems-linking/12885/3 "2024-11-02T13:40:19Z")

</div>

I made the changes you proposed, so I now have:

```auto
link_directories(
	../libraw/$<CONFIG>
	../libtiff/$<CONFIG>
	../ZClass/$<CONFIG>	
	"$<$<CONFIG:Debug>:C:/Users/amonra/Documents/GitHub/DSS/libs/Win64/DebugLibs>"
	"$<$<CONFIG:Release>:C:/Users/amonra/Documents/GitHub/DSS/libs/Win64/ReleaseLibs>"
	"$<$<CONFIG:Debug>:C:/Program Files (x86)/Visual Leak Detector/lib/Win64>"
	)

################################################################################
# Dependencies
################################################################################
# Link with other targets.
target_link_libraries(DeepSkyStacker PRIVATE
    Qt6::Widgets
	Qt6::Network
	DeepSkyStackerKernel
    libraw
    libtiff
    ZClass
)

set(DEBUG_DEPENDENCIES exiv2d libexpatd zlibstaticd)
set(RELEASE_DEPENDENCIES exiv2 libexpat zlibstatic)

set(ADDITIONAL_LIBRARY_DEPENDENCIES
    "$<$<CONFIG:Debug>:${DEBUG_DEPENDENCIES}>"
    "$<$<CONFIG:Release>:${RELEASE_DEPENDENCIES}>"
    "user32"
    "psapi"
    "htmlhelp"
    "cfitsio"
)

```

It still fails with:

```auto
7>LINK : fatal error LNK1181: cannot open input file 'exiv2d.lib'

```

The Qt\_LIBS\_ thing was a dropping from a conversion tool that didn’t do as good a job as I’d hoped.

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [November 2, 2024, 1:45pm UTC](https://discourse.cmake.org/t/problems-linking/12885/4 "2024-11-02T13:45:34Z")

</div>

Are you sure that file `exiv2d.lib` exists in one of your directories?

---

<div class="post-metadata">

**Author:** ![perdrix](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Post date:** [November 2, 2024, 2:44pm UTC](https://discourse.cmake.org/t/problems-linking/12885/5 "2024-11-02T14:44:41Z")

</div>

Yes I am. I actually found the problem I had a duplicate target\_link\_libraries with some libraries missing from the list in the relevant file. Once i deleted that, things worked a lot better.

David
