问题
Problem Summary
I'm trying to integrate Google Crashpad, (successor of Google Breakpad) a crash reporting system, into a software suite that links to all of its external libraries dynamically. My problem is that the default of Crashpad is to build as a static library - I need to build it dynamically.
After cloning Crashpad, GN is used to generate the .ninja files for the build. The build commands are as follows:
$ gn gen out/Default
The above command generates all of the .ninja files.
(Aside) To generate Visual Studio solution files (.sln), the following generation command can be used instead:
$ gn gen out/Default --ide=vs
To compile:
$ ninja -C out/Default
What I've Tried
This StackOverflow Question answers the same question, suggesting that you can simply modify the outputted .ninja files' link flags (/MT changed to /MD). However, grepping over all of the outputted files shows that no such flags exist.
Backtrace Integration Guide has a link to pre-built dynamically (shared) libraries of crashpad here. However, they appear to have built those libraries with Visual Studio 2017, using a newer toolset (v141) than I can use. I need to re-build Crashpad for dynamic linking, and using Visual Studio 2015 (v140).
回答1:
The output of:
$ gn gen out/Default
will create a file called toolchain.ninja, which contains lines that tell your specified compiler how to compile your projects. In the case of Crashpad, they look like this:
rule cc
command = ninja -t msvc -e environment.amd64 -- cl.exe /nologo /showIncludes ${defines} ${include_dirs} ${cflags} ${cflags_c} /c ${in} /Fo${out} /Fd"${target_out_dir}/${label_name}_c.pdb"
description = CC ${out}
deps = msvc
rule cxx
command = ninja -t msvc -e environment.amd64 -- cl.exe /nologo /showIncludes ${defines} ${include_dirs} ${cflags} ${cflags_c} /c ${in} /Fo${out} /Fd"${target_out_dir}/${label_name}_cc.pdb"
description = CXX ${out}
deps = msvc
For the Visual Studio MSVC 2015 / 2017 compiler, you can add the /MD
flag to each command
line above. This will compile the library dynamically. For example:
command = ninja -t msvc -e environment.amd64 -- cl.exe /MD /nologo /showIncludes ${defines} ${include_dirs} ${cflags} ${cflags_c} /c ${in} /Fo${out} /Fd"${target_out_dir}/${label_name}_cc.pdb"
来源:https://stackoverflow.com/questions/57486462/how-do-i-build-google-crashpad-into-shared-dynamic-libraries