google / glog

C++ implementation of the Google logging module
http://google.github.io/glog/
BSD 3-Clause "New" or "Revised" License
6.93k stars 2.05k forks source link

Can not build app integrating glog using CMake . #1079

Closed xsc351072127 closed 5 months ago

xsc351072127 commented 5 months ago

In short,I find build glog with cmake version 3.25.1. And use find_package() to add glog to the project, Do not add -DGLOG_USE_GLOG_EXPORT for the build command.

I installed Glog according to the document requirements.

cd glog  
cmake -S . -B build  
cmake --build build   
cmake --build build --target install

I got the install log like these,all these is work find.

-- Installing: /usr/local/lib/libglog.so.0.7.0  
-- Installing: /usr/local/lib/libglog.so.2  
-- Installing: /usr/local/lib/libglog.so  
-- Installing: /usr/local/include/glog/export.h  
-- Installing: /usr/local/include/glog/log_severity.h  
-- Installing: /usr/local/include/glog/logging.h  
-- Installing: /usr/local/include/glog/platform.h  
-- Installing: /usr/local/include/glog/raw_logging.h  
-- Installing: /usr/local/include/glog/stl_logging.h  
-- Installing: /usr/local/include/glog/types.h  
-- Installing: /usr/local/include/glog/flags.h  
-- Installing: /usr/local/include/glog/vlog_is_on.h  
-- Installing: /usr/local/lib/cmake/glog/glog-modules.cmake  
-- Installing: /usr/local/lib/cmake/glog/glog-config.cmake  
-- Installing: /usr/local/lib/cmake/glog/glog-config-version.cmake  
-- Installing: /usr/local/share/glog/cmake  
-- Installing: /usr/local/share/glog/cmake/FindUnwind.cmake  
-- Installing: /usr/local/lib/cmake/glog/glog-targets.cmake  
-- Installing: /usr/local/lib/cmake/glog/glog-targets-noconfig.cmake  

After I build myapp use cmake and use the find_package, with cmake 3.25.1,my cmake file

cmake_minimum_required (VERSION 3.16)
project (myproj VERSION 1.0)
find_package (glog 0.7.0 REQUIRED)
add_executable (myapp main.cpp)
target_link_libraries (myapp glog::glog)

And build myapp,I got build error,My cmake output show that glog was found by find_package.

-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found Unwind: /usr/include/x86_64-linux-gnu (found suitable version "1.6.2", minimum required is "1.6.2")
-- Configuring done
-- Generating done

I got build error like this:

image

/usr/local/include/glog/logging.h:60:4: error: #error <glog/logging.h> was not included correctly. See the documentation for how to consume the library.

After some debugging I found, I can build the demo with this cmake and keep glog in my porject dir(with use add_subdirectory ):

cmake_minimum_required (VERSION 3.16)
project (myproj VERSION 1.0)
add_subdirectory (glog)
add_executable (myapp main.cpp)
target_link_libraries (myapp glog::glog)

The make show that this build will add -DGLOG_USE_GLOG_EXPORT but find_package() do not.

[ 34%] Building CXX object CMakeFiles/myapp.dir/main.cpp.o
/usr/bin/c++ -DGLOG_USE_GLOG_EXPORT -I/home/dev/workspace/test_glog/build/glog -I/home/dev/workspace/test_glog/glog/src  -MD -MT CMakeFiles/myapp.dir/main.cpp.o -MF CMakeFiles/myapp.dir/main.cpp.o.d -o CMakeFiles/myapp.dir/main.cpp.o -c /home/dev/workspace/test_glog/main.cpp
sityliu commented 5 months ago

Having the same problem as you, I am using version 0.6.0 for the time being

SteveSelva commented 5 months ago

I also came across this issue, so I rolled back to 0.6.0.

xsc351072127 commented 5 months ago

It is my mistake. I write the target_link_libraries (myapp glog) but not target_link_libraries (myapp glog::glog)

Sorry I will close this issue.