# How to link library with suffix d for debug?

**URL:** https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355
**Category:** Usage
**Created:** [October 28, 2021, 12:12pm UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355 "2021-10-28T12:12:15Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [October 28, 2021, 12:12pm UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/1 "2021-10-28T12:12:15Z")

</div>

I want to use a third package (VTK) in my project, and the folder is:

```auto
Thirdparty
    VTK
        bin
            Debug
                vtkCommonCore-9.0d.dll
                ...
            Release
                vtkCommonCore-9.0.dll
                ...
        include
                xxx
                ...
        lib
            Debug
                vtkCommonCore-9.0d.lib
                ...
            Release
                vtkCommonCore-9.0.dll
                ...

```

In my CMakeLists.txt:

```auto
set(VTI_DIR "xxx/Thirdparty/VTK")
include_directories(
    ${VTK_DIR}/include
)
target_link_libraries(Pro
    vtkCommonCore-9.0
    ....
)

```

If I use `target_link_libraries(Pro vtkCommonCore-9.0d ....)` , the code would be ok for debug but wrong for release.  
If I use `target_link_libraries(Pro vtkCommonCore-9.0 ....)` , the code would be ok for release but wrong for debug.

One solution is:

```auto
target_link_libraries(Pro
    debug vtkCommonCore-9.0d
    optimized vtkCommonCore-9.0
    ....
)

```

But, it seem to be inconvenient.

Is there any method which is more convenient?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 28, 2021, 4:07pm UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/2 "2021-10-28T16:07:53Z")

</div>

> [@zhang-qiang-github](#):
>
> Is there any method which is more convenient?

Yes. Use `find_package(VTK)` and link to `VTK::CommonCore` instead.

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [October 29, 2021, 1:28am UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/3 "2021-10-29T01:28:38Z")

</div>

If I want to use `fidn_package(VTK)`, I need to compile `vtk` in my computer. But, I don’t want to build vtk in my computer, and I just want to use `vtk` by bin/lib/include.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 29, 2021, 12:16pm UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/4 "2021-10-29T12:16:22Z")

</div>

> [@zhang-qiang-github](#):
>
> But, I don’t want to build vtk in my computer, and I just want to use `vtk` by bin/lib/include.

How are you going to use it if you don’t compile it? Where does `libvtkCommonCore-9.0.lib` come from if you haven’t built it?

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [October 30, 2021, 1:46pm UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/5 "2021-10-30T13:46:08Z")

</div>

I can build vtk in one compute, and install vtk. Thus, I can obtain the dll/lib/include files.

Then, I copy thus files to another computer. In this new computer, the vtk is not built, and the `find_package` will fail.

I want to use vtk by only dll/lib, rather that to build it.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [October 30, 2021, 5:27pm UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/6 "2021-10-30T17:27:35Z")

</div>

> [@zhang-qiang-github](#):
>
> I can obtain the dll/lib/include files.

Why do you not pack the hole installation packages of vtk?

```bash
/usr/local/lib/cmake/vtk-9.0/
├── FindEXPAT.cmake
├── FindEigen3.cmake
├── FindFFMPEG.cmake
├── FindFontConfig.cmake
├── FindFreetype.cmake
├── FindGL2PS.cmake
├── FindGLEW.cmake
├── FindJOGL.cmake
├── FindJsonCpp.cmake
├── FindLZ4.cmake
├── FindLZMA.cmake
├── FindLibHaru.cmake
├── FindLibPROJ.cmake
├── FindLibXml2.cmake
├── FindMySQL.cmake
├── FindNetCDF.cmake
├── FindODBC.cmake
├── FindOGG.cmake
├── FindOSMesa.cmake
├── FindOpenMP.cmake
├── FindOpenSlide.cmake
├── FindOpenVR.cmake
├── FindPEGTL.cmake
├── FindTBB.cmake
├── FindTHEORA.cmake
├── Finddouble-conversion.cmake
├── Findmpi4py.cmake
├── Findutf8cpp.cmake
├── VTK-targets-release.cmake
├── VTK-targets.cmake
├── VTK-vtk-module-find-packages.cmake
├── VTK-vtk-module-properties.cmake
├── VTKPython-targets-release.cmake
├── VTKPython-targets.cmake
├── patches
│ ├── 3.13
│ │ └── FindZLIB.cmake
│ ├── 3.16
│ │ ├── FindMPI
│ │ │ ├── fortranparam_mpi.f90.in
│ │ │ ├── libver_mpi.c
│ │ │ ├── libver_mpi.f90.in
│ │ │ ├── mpiver.f90.in
│ │ │ ├── test_mpi.c
│ │ │ └── test_mpi.f90.in
│ │ ├── FindMPI.cmake
│ │ └── FindPostgreSQL.cmake
│ ├── 3.18
│ │ ├── FindPython
│ │ │ └── Support.cmake
│ │ ├── FindPython2.cmake
│ │ └── FindPython3.cmake
│ └── 99
│ ├── FindGDAL.cmake
│ ├── FindHDF5.cmake
│ ├── FindJPEG.cmake
│ ├── FindLibArchive.cmake
│ ├── FindOpenGL.cmake
│ ├── FindSQLite3.cmake
│ └── FindX11.cmake
├── vtk-config-version.cmake
├── vtk-config.cmake
├── vtk-prefix.cmake
├── vtk-use-file-compat.cmake
├── vtk-use-file-deprecated.cmake
├── vtk-use-file-error.cmake
├── vtkCMakeBackports.cmake
├── vtkDetectLibraryType.cmake
├── vtkEncodeString.cmake
├── vtkHashSource.cmake
├── vtkModule.cmake
├── vtkModuleGraphviz.cmake
├── vtkModuleJson.cmake
├── vtkModuleTesting.cmake
├── vtkModuleWrapJava.cmake
├── vtkModuleWrapPython.cmake
├── vtkObjectFactory.cmake
├── vtkObjectFactory.cxx.in
├── vtkObjectFactory.h.in
├── vtkTestingDriver.cmake
├── vtkTestingRenderingDriver.cmake
├── vtkTopologicalSort.cmake
└── vtkmodules-vtk-python-module-properties.cmake

7 directories, 76 files
Claus-iMac:~ clausklein$ 

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 31, 2021, 12:43am UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/7 "2021-10-31T00:43:29Z")

</div>

> [@zhang-qiang-github](#):
>
> I want to use vtk by only dll/lib, rather that to build it.

As stated above, you should copy the _whole_ install tree. That will come with what you need to `find_package(VTK)`. This includes the [`vtk_module_autoinit` command](https://vtk.org/doc/nightly/html/group__module.html#gaa19497c3d949b3a93eaa13ed6df5d416) you’ll need to use if you use any object factories (commonly, rendering or MPI support).

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [November 1, 2021, 2:47am UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/8 "2021-11-01T02:47:58Z")

</div>

Yes, I have copied the whole install tree. Now, the folder is:

```auto
Thirdparty
    VTK
        bin
            Debug
                vtkCommonCore-9.0d.dll
                ...
            Release
                vtkCommonCore-9.0.dll
                ...
        include
                xxx
                ...
        lib
            Debug
                cmake
                    vtk-9.0
                        patches
                        Finddouble-comversion.cmake
                        ....
                        vtk-config.cmake
                        ...
                        VTK-targets-debug.cmake
                        ...
                vtkCommonCore-9.0d.lib
                ...
            Release
                cmake
                    vtk-9.0
                        patches
                        Finddouble-comversion.cmake
                        ....
                        vtk-config.cmake
                        ...
                        VTK-targets-release.cmake
                        ...
                vtkCommonCore-9.0.dll
                ...

```

But, if I use `find_package(VTK)` as:

```auto
set(VTK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Thirdparty/VTK")
find_package(VTK)

```

The cmake will report :

```auto
By not providing "FIndVTK.cmake" in CMAKE_MODULE_PATH this project has asked CMAke to find a package configuration file provided by "VTK", but CMAke did not find one.

Could not find a package configuration file provided by "VTK" with any of the following names:

VTKConfig.cmake
vtk-config.cmake

Add the installation prefix of "VTK" to CMAKE_PREFIX_PATH or set "VTK_DIR" to a directory containing one of the above files. If "VTK" provided a separate development package or SDK, be sure it has been installed. 

```

If my following cmake file is wrong?

```auto
set(VTK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Thirdparty/VTK")
find_package(VTK)

```

How can I implement my cmake file to make `find_package` work?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 1, 2021, 11:03am UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/9 "2021-11-01T11:03:15Z")

</div>

You can either set `CMAKE_PREFIX_PATH` to the install root of VTK or `VTK_DIR` to the directory that contains `vtk-config.cmake`.

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [November 1, 2021, 12:57pm UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/10 "2021-11-01T12:57:14Z")

</div>

There are two paths contains vtk-config.cmake.

1. Thirdparty/VTK/lib/Debug/cmake/vtk-9.0
2. Thirdparty/VTK/lib/Release/cmake/vtk-9.0

Whick path should be `VTK_DIR`?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 1, 2021, 1:26pm UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/11 "2021-11-01T13:26:19Z")

</div>

How did you get such a setup? The CMake files should never be under a config-specific location unless you specified that manually. If you want a single install prefix with both, you’ll need a single CMake package directory which knows about both.

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [November 1, 2021, 2:05pm UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/12 "2021-11-01T14:05:24Z")

</div>

Yes, I manually copy the dll/lib/include files to a config-specific location. The reason is that I want to include Debug/Release/RelWithDebInfo files.

If I do not copy dll/lib/include files to a config-specific location manually, I can distinguish the debug/release by suffix. But, how can I distinguish lib of release and RelWithDebInfo?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 1, 2021, 2:55pm UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/13 "2021-11-01T14:55:44Z")

</div>

Right now, VTK doesn’t have a different suffix for release and relwithdebinfo built-in. You can pass `-DCMAKE_RELWITHDEBINFO_POSTFIX=rd` to the configure to make a different suffixes for that configuration. Then you should be able to have then entire setup in a unified config-less install tree.

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [November 2, 2021, 7:30am UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/14 "2021-11-02T07:30:51Z")

</div>

My folder is:

```auto
Thirdparty
    x64
        VTK
            bin
            include
            lib
                cmake
                    vtk-9.0
                        vtk-config.cmake
                        ...

```

And My Cmakelists.txt is:

```auto
set(VTK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Thirdparty/$(PlatformName)/VTK/lib/cmake/vtk-9.0")
find_package(VTK REQUIRED)

```

But, it still reported:

```auto
By not providing "FIndVTK.cmake" in CMAKE_MODULE_PATH this project has asked CMAke to find a package configuration file provided by "VTK", but CMAke did not find one.

Could not find a package configuration file provided by "VTK" with any of the following names:

VTKConfig.cmake
vtk-config.cmake

Add the installation prefix of "VTK" to CMAKE_PREFIX_PATH or set "VTK_DIR" to a directory containing one of the above files. If "VTK" provided a separate development package or SDK, be sure it has been installed. 

```

Then, I print the `VTK_DIR`, it shows:

```auto
Project/Thirdparty/$(PlatformName)/VTK/lib/cmake/vtk-9.0

```

Is there any wrong with my `VTK_DIR` by: `set(VTK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Thirdparty/$(PlatformName)/VTK/lib/cmake/vtk-9.0")`?

But, the following is OK:

```auto
set(VTK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Thirdparty/x64/VTK/lib/cmake/vtk-9.0")

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 2, 2021, 11:31am UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/15 "2021-11-02T11:31:49Z")

</div>

> [@zhang-qiang-github](#):
>
> `$(PlatformName)/`

CMake will take this literally, so it will never see `x64`. You’ll need to compute this based on whatever information you have and set a CMake variable appropriately.

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [November 2, 2021, 12:05pm UTC](https://discourse.cmake.org/t/how-to-link-library-with-suffix-d-for-debug/4355/16 "2021-11-02T12:05:22Z")

</div>

thank you for your suggestions~~~
