0

I have Windows 7 64bit, CMake 3.8.1, NVidia Cuda 8.0, NVidia Video Codec SDK 7.1.9.

I have this file: C:\Windows\SysWOW64\nvEncodeAPI.dll

I have this CMake module: D:\projects\git\myProject\CMakeModules\FindNVenc.cmake as follows...

Outline (of relevant part):

  • Printing variables (sometimes environment variables after an ENV word)
  • Printing find_library command
  • Executing find_library command
  • Printing NVenc_LIBRARY variable

Contents as-is (of relevant part):

message(STATUS "NVenc_ROOT: ${NVenc_ROOT} ENV $ENV{NVenc_ROOT}")
message(STATUS "NVenc_INCLUDE_DIR: ${NVenc_INCLUDE_DIR} ENV $ENV{NVenc_INCLUDE_DIR}")
message(STATUS "NVenc_LIBRARY_DIR: ${NVenc_LIBRARY_DIR} ENV $ENV{NVenc_LIBRARY_DIR}")
message(STATUS "NVenc_LIBRARY_NAME: ${NVenc_LIBRARY_NAME}")
message(STATUS "find_library(NVenc_LIBRARY NAMES ${NVenc_LIBRARY_NAME} PATHS ${NVenc_LIBRARY_DIR} $ENV{NVenc_LIBRARY_DIR} ${NVenc_ROOT} $ENV{NVenc_ROOT} PATH_SUFFIXES lib NO_DEFAULT_PATH)")
find_library(NVenc_LIBRARY NAMES ${NVenc_LIBRARY_NAME}
  PATHS ${NVenc_LIBRARY_DIR} $ENV{NVenc_LIBRARY_DIR} ${NVenc_ROOT} $ENV{NVenc_ROOT}
  PATH_SUFFIXES lib
  NO_DEFAULT_PATH)
message(STATUS "NVenc_LIBRARY: ${NVenc_LIBRARY}")

The output is

-- NVenc_ROOT:  ENV D:\projects\git\libs
-- NVenc_INCLUDE_DIR: D:/projects/git/libs ENV
-- NVenc_LIBRARY_DIR:  ENV C:\Windows\SysWOW64
-- NVenc_LIBRARY_NAME: nvEncodeAPI
-- find_library(NVenc_LIBRARY nvEncodeAPI PATHS  C:\Windows\SysWOW64  D:\projects\git\libs PATH_SUFFIXES lib NO_DEFAULT_PATH)
-- NVenc_LIBRARY: NVenc_LIBRARY-NOTFOUND

Which means that the find_library command did not find the file I have. This CMake module is working perfectly on Linux. (Worked until I started to alter it on Windows. Now I really don't know, but I think it still should work. Will fix If I broke it.)

Do I have a typo somewhere? Is there something that I don't get about find_library?

Notinlist
  • 16,144
  • 10
  • 57
  • 99
  • I have no idea if this could be the problem but shouldn't you use backslashes here since it's windows `-- NVenc_INCLUDE_DIR: D:/projects/git/libs ENV` ? – Loay Ashmawy May 04 '17 at 14:27
  • I tried forward and backward slashes at places. Did not change anything in any direction. – Notinlist May 04 '17 at 14:38
  • Try using find_library( ... HINTS ) – Tiago Cunha May 04 '17 at 15:57
  • Which generator do you use? If Visual Studio, it wants `.lib` file (it cannot link using `.dll`). – Tsyvarev May 04 '17 at 20:22
  • Yes. Visual Studio. What do you mean by wants? I don't have .lib, I will never have. Is it really impossible at all to use .h with .dll? Or I just have to use other ways with CMake? – Notinlist May 05 '17 at 07:37
  • 1
    Answer to [that question](http://stackoverflow.com/questions/15856445/cmake-find-sqlite3-library-on-windows) also tells that for Visual Studio `find_library` looks for `.lib`. Not sure whether it is actually applied to 64-bit Windows, but you may check content of `CMAKE_FIND_LIBRARY_SUFFIXES` variable. You may try to create `.lib` from `.dll` by following [this question](http://stackoverflow.com/questions/9360280/how-to-make-a-lib-file-when-have-a-dll-file-and-a-header-file). – Tsyvarev May 05 '17 at 08:00
  • @Tsyvarev Can you give me reference for the "it cannot link using .dll"? – Notinlist May 05 '17 at 09:06
  • 1
    From the CMake [mailing discussion](http://cmake.3232098.n2.nabble.com/FindLibrary-only-looks-for-lib-under-Windows-tp5532822p5535193.html): `In VS linking to the .lib is necessary even though the executable code is in the .dlls`. See also [Linking an Executable to a DLL](https://msdn.microsoft.com/en-us/library/9yd93633.aspx) in MSDN. – Tsyvarev May 05 '17 at 09:15

0 Answers0