Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to compile with Visual Studio 2019 and vcpkg #94

Closed
Armillus opened this issue Mar 24, 2021 · 10 comments
Closed

Unable to compile with Visual Studio 2019 and vcpkg #94

Armillus opened this issue Mar 24, 2021 · 10 comments
Labels
bug Something isn't working

Comments

@Armillus
Copy link

Hello,

I don't know if this is the appropriate place for this issue since I don't know who is the maintainer of the vpckg quill package, let me know if I should make a similar issue directly on vcpkg.

Tools used

  • Visual Studio: v16.9.2
  • Windows 10: 20h2 (build 19042.746)
  • vcpkg: 2021-01-13-768d8f95c9e752603d2c5901c7a7c7fbdb08af35

Builds have been done on both x86 and x64, Debug and Release modes.

Code snippet

Nothing unusual here, I reduced the code and the dependencies to the minimum and the problem still persists.

#include <quill/Quill.h>

int main()
{
    quill::start();

    quill::Logger* logger = quill::get_logger();

    // Here is the IDE first error (C++ pointer to incomplete class type is not allowed)
    logger->set_log_level(quill::LogLevel::Info);

    LOG_INFO(logger, "A simple test.");

    return 0;
}

What is the problem?

I was looking for a fast and lightweight logger, and quill appeared to me as the perfect library to use. However, I'm working with Visual Studio and there is an annoying issue with vcpkg concerning quill.

When I try to compile, I get a long list of errors, which seem to come from the bundled version of fmt inside of quill.
Here is the output of the build (the actual error list of VS is composed of 32 errors, but they're all coming from the fmt integration):

Build started...
1>------ Build started: Project: QuillTest, Configuration: Debug Win32 ------
1>main.cpp
1>C:\Users\Armillus\Programming\vcpkg\installed\x86-windows\include\quill\Fmt.h(20,12): fatal error C1083: Cannot open include file: 'quill/bundled/fmt/chrono.h': No such file or directory
1>Done building project "QuillTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Of course, I can't compile nor run the program, but the IDE isn't recognizing properly the code after quill::Logger* logger = quill::get_logger();. On next line, it complains during static analysis about the logger object (C++ pointer to incomplete class type is not allowed).

What about CMake?

When it comes to CMake, everything is working well, the vcpkg integrations works nicely and I don't have any error.
For the sake of accuracy and completeness, here is the CMakeLists.txt that I used.

cmake_minimum_required(VERSION 3.1.0)
project(NAlamo)

set(CMAKE_CXX_STANDARD 14)

find_package(quill CONFIG REQUIRED)

add_executable(NAlamo "main.cpp")

target_link_libraries(NAlamo PRIVATE quill::quill)

Eventually, this error seems to come from the vcpkg package itself and maybe you'll have an idea about how to fix it.
I can still compile with CMake, but I don't use it in the project where I plan to use quill and the IDE integration failure is quite disturbing.

Thank you in advance for your help!

@odygrd
Copy link
Owner

odygrd commented Mar 28, 2021

Hey, thanks for reporting.

This error means that quill is trying to import the bundled version of libfmt, which does not exist. For vckpg we depend on lib fmt installed by vcpkg.

You should not get this error.

Quill does https://github.com/odygrd/quill/blob/master/CMakeLists.txt#L127

And in vcpkg it is called as https://github.com/microsoft/vcpkg/blob/8ede7e82b2fe816803c023a201c017cca0d6238a/ports/quill/portfile.cmake#L17

I see that in vcpkg last month they did this:
microsoft/vcpkg#16202

I don't know the reason they did this but i suspect this broke it

@odygrd
Copy link
Owner

odygrd commented Mar 28, 2021

I have tried on windows with vcpkg and I can compile without issues.

.\vcpkg.exe install quill:x86-windows
.\vcpkg.exe install quill:x86-windows

cmake which i ran passing -DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake
`cmake_minimum_required(VERSION 3.17)

project(main VERSION 1.0.0)
add_executable(main main.cpp)

find_package(quill CONFIG REQUIRED)
target_link_libraries(main PRIVATE quill::quill)
`

Screenshot 2021-03-28 at 00 47 54

@RT2Code
Copy link
Contributor

RT2Code commented Mar 28, 2021

I see that in vcpkg last month they did this:
microsoft/vcpkg#16202

I don't know the reason they did this but i suspect this broke it

It's the opposite actually, that's the issue I fixed with this commit. The QUILL_FMT_EXTERNAL macro need to be defined during the library build, or it won't find the bundled fmt library because we don't provide it (we use the vcpkg fmt port instead).

When you install Quill via vcpkg, everything is fine because this macro is defined by the CMake file. But when you try to build a project using Quill, it fails because you're not using the CMake file and the macro isn't defined anymore.

Uncomment this macro in the Quill tweak file, or update to a newest vcpkg version and the problem should be gone. :)

@odygrd
Copy link
Owner

odygrd commented Mar 28, 2021

@RT222 I see thanks for the explanation
@Armillus please can you try to update your vcpkg and try again please as Remy suggests ?

@Armillus
Copy link
Author

Thank you very much @odygrd and @RT222, I've updated vcpkg and reinstalled quill, and everything works fine... Or should I say almost everything?

Indeed, I faced a really weird behaviour in my project. I make use of Direct3D9 and DirectXMath (among others dependencies), and I found something strange. Here is a minimalist example:

Direct3D9.hpp

#pragma once

// Direct3D includes
#include <d3d9.h>
#include <DirectXMath.h>

#ifndef D3D9_IMPORTED

#pragma comment (lib, "d3d9.lib")
#define D3D9_IMPORTED 1

#endif

main.cpp

// Project includes
#include "Direct3D9.hpp"

// Quill includes
#include <quill/Quill.h>

int main()
{
    // We only define a matrix to be sure that there isn't any issue with DirectXMath
    DirectX::XMMATRIX m = DirectX::XMMatrixIdentity();
    
    // Below is the quill standard example to ensure everything works 
    quill::start();

    quill::Logger* logger = quill::get_logger();
    logger->set_log_level(quill::LogLevel::Info);

    LOG_INFO(logger, "A simple test.\n");

    return 0;
}

When I compile this small project, it fails and produces the following output:

1>------ Build started: Project: QuillTest, Configuration: Debug x64 ------
1>main.cpp
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(30,80): warning C4003: not enough arguments for function-like macro invocation 'max'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(30,80): error C2589: '(': illegal token on right side of '::'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(29,17): error C2059: syntax error: ')'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(61,63): warning C4003: not enough arguments for function-like macro invocation 'max'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(87,64): warning C4003: not enough arguments for function-like macro invocation 'max'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(86,39): error C2059: syntax error: 'member initializer'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(86,39): error C2143: syntax error: missing ';' before '{'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(86,39): error C2447: '{': missing function header (old-style formal list?)
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(87,64): error C2589: '(': illegal token on right side of '::'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(87,31): error C2059: syntax error: 'member initializer'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(87,31): error C2143: syntax error: missing ';' before '{'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(87,31): error C2447: '{': missing function header (old-style formal list?)
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(88,1): error C2059: syntax error: '<L_GRAMMAR_end_class>'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(29,17): error C2587: 'logger_details': illegal use of local variable as default parameter
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(29): message : see declaration of 'logger_details'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(29,17): error C2587: 'backtrace_capacity': illegal use of local variable as default parameter
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(30): message : see declaration of 'backtrace_capacity'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(32,1): error C2587: 'this': illegal use of local variable as default parameter
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(29): message : see declaration of 'this'
1>C:\Users\Armillus\Programming\vcpkg\installed\x64-windows\include\quill\detail\events\BacktraceEvent.h(32,1): fatal error C1903: unable to recover from previous error(s); stopping compilation
1>INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\CL.exe'
1>    Please choose the Technical Support command on the Visual C++
1>    Help menu, or open the Technical Support help file for more information
1>Done building project "QuillTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

For some reason, Quill does not compile in this case. The same happens when I try to compile with CMake instead of Visual Studio, with the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.1.0)
project(QuillTest)

set(CMAKE_CXX_STANDARD 14)

find_package(quill CONFIG REQUIRED)

add_executable(QuillTest "main.cpp" "Direct3D9.hpp")

target_link_libraries(QuillTest PRIVATE quill::quill)

Note that I only tried in x64 (Debug and Release) configuration. However, if I include quill/Quill.h before Direct3D9.hpp, everything works and the program produce the expected output:

13:55:20.602243338 [2328] main.cpp:16                  LOG_INFO      root         - A simple test.


C:\Users\Armillus\source\repos\QuillTest\x64\Debug\QuillTest.exe (process 11148) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

So, is there anything that I miss somewhere ? Did I make any mistake in the CMakeLists or in the way I include / import DirectX libraries?

Eventually, I can compile, I just need to include quill/Quill.h first. But I wanted to point out this problem, since I don't think it's normal.

@bl-ue
Copy link
Contributor

bl-ue commented Mar 28, 2021

I wonder is quill is calling a function somewhere but Direct3D9.hpp is #defineing a macro with the name of the function, and that's causing crazy problems. If I'm correct, it looks like the culprit is max, based on the error messages.

uint32_t backtrace_capacity = (std::numeric_limits<uint32_t>::max()))

@odygrd
Copy link
Owner

odygrd commented Mar 28, 2021

@Armillus thanks for reporting. I could reproduce and will fix it in the next release.

For now, can you try to define NOMINMAX before including everything ?
#define NOMINMAX

For me it worked

@odygrd odygrd added the bug Something isn't working label Mar 28, 2021
@odygrd
Copy link
Owner

odygrd commented Mar 28, 2021

This should be fixed in commit 519f59e
I forgot to change the commit message tho to indicate the fix .. :(

@odygrd
Copy link
Owner

odygrd commented Mar 28, 2021

@Armillus after this PR is merged microsoft/vcpkg#16931 you should upgrade to version 1.6.2 that fixes this issue.
Thanks for reporting

@Armillus
Copy link
Author

Thank you @odygrd and @bl-ue, it works very well now :)
Keep up your talented work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants