1

I have this line in my cmake to pick glog library:

find_library(GLOG_LIBRARY libglog $ENV{GLOG_DIR}/x64/Release)
message(${GLOG_LIBRARY})

and in the release folder I have these files:

03/03/2015  15:00           308,736 libglog.dll
03/03/2015  15:00            64,998 libglog.exp
03/03/2015  15:00           104,884 libglog.lib
03/03/2015  15:00         3,248,128 libglog.pdb

But when I run cmake, I can see that GLOG_LIBRARY is set to libglog_static.lib

why cmake get the wrong library?

mans
  • 17,104
  • 45
  • 172
  • 321
  • Did you run it with cleared cache? I would also run it with explicitly naming the path as a HINT: `find_library(GLOG_LIBRARY libglog HINTS $ENV{GLOG_DIR}/x64/Release)`, but you need to clear cache otherwise cmake won't re-search it. – luk32 Mar 03 '15 at 15:11
  • @luk32 Thanks. What is the difference between adding hint and not adding hint? – mans Mar 03 '15 at 19:05
  • Did it work? If so, I will make it an answer. The difference is kind of like between using named and positional parameters. It's easier to make a mistake, if you don't know the API well. I am not even sure if you can pass named arguments just by position with out using the keyword in cmake. – luk32 Mar 03 '15 at 20:03
  • @luk32 Yes it worked. The problem was cache which after deleting, found the correct lib. Can you please give more information about hint or a place to read? cmake documentation is not clear and has no information about this hint parameter. – mans Mar 03 '15 at 20:39
  • I dunno, maybe the docs are not the clearest but I got all from there. I linked it in my answer. – luk32 Mar 03 '15 at 23:42

1 Answers1

1

Ok, so the problem was that most probably the change in the code to use hint was made after first execution of the script. CMake by default caches most values of its standard functions.

find routines by default first check whether the variable is present in the cache, thus even if you change your code, it might appear not to work. One does need to clear cache manually before trying new version, or if somehow configuration changed - e.g. some flag that changes version or alters resolution process is used - if the name of the variable is the same it will be pulled from cache.

The search process as well as parameters are described in the documentation: http://www.cmake.org/cmake/help/v3.0/command/find_library.html

luk32
  • 15,812
  • 38
  • 62