easyloggingpp icon indicating copy to clipboard operation
easyloggingpp copied to clipboard

Compile as a DLL using MinGW failed

Open ZacahryZ opened this issue 7 months ago • 0 comments

I modifed the header file easylogging++.h, add ELPP_MINGW to make sure ELPP_EXPORT will be __declspec(dllexport)

#if defined(ELPP_AS_DLL) && (ELPP_COMPILER_MSVC || ELPP_MINGW)
#  if defined(ELPP_EXPORT_SYMBOLS)
#    define ELPP_EXPORT __declspec(dllexport)
#  else
#    define ELPP_EXPORT __declspec(dllimport)
#  endif  // defined(ELPP_EXPORT_SYMBOLS)
#else
#  define ELPP_EXPORT
#endif  // defined(ELPP_AS_DLL) && ELPP_COMPILER_MSVC
// Some special functions that are VC++ specific

This is the command I tried and the output

> g++.exe -std=c++11 -Wall -DELPP_AS_DLL -DELPP_EXPORT_SYMBOLS -DELPP_THREAD_SAFE -c easylogging++.cc -o easylogging++.o
easylogging++.cc: In member function 'el::Logger* el::base::RegisteredLoggers::get(const std::string&, bool)':
easylogging++.cc:1903:83: warning: loop variable 'h' of type 'const std::pair<std::__cxx11::basic_string<char>, std::shared_ptr<el::LoggerRegistrationCallback> >&' binds to a temporary constructed from type 'std::pair<const std::__cxx11::basic_string<char>, std::shared_ptr<el::LoggerRegistrationCallback> >' [-Wrange-loop-construct]
 1903 |     for (const std::pair<std::string, base::type::LoggerRegistrationCallbackPtr>& h
      |                                                                                   ^
easylogging++.cc:1903:83: note: use non-reference type 'const std::pair<std::__cxx11::basic_string<char>, std::shared_ptr<el::LoggerRegistrationCallback> >' to make the copy explicit or 'const std::pair<const std::__cxx11::basic_string<char>, std::shared_ptr<el::LoggerRegistrationCallback> >&' to prevent copying
easylogging++.cc: In member function 'void el::base::LogDispatcher::dispatch()':
easylogging++.cc:2493:74: warning: loop variable 'h' of type 'const std::pair<std::__cxx11::basic_string<char>, std::shared_ptr<el::LogDispatchCallback> >&' binds to a temporary constructed from type 'std::pair<const std::__cxx11::basic_string<char>, std::shared_ptr<el::LogDispatchCallback> >' [-Wrange-loop-construct]
 2493 |   for (const std::pair<std::string, base::type::LogDispatchCallbackPtr>& h
      |                                                                          ^
easylogging++.cc:2493:74: note: use non-reference type 'const std::pair<std::__cxx11::basic_string<char>, std::shared_ptr<el::LogDispatchCallback> >' to make the copy explicit or 'const std::pair<const std::__cxx11::basic_string<char>, std::shared_ptr<el::LogDispatchCallback> >&' to prevent copying
> g++.exe -shared -o libeasylogging.dll easylogging++.o
mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: easylogging++.o:easylogging++.:(.rdata$.refptr._ZN2el4base9elStorageE[.refptr._ZN2el4base9elStorageE]+0x0): undefined reference to `el::base::elStorage'
collect2.exe: error: ld returned 1 exit status

If remove key word extern in line 2751 of easylogging++.h, the methods mentioned above were successful.

extern ELPP_EXPORT base::type::StoragePointer elStorage;

However, when linking the DLL to an executable program, errors still occur.

undefined reference to ~el::base::Writer::construct(int, char const*, ...)
undefined reference to ^el::base::writer::construct(int, char const*, @.)
undefined reference to ~el::base::Writer::processDispatch()

BTW, demo in samples/MinGW can be success.

Source Version: 9.94.1 MinGW Version: x86_64-13.2.0-release-win32-seh-ucrt-rt_v11-rev1

ZacahryZ avatar Apr 09 '25 11:04 ZacahryZ