0

I am trying to create an executable that links to a static library (on Windows), called mkl.lib in the CMakeLists below.

I had a look at this question and tried the suggestions in this one but for me they didn't work.

I have tried two different approaches to get the *.exe to link against the *.lib I have but every time I run it, I get the error message requiring the mkl.dll file (which I don't have).

My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.15)

project(MKLLink)

add_executable(MKL main.cpp)
find_library(MKLLIB NAMES mkl.lib HINTS "${CMAKE_CURRENT_SOURCE_DIR}/external/lib/")
target_link_libraries(MKL PUBLIC ${MKLLIB})
target_include_directories(MKL PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/external/include")

and my main.cpp looks like:

#include "mkl/mkl_service.h"
#include <iostream>

int main( int argc, char** argv)
{
  // Correct version is
  MKLVersion pVersion;
  mkl_get_version(&pVersion);
  std::cout << "Major:  " << pVersion.MajorVersion << std::endl;
  std::cout << "Minor:  "  << pVersion.MinorVersion << std::endl; 
  std::cout << "Update: " << pVersion.UpdateVersion << std::endl;

  return 0;
}

Using CMake I can create the project files for VSStudio and open the solution there. The Properties look correct and he solution compiles fine and does not complain about linking. When I run the executable, I see the error requiring mkl.dll.

Independently, I have tried starting from scratch and created a VS Project but I get exactly the same issue. Compilation and Linkage are good but running crashes asking for *.dll. Generally, it seems to me that I should just be able to link against a *.lib file but maybe I am missing some flags.

Thank you

pol
  • 53
  • 4
  • The explanation [here](https://stackoverflow.com/questions/11051516/program-statically-linked-to-a-library-but-still-needs-dll-to-run) has very helpful and put me on the right path I think! – pol Sep 21 '21 at 12:28
  • If it requires a dll the .lib is not a static library its an import library. This question may be helpful in determining what type of library you have: [https://stackoverflow.com/questions/488809/tools-for-inspecting-lib-files](https://stackoverflow.com/questions/488809/tools-for-inspecting-lib-files) – drescherjm Sep 21 '21 at 12:57

0 Answers0