microsoft / microsoft/vcpkg

[yaml-cpp] warnings when using dynamic library

Open
#4,205 5 comments 1 reaction 1 assignee View on GitHub

@Cheney-W is already working on this.

Since Nov 26, 2019.

depends:upstream-changes
Dominant language
CMake
Stars
27.5k
Forks
7.7k
Avg merge
2d 19h
Merged PRs (30d)
321

Description

When using yaml-cpp built as a dynamic library under visual studio there are warning issued C4251 (needs to have dll interface) and C4275 (non-dll interface used as base for dll-interface). This seems to stem from an action done in the portfile

When building yaml-cpp the portfile patches the file dll.h lines 58-64

file(READ ${CURRENT_PACKAGES_DIR}/include/yaml-cpp/dll.h DLL_H)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
string(REPLACE "#ifdef YAML_CPP_DLL" "#if 1" DLL_H "${DLL_H}")
else()
string(REPLACE "#ifdef YAML_CPP_DLL" "#if 0" DLL_H "${DLL_H}")
endif()
file(WRITE ${CURRENT_PACKAGES_DIR}/include/yaml-cpp/dll.h "${DLL_H}")

This probably doesn't matter on static builds but for dynamic builds this cause the dll.h file to define

#define YAML_CPP_API __declspec(dllexport)

unconditionally, which in turn causes visual studio to issue a warning when using the yaml-cpp file. This block was introduced last year. I am assuming to fix another issue but there isn't really any explanation in the log, i'd just remove the block from the portfile, but it's hard to know what might get broken. Additionally it doesn't look like `YAML_CPP_DLL` gets defined in the portfile on dynamic builds. That should probably be passed to `vcpkg_configure_cmake`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.