Mert Mertce
Mert Mertce

Reputation: 1203

Trying to use glog on windows results undefined references

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

I try to compile with cmake.

What I have done is:

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)
...

Upvotes: 1

Views: 2983

Answers (1)

Mert Mertce
Mert Mertce

Reputation: 1203

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.

Upvotes: 1

Related Questions