2

On macOS I managed to build my own small SHARED library based on fmt, while installing it with vcpkg and building the project with cmake.

Now on Windows I have:

CMakeLists.txt

cmake_minimum_required(VERSION 3.19.1)

set(CMAKE_TOOLCHAIN_FILE C:/vcpkg/scripts/buildsystems/vcpkg.cmake)

project(MYLIB)

set (CMAKE_CXX_STANDARD 14)

find_package(fmt REQUIRED)

include_directories(C:/vcpkg/installed/x64-osx/include)

link_libraries(fmt::fmt)

add_library(mylib SHARED mylib.cpp)

mylib.cpp

#include "mylib.h"

#include <fmt/core.h>

float add(float a, float b)
{
    fmt::print("Hello MYLIB, world!\n");
    return (a + b);
}

This generates the .dll but no .lib, why?

KcFnMi
  • 5,516
  • 10
  • 62
  • 136
  • 2
    I suspect [this question](https://stackoverflow.com/questions/33062728/cmake-link-shared-library-on-windows) may be on-topic for what you're trying to do. – WhozCraig Apr 03 '22 at 11:16
  • 3
    You don't get an import library `.lib` if your code does not export any symbols. This msdn article explains how to create a native c++ dll in winapi: [https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=msvc-170](https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=msvc-170) with this said there are options in CMake to avoid the need to export and options to have CMake help generate the export macro listed in the link above this comment. – drescherjm Apr 03 '22 at 13:21

0 Answers0