Comments (37)
Just for the sake of completeness. I recently had some issues with how the glog CMake implementation works. It is not glog related I guess it is how CMake's find_package
config mode works. Together with object-libraries CMake did not passed the Include files folder to the object file compilation step.
This example form ifm3d will fail compilation at least under Windows with Visual Studio 2017
file(GLOB IFM3D_CAMERA_SOURCES *.cpp)
add_library(ifm3d_camera OBJECT ${IFM3D_CAMERA_SOURCES})
set_property(TARGET ifm3d_camera PROPERTY POSITION_INDEPENDENT_CODE 1)
add_library(ifm3d_camera_shared SHARED $<TARGET_OBJECTS:ifm3d_camera>)
target_link_libraries(
ifm3d_camera_shared
glog::glog
${LIB_xmlrpcxx}
${LIB_xmlrpc_clientxx}
)
The fix is pretty easy but maybe this save someone some time
find_package(Boost REQUIRED COMPONENTS system date_time regex)
find_package(glog REQUIRED CONFIG NAMES google-glog glog)
if (NOT TARGET glog::glog)
find_library(LIB_glog NAMES glog)
else()
set(LIB_glog glog::glog)
endif (NOT TARGET glog::glog)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
file(GLOB IFM3D_FG_SOURCES *.cpp)
add_library(
ifm3d_framegrabber_shared SHARED ${IFM3D_FG_SOURCES}
)
set_property(TARGET ifm3d_framegrabber_shared PROPERTY POSITION_INDEPENDENT_CODE 1)
target_link_libraries(
ifm3d_framegrabber_shared
ifm3d_camera_shared
${LIB_glog}
${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
from glog.
Thanks for the hint with the extra library and I highly appreciate your CMake support for glog which saved me a lot of time.
I tried to explain in the comments above I do not consider this a bug in Glogs CMake implementation nor in the CMake itself. It was just something which took me quite some time to figure out. And I tried to document it somehow so maybe I can save someone some time.
from glog.
I've added CMake support to glog: https://github.com/sergiud/glog. Tested on Windows using VC 8.0-14.0 CTP 6 and cygwin gcc 4.9.2, and on Arch Linux using gcc 4.9.2 and clang 3.6.
Usage in a CMake project:
cmake_minimum_required (VERSION 2.8.11)
project (myproject)
find_package (glog 0.3.4)
add_executable (myproject myproject.cpp)
target_link_libraries (myproject glog)
from glog.
Hi thanks for your work ! I will test it asap.
how about a pull request on the google/glog to see what the maintainer says ?
from glog.
There are minor things left to be done. Once I'm done, I'll create a pull request.
from glog.
When adding cmake support it would be nice to have also mingw support on windows.
The release 0.3.4 states "attempt to improve mingw-w64 support", but I think that's maybe only for cross compiles.
Building with mingw-w64 seems not to be supported.
from glog.
MinGW and CMake support are pretty much unrelated issues. MinGW is simply missing functions that are required to compile glog.
from glog.
Thank you for your help.
I was able to compile glog with mingw, but I had to use msys to run the configure script, and there were some linker problems with the test. Also there are some problems with pthreads, because glog defines its own pthreads. I had to use mingw without pthread support. But I was able to use the library in my project that I compiled with MinGW and the logging could be used correctly. MinGW does not support symbolic links, but glog can be used without this functionality. I just thought that during the cmake process one could check for mingw compiler and set the correct macros.
Currently I am testing your cmake fork and it also seems that somehow the MSVC Project can not include the gflags headers correctly.
from glog.
What MinGW version are you using? Maybe I can take a look.
Would you also post the CMake/compiler output regarding the gflags problem? Thanks.
from glog.
I am using mingw-w64: i686-4.9.2-win32-sjlj-rt_v3-rev1 from the mingw-w64 project.
Note that in logging.h I had to import stdlib and disable the dllimport stuff also for mingw
#include <stdlib.h>
...
# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
# define GOOGLE_GLOG_DLL_DECL __declspec(dllimport)
# else
# define GOOGLE_GLOG_DLL_DECL
# endif
The problem with gflags is, that the headers are not found.
Fehler 1 error C1083: Datei (Include) kann nicht geöffnet werden: "gflags/gflags.h": No such file or directory d:\buildlibs\glogcmake\glog\src\base\commandlineflags.h 58 1 glog
From the CmakeCache.txt
//The directory containing a CMake configuration file for Gflags.
Gflags_DIR:PATH=D:/libs/local/cmake
Additionally you could add Cache variable in cmake to disable gflags.
Thank you
from glog.
My MinGW installation is missing the strerror_s
and localtime_s
functions, which are required for the implementation of strerror_r
and localtime_r
. I pushed a fix for the gflags issue, though.
from glog.
As a side note, you have to use the gflags_DIR
CMake variable instead of Gflags_DIR
now.
from glog.
Thank you. Compiling without gflags with MSVS works now.
When building with gflags, the gflags headers are still not included automatically.
This is a typo, the gflags include directory is called gflags_INCLUDE_DIR
and not gflags_INCLUDE_DIRS
.
After fixing this, MSVS complains about:
Compiler Error C2370
'identifier' : redefinition; different storage class
in logging.cc line 105, 107, 134, 1034, 175, 140, 142, 172, 138, 128, 166, 168
e.g.: 'fLB::FLAGS_alsologtostderr'
in vlog_is_on line 53
'fLI::FLAGS_v'
and
Compiler Error C2872
'symbol' : ambiguous symbol
'int64' and 'uint32' in several lines in logging_unittest.cc
mingw with posix threads is not compiling, I will try mingw with win32 threads later.
from glog.
Thanks for letting me know. The gflags issues should be fixed now.
from glog.
using mingw with win32 threads:
PS D:\buildlibs\glogcmake\glog\build> mingw32-make
Scanning dependencies of target glog
[ 8%] Building CXX object CMakeFiles/glog.dir/src/demangle.cc.obj
[ 16%] Building CXX object CMakeFiles/glog.dir/src/logging.cc.obj
[ 25%] Building CXX object CMakeFiles/glog.dir/src/raw_logging.cc.obj
[ 33%] Building CXX object CMakeFiles/glog.dir/src/symbolize.cc.obj
[ 41%] Building CXX object CMakeFiles/glog.dir/src/utilities.cc.obj
[ 50%] Building CXX object CMakeFiles/glog.dir/src/vlog_is_on.cc.obj
[ 58%] Building CXX object CMakeFiles/glog.dir/src/signalhandler.cc.obj
[ 66%] Building CXX object CMakeFiles/glog.dir/src/windows/port.cc.obj
D:\buildlibs\glogcmake\glog\src\windows\port.cc: In function 'int snprintf(char*, size_t, const char*, ...)':
D:\buildlibs\glogcmake\glog\src\windows\port.cc:59:5: error: redefinition of 'int snprintf(char*, size_t, const char*, .
..)'
int snprintf(char *str, size_t size, const char *format, ...) {
^
In file included from D:/Software/mingw-w64/i686-4.9.2-win32-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/locale.h:1
2:0,
from D:/Software/mingw-w64/i686-4.9.2-win32-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/clocal
e:42,
from D:/Software/mingw-w64/i686-4.9.2-win32-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/i686-w
64-mingw32/bits/c++locale.h:41,
from D:/Software/mingw-w64/i686-4.9.2-win32-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/bits/l
ocalefwd.h:40,
from D:/Software/mingw-w64/i686-4.9.2-win32-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/string
:43,
from D:\buildlibs\glogcmake\glog\src\windows\port.cc:43:
D:/Software/mingw-w64/i686-4.9.2-win32-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/stdio.h:339:5: note: 'int snprin
tf(char*, size_t, const char*, ...)' previously defined here
int snprintf (char *__stream, size_t __n, const char *__format, ...)
^
At global scope:
cc1plus.exe: warning: unrecognized command line option "-Wno-unnamed-type-template-args"
CMakeFiles\glog.dir\build.make:222: recipe for target 'CMakeFiles/glog.dir/src/windows/port.cc.obj' failed
mingw32-make[2]: *** [CMakeFiles/glog.dir/src/windows/port.cc.obj] Error 1
CMakeFiles\Makefile2:94: recipe for target 'CMakeFiles/glog.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/glog.dir/all] Error 2
makefile:146: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
PS D:\buildlibs\glogcmake\glog\build>
using mingw with posix threads:
PS D:\buildlibs\glogcmake\glog\build> mingw32-make
Scanning dependencies of target glog
[ 8%] Building CXX object CMakeFiles/glog.dir/src/demangle.cc.obj
[ 16%] Building CXX object CMakeFiles/glog.dir/src/logging.cc.obj
In file included from D:\buildlibs\glogcmake\glog\src\utilities.h:78:0,
from D:\buildlibs\glogcmake\glog\src\logging.cc:32:
D:/buildlibs/glogcmake/glog/src/windows/port.h:139:15: error: conflicting declaration 'typedef DWORD pthread_t'
typedef DWORD pthread_t;
^
In file included from D:/Software/mingw-w64/i686-4.9.2-posix-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/i686-w
64-mingw32/bits/gthr-default.h:35:0,
from D:/Software/mingw-w64/i686-4.9.2-posix-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/i686-w
64-mingw32/bits/gthr.h:148,
from D:/Software/mingw-w64/i686-4.9.2-posix-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/ext/at
omicity.h:35,
from D:/Software/mingw-w64/i686-4.9.2-posix-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/bits/b
asic_string.h:39,
from D:/Software/mingw-w64/i686-4.9.2-posix-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/string
:52,
from D:\buildlibs\glogcmake\glog\src\utilities.h:75,
from D:\buildlibs\glogcmake\glog\src\logging.cc:32:
D:/Software/mingw-w64/i686-4.9.2-posix-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/pthread.h:196:19: note: previous
declaration as 'typedef uintptr_t pthread_t'
typedef uintptr_t pthread_t;
^
In file included from D:\buildlibs\glogcmake\glog\src\utilities.h:78:0,
from D:\buildlibs\glogcmake\glog\src\logging.cc:32:
D:/buildlibs/glogcmake/glog/src/windows/port.h:140:15: error: conflicting declaration 'typedef DWORD pthread_key_t'
typedef DWORD pthread_key_t;
^
In file included from D:/Software/mingw-w64/i686-4.9.2-posix-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/i686-w
64-mingw32/bits/gthr-default.h:35:0,
from D:/Software/mingw-w64/i686-4.9.2-posix-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/i686-w
64-mingw32/bits/gthr.h:148,
from D:/Software/mingw-w64/i686-4.9.2-posix-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/ext/at
omicity.h:35,
from D:/Software/mingw-w64/i686-4.9.2-posix-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/bits/b
asic_string.h:39,
from D:/Software/mingw-w64/i686-4.9.2-posix-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/c++/string
:52,
from D:\buildlibs\glogcmake\glog\src\utilities.h:75,
from D:\buildlibs\glogcmake\glog\src\logging.cc:32:
D:/Software/mingw-w64/i686-4.9.2-posix-sjlj-rt_v3-rev1/mingw32/i686-w64-mingw32/include/pthread.h:182:18: note: previous
declaration as 'typedef unsigned int pthread_key_t'
typedef unsigned pthread_key_t;
^
D:/buildlibs/glogcmake/glog/src/windows/port.h:142:8: error: expected identifier before numeric constant
enum { PTHREAD_ONCE_INIT = 0 }; // important that this be 0! for SpinLock
^
D:/buildlibs/glogcmake/glog/src/windows/port.h:142:8: error: expected '}' before numeric constant
D:/buildlibs/glogcmake/glog/src/windows/port.h:142:8: error: expected unqualified-id before numeric constant
In file included from D:\buildlibs\glogcmake\glog\src\utilities.h:78:0,
from D:\buildlibs\glogcmake\glog\src\logging.cc:32:
D:/buildlibs/glogcmake/glog/src/windows/port.h:142:30: error: expected declaration before '}' token
enum { PTHREAD_ONCE_INIT = 0 }; // important that this be 0! for SpinLock
^
cc1plus.exe: warning: unrecognized command line option "-Wno-unnamed-type-template-args"
CMakeFiles\glog.dir\build.make:78: recipe for target 'CMakeFiles/glog.dir/src/logging.cc.obj' failed
mingw32-make[2]: *** [CMakeFiles/glog.dir/src/logging.cc.obj] Error 1
CMakeFiles\Makefile2:94: recipe for target 'CMakeFiles/glog.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/glog.dir/all] Error 2
makefile:146: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
from glog.
I see. Adding MinGW support basically requires some code refactoring, which I can't really help with.
from glog.
Thank you very much for your help. In the release 0.3.4, the developers added the feature
- attempt to improve mingw-w64 support
I hope they will continue adding mingw-w64 on windows with cmake.
from glog.
sergiud, there's a bug in your CMake build somewhere, on Windows 7 with Visual Studio 2013 Community Edition at least. It doesn't copy the glog\log_severity.h file. I haven't found the cause yet. I'm building in build\serguid_glog. My build\sergiud_glog\glog directory doesn't have the file, although all the other *.h files are present. build\sergiud_glog\install_manifest.txt does not list the file, but the other *.h files are listed. As I have not found an explicit list of these files for installation, I am guessing you used some kind of automated routine to grab all the needed files, and had an endpoint error iterating through them. I would have filed this as an issue in your github repository, but you don't seem to have Issues enabled.
Anyways count me as someone who'd like to see an official CMake build for glog. I've found 3 different ones including sergiud's. I'm currently dealing with 2 projects that consume gflags and glog, that aren't working well with gflags detection or glog building in Visual Studio 2013. The .sln files that glog proper provides, are only 32-bit when imported to Visual Studio 2013. 7 project upgrade errors are given, which might be worrisome.
from glog.
@bvanevery, good catch. I failed to include log_severity.h
for install.
from glog.
sergiud, are you going to fix that in your repo? Or at least enable Issues reporting in your repo, so that it's not forgotten?
from glog.
@bvanevery I've enabled issues in my repository.
from glog.
@sergiud Hi, I am glad that you make google-glog support CMake, however, I write a find_package(glog REQUIRED)
in my CMakeList.txt, and cmake it, it complains:
CMake Error at CMakeLists.txt:26 (find_package):
By not providing "Findglog.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "glog", but
CMake did not find one.
Could not find a package configuration file provided by "glog" with any of
the following names:
glogConfig.cmake
glog-config.cmake
My OS is Arch Linux, and I execute pacman -Ql google-glog
, I do not know why does it not contains the glog-config.cmake
:
google-glog /usr/
google-glog /usr/include/
google-glog /usr/include/glog/
google-glog /usr/include/glog/log_severity.h
google-glog /usr/include/glog/logging.h
google-glog /usr/include/glog/raw_logging.h
google-glog /usr/include/glog/stl_logging.h
google-glog /usr/include/glog/vlog_is_on.h
google-glog /usr/lib/
google-glog /usr/lib/libglog.so
google-glog /usr/lib/libglog.so.0
google-glog /usr/lib/libglog.so.0.0.0
google-glog /usr/lib/pkgconfig/
google-glog /usr/lib/pkgconfig/libglog.pc
google-glog /usr/share/
google-glog /usr/share/licenses/
google-glog /usr/share/licenses/google-glog/
google-glog /usr/share/licenses/google-glog/COPYING
Any ides? Thank you!
from glog.
Glog 0.3.5 which includes CMake support has not been released yet. You'll have to compile Glog from source.
from glog.
@sergiud So it is! Thank you!
from glog.
@sergiud Hi, I write the PKBGUILD to comiple Glog from source, however, I find it does not compile libglog.so
, I do not know why, any idea? Thank you!
See my compile output and PKGBUILD: https://gist.github.com/acgtyrant/ae5794c37cef79c8464c
from glog.
You have two code paths there. The first one (which calls find_library
) uses only the raw glog library. This code path may fail if you did not set the include directories, compile definitions etc. correctly, which is user's responsibility. The second one where the glog::glog
target is defined, should not fail if the package was found.
I don't see how the problem is related to CMake's config mode or object-libraries. Why do you need to locate glog using find_library
in the first place?
from glog.
@sergiud the find_library(LIB_glog NAMES glog)
is for glog < 0.3.5 where no CMake support was provided. If using the glog::glog
which uses the magic inside the CMake-config file for setting the right compiler and linker flags this will not work when compiling an OBJECT library. Because at least the include path is not provided correctly and the CFLAGS also missing.
add_library(ifm3d_camera OBJECT ${IFM3D_CAMERA_SOURCES})
from glog.
As per CMake documentation object libraries only compile the sources. You need to add another library which uses the objects and then you can link to the imported glog::glog
target as usual.
from glog.
My OS is Arch Linux, and I execute
pacman -Ql google-glog
, I do not know why does it not contains theglog-config.cmake
:
i want to know how you solve this problem. i also met this case!
from glog.
@majiqiang It looks like Arch uses configure
to build the package thus the cmake stuff is not generated. So you can add a comment or vote on their issue tracker to the already opened issue about this.
FS#55185 - [google-glog] use cmake to build to generate cmake import configs maybe adding a link to this issue might shed some lights.
from glog.
@majiqiang It looks like Arch uses
configure
to build the package thus the cmake stuff is not generated. So you can add a comment or vote on their issue tracker to the already opened issue about this.
FS#55185 - [google-glog] use cmake to build to generate cmake import configs maybe adding a link to this issue might shed some lights.
@graugans What should I do specifically? I first installed various dependencies, such as glog, egien3, and so on. Then I git clone handeye-calib-camodocal to my workspace ~/catkin_ws/src, and catkin_make. but I got the errors:
Could not find a package configuration file provided by "Glog" with any of
the following names:
GlogConfig.cmake
glog-config.cmake
from glog.
@majiqiang you can try to get in touch with the Arch guys so they fix it. or you can build glog from source.
from glog.
@majiqiang you can try to get in touch with the Arch guys so they fix it. or you can build glog from source.
@graugans you mean this?
git clone https://github.com/google/glog
sudo apt-get install autoconf automake libtool
./autogen.sh
./configure
make -j 24
sudo make install
from glog.
This will not help. This is exactly how the Arch Maintainer builds. You have to use CMake. https://github.com/google/glog/blob/master/cmake/INSTALL.md
from glog.
Whenever I build on windows I get a warning fLB::FLAGS_logtostderr': inconsistent dll linkage
And after running tests, symbolize always fails.
Anyone point me in the right direction?
from glog.
When I execute the cmake, it says the add_library cannot create imported target "glog::glog" because another
target with the same name already exists. Could anyone help me about it? Thanks.
-- Found Glog
-- Includes : /usr/include
-- Libraries : /usr/lib/x86_64-linux-gnu/libglog.so
-- Found SQLite3: /usr/include (found version "3.31.1")
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so
-- Found Git: /usr/bin/git (found version "2.25.1")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found required Ceres dependency: Eigen version 3.3.7 in /usr/lib/cmake/eigen3
CMake Error at /usr/local/lib/cmake/Ceres/FindGlog.cmake:349 (add_library):
add_library cannot create imported target "glog::glog" because another
target with the same name already exists.
Call Stack (most recent call first):
/usr/local/lib/cmake/Ceres/CeresConfig.cmake:247 (find_package)
cmake/FindDependencies.cmake:33 (find_package)
CMakeLists.txt:85 (include)
-- Found required Ceres dependency: glog
-- Found Ceres version: 2.2.0 installed in: /usr/local with components: [EigenSparse, SparseLinearAlgebraLibrary, SchurSpecializations]
from glog.
With the information you provided it is hard to tell what is going on. However, if had to guess I'd say that you are using broken/outdated distribution that does not provide a CMake glog package configuration or the project that you are trying to compile is mixing different glog versions.
I suggest opening a separate issue with detailed information on how to reproduce the error.
from glog.
Related Issues (20)
- How to encrypt logs HOT 1
- [proposal] Provide pre-defined JSON log sink in glog HOT 2
- [Emscripten][Ubuntu 22.04.3 LTS] Use of undeclared identifier 'SYS_write' HOT 3
- building phase in Ubuntu 23.10 : /usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPI HOT 3
- windows mingw64 compile fail HOT 4
- error in including <glog/logging.h> after installing glog according to the official tutorial HOT 2
- namespace "google" has no member "InitGoogleLogging" HOT 1
- FetchContent support HOT 4
- Customizing the Log Line Prefix HOT 2
- Can not build app integrating glog using CMake . HOT 3
- Using call_once could lead to infinite loop in fatal signal handler ? HOT 9
- bazel compilation with emscripten failed HOT 3
- HAVE_SYMBOLIZE missing on linux with bazel
- How do you solve this problem during installation? HOT 1
- Apply max_log_file constraint when timestamp_in_log_file=false
- Flag GLOG_v failed to set in Mac environment and resulting in incorrect printing of logs HOT 1
- why compile can not pass.it ocurrs the errors as follow。 HOT 3
- make error relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' HOT 2
- Support Unicode in paths HOT 6
- LoongArch undefined reference error HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glog.