1

I'm trying to compile my code to dll format (instead of .so format) and I'm doing it on my Ubuntu machine with a MinGW compiler (which was compiled from mxe).

The code uses Google's glog library for logging, and is compiled via Makefile (no cmake usage). The code compiles well for Linux, but when I switch the g++ used in the Makefile to the i686-w64-mingw32.static-g++ compiled from mxe, the linker shows many errors such as this -

undefined reference to `google::LogMessage::LogMessage(char const*, int, int)'
undefined reference to `google::LogMessage::stream()'
undefined reference to `google::LogMessage::~LogMessage()'

To publish this question I've recreated the issue on a small (non-dll) executable -

#define GOOGLE_GLOG_DLL_DECL
#include "glog/logging.h"

int main() {
    LOG(ERROR) << "HELLO";
    return 0;
}

with the following compilation line -

i686-w64-mingw32.static-g++ -L/path/to/library/directory -I/path/to/include/dir \
    -static-libstdc++ simple_main.cpp -lglog -o simple_main.exe

And I've put the glog include files in the include directory and the libglog.a in the directory given with -L. When doing this I'm getting the same errors as my real library -

/tmp/ccBBAXeQ.o:simple_main.cpp:(.text+0x69): undefined reference to `google::LogMessage::LogMessage(char const*, int, int)'
/tmp/ccBBAXeQ.o:simple_main.cpp:(.text+0x7d): undefined reference to `google::LogMessage::stream()'
/tmp/ccBBAXeQ.o:simple_main.cpp:(.text+0x9e): undefined reference to `google::LogMessage::~LogMessage()'
/tmp/ccBBAXeQ.o:simple_main.cpp:(.text+0xc2): undefined reference to `google::LogMessage::~LogMessage()'
collect2: error: ld returned 1 exit status

It's worth mentioning that my issue is very similar to this issue, and I've tried using CMake on my simple main to recreate the issue, but the answer supplied there didn't work for me (still getting the same errors).

I also made sure that the libglog.a file indeed contains the undefined symbols (via nm libglog.a | c++filt | grep ~LogMessage), and I also tried linking against a windows-built glog.lib which I compiled on windows, and this also didn't seem to work (the linker failed to identify the .lib file).

Thus, I'm not sure what the problem is, and I would appreciate some help.

zanron
  • 11
  • 1
  • Any reason you are avoiding ETW? – IInspectable Aug 01 '21 at 16:30
  • 1
    @IInspectable Because my library was (originally) a linux library (and I still need it to compile for linux as well as windows), and thus I need a logging mechanism which is cross platform. Also, I want to avoid replacing all of my logging usage in the existing code and stay with glog. – zanron Aug 03 '21 at 07:51

0 Answers0