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.