Vcpkg: fmt:x64-windows built and installed but still getting link errors

Created on 23 Nov 2016  路  14Comments  路  Source: microsoft/vcpkg

.\vcpkg install fmt:x64-windows
Package fmt:x64-windows is installed

.\vcpkg integrate install
Applied user-wide integration for this vcpkg root.

I am not sure if this is the reason. My platform is Windows 7 and in vcpkg.targets file I don't see SDK 8.1 has a target. I only see SDK 10

port-bug

All 14 comments

Hi,
as referenced above, there was a fix in the latest master branch that might be affecting you.
Can you try rebuilding fmt?:
vcpkg remove --purge fmt:x64-windows
vcpkg install fmt:x64-windows

I just did and am still getting link errors.

e.g. error LNK2019: unresolved external symbol "public: virtual __cdecl fmt::FormatError::~FormatError(void)" (??1FormatError@fmt@@UEAA@XZ) referenced in function "public: virtual void * __cdecl fmt::

What do you have to say about vcpkg.targets though. Is it OK that there is no 8.1 target. None of my programs will be on Windows 10 any time soon. Support for Windows 7 is crucial

Don't worry, we definitely understand that Windows 7 support is absolutely required :). The references to 10.0 in vcpkg.targets are entirely for UWP and shouldn't affect your scenario.

It looks like prior to #333, fmt was not exporting ~FormatError

PS D:\src\vcpkg\installed\x86-windows\lib> dumpbin /exports .\fmt.lib | select-string FormatError
<no output>

After #333, it is:

PS D:\src\vcpkg\installed\x64-windows\lib> dumpbin /exports .\fmt.lib | select-string FormatError

                  ??0FormatError@fmt@@QEAA@AEBV01@@Z (public: __cdecl fmt::FormatError::FormatError(class fmt::FormatError const &))
                  ??1FormatError@fmt@@UEAA@XZ (public: virtual __cdecl fmt::FormatError::~FormatError(void))
                  ??_R0?AVFormatError@fmt@@@8 (class fmt::FormatError `RTTI Type Descriptor')

To check if this change was correctly applied, could you run vcpkg list fmt?

PS D:\src\vcpkg\installed\x86-windows\lib> vcpkg list fmt
fmt:x64-windows             3.0.1-1          Formatting library for C++. It can be used as a s...
fmt:x86-windows             3.0.0            Formatting library for C++. It can be used as a s...

If you have 3.0.0 installed, that would explain the issue (you'll need to do git pull before the above steps that Alex posted).

Otherwise, it looks like there's an issue in the MSBuild integration. However, this seems really unlikely since the include directory is correctly being added.

I had similar problem as you. Cmake below version 3.4 does not support WINDOWS_EXPORT_ALL_SYMBOLS option. Try to install the latest release.

Edit oooops, looks like some symbols are still not exported

1>main.obj : error LNK2001: unresolved external symbol "public: static unsigned int const * const fmt::internal::BasicData<void>::POWERS_OF_10_32" (?POWERS_OF_10_32@?$BasicData@X@internal@fmt@@2QBIB)
1>main.obj : error LNK2001: unresolved external symbol "public: static unsigned __int64 const * const fmt::internal::BasicData<void>::POWERS_OF_10_64" (?POWERS_OF_10_64@?$BasicData@X@internal@fmt@@2QB_KB)
1>main.obj : error LNK2001: unresolved external symbol "public: static char const * const fmt::internal::BasicData<void>::DIGITS" (?DIGITS@?$BasicData@X@internal@fmt@@2QBDB)

I have the latest fmt see:
vcpkg list fmt
D:\vcpkg>vcpkg list fmt
fmt:x64-windows 3.0.1-1
fmt:x64-windows-static 3.0.1-1

Ok I got it working now. It turned out there was a problem with symbols not being imported.
@bangusi you probably need to perform these steps:
1) Install latest CMake.
2) Rebuild fmt as mentioned before.
3) Add #define FMT_SHARED before including fmt headers.

I do have the latest cmake already.
D:\vcpkg>cmake --version
cmake version 3.7.0

Sorry, this issue got a bit lost. To pick up where we left off:

Could you try running the dumpbin expression I posted above on the produced library?

  1. Open a 2015 developer prompt
  2. powershell
  3. cd C:\path\to\vcpkg
  4. dumpbin /exports installed\x64-windows\lib\fmt.lib | select-string FormatError

If this comes up with results, then we've conclusively narrowed it down to an issue with the buildsystem integration.

This is the output:

??0FormatError@fmt@@QEAA@AEBV01@@Z (public: __cdecl fmt::FormatError::FormatError(class fmt::FormatError const &))
??1FormatError@fmt@@UEAA@XZ (public: virtual __cdecl fmt::FormatError::~FormatError(void))
??_R0?AVFormatError@fmt@@@8 (class fmt::FormatError `RTTI Type Descriptor')

Ok, so the library itself is definitely fine (as is the installation).

Could you post a minimal source file that doesn't link correctly? If you'd prefer to zip up the whole project, you can send the whole thing to [email protected].

I have never used fmt for anything before. It just happened that is the first library I decided to test my first installation of vcpkg with.
This is the piece of code.

#include"fmt\format.h"
void f0()
{
    fmt::format("{0}, {1}, {2}", 'a', 'b', 'c');
}
int main()
{
    f0();
    return 0;
}

Reproduced - as I said before it's a problem with importing symbols. With this change:

#define FMT_SHARED
#include"fmt/format.h"

everything works fine.
It's not FormatError that is problematic, but some static data tables. As CMake's documentation states for WINDOWS_EXPORT_ALL_SYMBOLS option:

For global data symbols, __declspec(dllimport) must still be used when compiling against the code in the .dll.

We could probably patch fmt headers in dynamic builds to avoid this problem in the future.

I reproduced this in my own project. Seems things are super temperamental. there is a FMT_EXPORT define you can add to get fmt to export symbols, but I don't think they define it on widnows. Maybe we should try and fix this upstream.

I could only repro this when building fmt with MSVC 2017 moving to 2015 fixed it. Not ideal, maybe they are checking MSVC versions in some header file

Thanks to @codicodi for the root cause!

I've modified the fmt package in 3.0.1-4 to edit the installed headers and always act as though FMT_SHARED is defined, which fixes my local repro.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jasjuang picture jasjuang  路  3Comments

angelmixu picture angelmixu  路  3Comments

pakdel picture pakdel  路  3Comments

grandprixgp picture grandprixgp  路  3Comments

ThinkalVB picture ThinkalVB  路  3Comments