0

I'm now trying to use glog in my project. By following the rules in google/glog, I designed a log system.

In the compiling stage, I wrote down my CMakeLists.txt as below:

    cmake_minimum_required(VERSION 3.0.2)
    project(glog_system)
    add_compile_options(-std=c++11)
    add_executable(glog_example
        example/example1.cpp
        example/g_logger.cpp
    )
    target_include_directories(glog_example PUBLIC
      example
    )
    target_link_libraries(glog_example
        glog
        stdc++fs
    )

What confused me is if find_package(glog) is not added in the CMakeLists.txt, I can still build the log system, and run the executable file successfully. But why?

I think this is related to cmake, can anyone give me some hints? Thanks.

UPDATE:

- build/
- example/
  - example1.cpp
  - g_logger.cpp
  - g_logger.h
CMakeLists.txt
  • Where do you run cmake? – 273K Oct 26 '22 at 03:12
  • Why do you think the `find_package` call is necessary? I haven't used `glog`, but if headers and its library are in a standard location, the behavior you're reporting would match my expectations. – Stephen Newell Oct 26 '22 at 03:13
  • @273K I just make a "build/" folder and use normal cmake method. I updated the folder structure in my post. – RyanChen.YLC Oct 26 '22 at 03:37
  • @Stephen Newell Because I did not install glog library on my project folder. I install it under `/usr/lib`, so I think I need to use `find_package` call to link this library to my project. – RyanChen.YLC Oct 26 '22 at 03:45
  • `/usr/lib` is almost certainly in the standard search path for your linker. – Stephen Newell Oct 26 '22 at 04:26
  • @StephenNewell So, when do I need to use `find_package`? Only when library is not in standard search path? and use `Find___.cmake` and `find_package` call to search it? I'm a little confused now. BTW, thanks for your comment. – RyanChen.YLC Oct 26 '22 at 05:53

0 Answers0