尝试在 windows 上使用 glog 结果未定义的引用

Trying to use glog on windows results undefined references

我正在尝试 glog。我已经下载了最新版本 (0.3.5)

我尝试用cmake编译。

我所做的是:

这里是 CMakeLists.txt 的可执行文件:

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

这里是唯一的可执行文件,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;
}

我在 windows 中错过了什么?

编辑: 图书馆有那些没有 _imp 的符号。我该如何摆脱它?我没有 dllimport。

编辑 2: 嗯,我有 dllimport。我不应该。为了摆脱它,我发现我应该定义 GOOGLE_GLOG_DLL_DECL。当我定义它时,未定义的引用是:

undefined reference to google::InitGoogleLogging(char const*)
undefined reference to google::LogMessage::LogMessage(char const*, int)
...

我做了这些东西:

  • 我必须将 glog 安装到系统中,然后我 link 使用它:

    target_link_libraries(${PROJECT_NAME glog::glog}
    

Here 说这样做会自动添加定义和选项。因此,windows 上还有一些 options/definitions。我宁愿了解它们,而不是像我在 linux 上那样被迫安装 glog 并直接从其构建路径使用库。

这仍然很神秘。如果有人知道,请评论。

  • 然后,我还有其他未解析的符号。这些通过添加 dbghelp 作为目标库来解决。我也不知道为什么我被迫在 windows.
  • 上包含这个

但最终在这些更改之后我的可执行文件被编译并运行了。