1

I am trying glog. I have downloaded last version (0.3.5)

I try to compile with cmake.

What I have done is:

  • I have compiled as static library with options BUILD_TESTING = OFF and WITH_GFLAGS = OFF and used libglog.a perfectly on linux

  • Now I try on windows. I have compiled glog with same options as static library:

    [ 11%] Building CXX object CMakeFiles/glog.dir/src/demangle.cc.obj
    [ 22%] Building CXX object CMakeFiles/glog.dir/src/logging.cc.obj
    [ 33%] Building CXX object CMakeFiles/glog.dir/src/raw_logging.cc.obj
    [ 44%] Building CXX object CMakeFiles/glog.dir/src/symbolize.cc.obj
    [ 55%] Building CXX object CMakeFiles/glog.dir/src/utilities.cc.obj
    [ 66%] Building CXX object CMakeFiles/glog.dir/src/vlog_is_on.cc.obj
    [ 77%] Building CXX object CMakeFiles/glog.dir/src/signalhandler.cc.obj
    [ 88%] Building CXX object CMakeFiles/glog.dir/src/windows/port.cc.obj
    [100%] Linking CXX static library libglogd.a
    [100%] Built target glog
    
  • Then, when i try to use it in a project (executable) including libglogd.a just like in linux, I got these exceptions of linking when compiling executable:

    undefined reference to `_imp___ZN6google17InitGoogleLoggingEPKc'
    undefined reference to `_imp___ZN6google10LogMessageC1EPKci'
    undefined reference to `_imp___ZN6google10LogMessage6streamEv'
    undefined reference to `_imp___ZN6google10LogMessageD1Ev'
    undefined reference to `_imp___ZN6google10LogMessageC1EPKcii'
    undefined reference to `_imp___ZN6google10LogMessage6streamEv'
    undefined reference to `_imp___ZN6google10LogMessageD1Ev'
    undefined reference to `_imp___ZN6google10LogMessageD1Ev'
    undefined reference to `_imp___ZN6google10LogMessageD1Ev'
    
  • I could not find any further info about this.

Here is CMakeLists.txt of executable:

project(exe)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)

#Ignore QT specified variables
set(ignoreMe "${QT_QMAKE_EXECUTABLE}")

#set(HEADERS foo.h)

add_executable(${PROJECT_NAME} ${SRC_LIST})

if (!WIN32)
    target_include_directories(${PROJECT_NAME} PUBLIC
        /home/glog-master/trunk/build/linux/Debug
        /home/glog-master/trunk/src
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include/${PROJECT_NAME}>)

    target_link_libraries(${PROJECT_NAME} /home/glog-master/trunk/build/linux/Debug/libglogd.a)
else()
    target_include_directories(${PROJECT_NAME} PUBLIC
        D:/glog-master/trunk/build/windows/Debug
        D:/glog-master/trunk/src
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include/${PROJECT_NAME}>)

    target_link_libraries(${PROJECT_NAME} D:/glog-master/trunk/build/windows/Debug/libglogd.a)
endif()

And here is the only file of executable, main.cpp:

#include <iostream>
#include "glog/logging.h"

using namespace std;

int main() {

    google::InitGoogleLogging("MYEXE");

    LOG(INFO) << "This is an info  message MAIN";
    LOG(WARNING) << "This is a warning message MAIN";

    return 0;
}

What do I miss in windows?

EDIT: The library has those symbols without _imp. How do I get rid of it? I do not have dllimport.

EDIT 2: Well, I do have dllimport. I should not have. To get rid of it I see that I should define GOOGLE_GLOG_DLL_DECL. When I define it, then undefined references are:

undefined reference to google::InitGoogleLogging(char const*)
undefined reference to google::LogMessage::LogMessage(char const*, int)
...
Mert Mertce
  • 1,049
  • 7
  • 34
  • You are building both glog library and your executable with **gcc** using **NMake** on Windows, am I right? – Tsyvarev Feb 19 '18 at 13:07
  • Yes, I compile both with mingw release 7.1.0 posix dwarf rt v5 rev 2.7 – Mert Mertce Feb 19 '18 at 13:25
  • When I look to the library .a, I see symbols like __ZN6google10LogMessageD1Ev. So, "_imp" is surplus. Where does it come? I do not have dllimport. – Mert Mertce Feb 20 '18 at 06:57
  • As far as I understand the [question on msdn](https://social.msdn.microsoft.com/Forums/sqlserver/en-US/663154ff-08bf-44a5-a50b-1f8e7ea26e43/linker-error-undefined-reference-when-linking-c-library-to-c-application?forum=vcgeneral), you shouldn't have any `__declecspec` in your headers if the library is in the form of `.a` file. – Tsyvarev Feb 20 '18 at 08:27
  • @Tsyvarev Curiously, I do not have, but now undefined reference is InitGoogleLogging, whereas the actual symbol is ___ZN6google17InitGoogleLoggingEPKc – Mert Mertce Feb 20 '18 at 08:32
  • Probably, the way you have built glog statically is incorrect. Have you use `-DBUILD_SHARED_LIBS=OFF` for that purpose? – Tsyvarev Feb 20 '18 at 08:48
  • @Tsyvarev Yes, I checked it with cmake "message", and it was not entering into where BUILD_SHARED_LIBS was ON. Finally it worked but I do not know why. If you know the things in my answer please comment below the answer, even write another answer and I accept. Thank you for interest! – Mert Mertce Feb 20 '18 at 08:51

1 Answers1

1

I have made these things:

  • I had to install glog to the system and then I link it with this:

    target_link_libraries(${PROJECT_NAME glog::glog}
    

Here says that making so adds definitions and options automatically. So, there were some more options/definitions on windows. I would rather know them instead of forced to install glog and use the library directly from its build path as I did on linux.

This stays as mysterious. If someone knows, please comment.

  • Then, I had other unresolved symbols. Those are solved by adding dbghelp as target library. I do also not know why I am forced to include this on windows.

But finally after these changes my executable is compiled and worked.

Mert Mertce
  • 1,049
  • 7
  • 34
  • `I would rather know them instead of forced to install glog and use the library directly from its build path as I did on linux.` - Hmm, `CMakeLists.txt` for glog has `export` calls. Probably, `find_package(glog)` should work for the glog which is just built (and not installed). You may try that. – Tsyvarev Feb 20 '18 at 09:03
  • Formatting hint: for being properly formatted, a code, which is a part of a list, should be **additionally indented** with 4 spaces. `Ctrl+K` behave wrongly in that case (it removes indentation instead), but you may fool it: add new line before/after the code with just a single character in it, started at the very beginning. Then select the code plus this line and use `Ctrl+K` (or `{}` button). After that just remove the line you have added before. – Tsyvarev Feb 20 '18 at 09:09