# use cmake to generate pdb

**URL:** <https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583>\
**Category:** Code\
**Tags:** gen:vs\
**Created:** [January 20, 2021, 9:00am UTC](https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583 "2021-01-20T09:00:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![NanaSeino233](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nanaseino233/32/1118_2.png) [@NanaSeino233](https://discourse.cmake.org/u/NanaSeino233)\
**Post date:** [January 20, 2021, 9:00am UTC](https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583/1 "2021-01-20T09:00:48Z")

</div>

我正在使用cmake编译leptonica1.78，在生成sln方案后，我使用了vs2017来生成.dll动态链接库，  
当用实用工具cppan-d-b-d来生成pvt.cppan.demo.jpeg-9.2.0.dll等依赖时，并没有生成pdb文件，由于配置属性是utility，在vs2017中无法更改设置。  
我想请教一下cmake中有没有指令可以配置utility生成pdb文件。  
目前尝试过的指令是 “set(CMAKE\_CXX\_FLAGS\_RELEASE “${CMAKE\_CXX\_FLAGS\_RELEASE} /Zi”)  
set(CMAKE\_SHARED\_LINKER\_FLAGS\_RELEASE “${CMAKE\_SHARED\_LINKER\_FLAGS\_RELEASE} /DEBUG /OPT:REF /OPT:ICF”)”  
但是我不知道将这个指令放在什么位置。  
谢谢你。

---

<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:** [January 20, 2021, 3:08pm UTC](https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583/2 "2021-01-20T15:08:26Z")

</div>

Thanks. Note that this is largely an English-speaking forum and other languages are a best-effort and depends on who is available.

In the interest of at least getting something, here is Google Translate’s take:

> [@](#):
>
> I am using cmake to compile leptonica 1.78. After generating the sln scheme, I used vs2017 to generate the .dll dynamic link library.  
> When using the utility cppan-d-b-d to generate dependencies such as pvt.cppan.demo.jpeg-9.2.0.dll, the pdb file is not generated. Since the configuration attribute is utility, the settings cannot be changed in vs2017.  
> I would like to ask if there are instructions in cmake to configure utility to generate pdb files.  
> The command I have tried so far is “set(CMAKE\_CXX\_FLAGS\_RELEASE “${CMAKE\_CXX\_FLAGS\_RELEASE} /Zi”)  
> set(CMAKE\_SHARED\_LINKER\_FLAGS\_RELEASE “${CMAKE\_SHARED\_LINKER\_FLAGS\_RELEASE} /DEBUG /OPT:REF /OPT:ICF”)”  
> But I don’t know where to put this instruction.  
> thank you.

---

<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:** [January 20, 2021, 3:09pm UTC](https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583/3 "2021-01-20T15:09:38Z")

</div>

I think putting those `set` commands in the top-level scope should be sufficient. Is there a reason that using the `RelWithDebInfo` build type is not suitable?

---

<div class="post-metadata">

**Author:** ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)\
**Post date:** [January 20, 2021, 7:52pm UTC](https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583/4 "2021-01-20T19:52:51Z")

</div>

I always make sure to build a PDB because than otherwise visual studio’s profiling capabilities are limited. Now that stripped PDBs exist I don’t really see a reason to not create a PDB by default even for release builds.

So I have the following code before I define any targets.

```cmake
    # Debug Information Format
    #
    # This is only really necessary for the Release configuration
    #
    # Explanation: Without this flag you won't get good profiling information in Release builds
    #
    # Use of /Zi doesn't affect optimizations
    #
    # Because we have a stripped PDB that we release to the public we should always specify this option
    # for our internal PDBs
    add_compile_option("/Zi")

```

---

<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:** [January 20, 2021, 8:06pm UTC](https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583/5 "2021-01-20T20:06:02Z")

</div>

That sounds like a feature request to CMake to change its default flags to me.

---

<div class="post-metadata">

**Author:** ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)\
**Post date:** [January 20, 2021, 8:08pm UTC](https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583/6 "2021-01-20T20:08:41Z")

</div>

I don’t think the intent of this post is asking for cmake to change anything. Just how to always generate the PDB. I just gave an explanation of my workflow, to try and guess a similar intent.

---

<div class="post-metadata">

**Author:** ![NanaSeino233](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nanaseino233/32/1118_2.png) [@NanaSeino233](https://discourse.cmake.org/u/NanaSeino233)\
**Post date:** [January 21, 2021, 1:18am UTC](https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583/7 "2021-01-21T01:18:02Z")

</div>

Usually after the sln file is generated, we use vs to generate the dll and lib files. What I mean is that the configuration type of the project I compiled is a utility, and it is impossible to set and generate a pdb file in VS. Therefore, I would like to ask whether my goal can be achieved through cmake commands.  
So far, I have searched the Internet and tried the following commands:  
set(CMAKE\_CXX\_FLAGS\_RELEASE “${CMAKE\_CXX\_FLAGS\_RELEASE} /Zi”)  
set(CMAKE\_SHARED\_LINKER\_FLAGS\_RELEASE “${CMAKE\_SHARED\_LINKER\_FLAGS\_RELEASE} /DEBUG /OPT:REF /OPT:ICF”)  
But I don’t know where this command should be placed in which cmakelists, and whether it will really work.Thank you for your help.

---

<div class="post-metadata">

**Author:** ![NanaSeino233](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nanaseino233/32/1118_2.png) [@NanaSeino233](https://discourse.cmake.org/u/NanaSeino233)\
**Post date:** [January 21, 2021, 1:24am UTC](https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583/8 "2021-01-21T01:24:02Z")

</div>

Sorry for not using English, I will correct it

---

<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:** [January 21, 2021, 3:24pm UTC](https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583/9 "2021-01-21T15:24:22Z")

</div>

Placing it in the top-level `CMakeLists.txt` should be sufficient.
