我正在尝试 glog。我已经下载了最新版本(0.3.5)
我尝试用 cmake 编译。
我所做的是:
我已经编译为带有选项的静态库,
BUILD_TESTING = OFF
并WITH_GFLAGS = OFF
在 linux 上完美地使用了 libglog.a现在我尝试在 Windows 上。我已经用与静态库相同的选项编译了 glog:
[ 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
然后,当我尝试在包括 libglogd.a 的项目(可执行文件)中使用它时,就像在 linux 中一样,我在编译可执行文件时遇到了这些链接异常:
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'
我找不到有关此的任何进一步信息。
这是可执行文件的 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)
...