abumq / easyloggingpp

C++ logging library. It is powerful, supports asynchronous low latency, extendable, light-weight, fast performing, thread and type safe and consists of many built-in features. It provides ability to write logs in your own customized format. It also provide support for logging your classes, third-party libraries, STL and third-party containers etc.
MIT License
3.77k stars 921 forks source link

Build fail with MinGW #58

Closed abumq closed 11 years ago

abumq commented 11 years ago

For details: https://www.facebook.com/icplusplus/posts/566945396679629?comment_id=6509000&offset=0&total_comments=1&notif_t=share_comment

Nuxij commented 11 years ago

Log here: http://haste.alluha.net/sumate.txt

EasyLogging++ - HEAD (8.47?) MinGW - 3.20 G++ - 4.7.2

abumq commented 11 years ago

Great thanks for that

Looks like compiler is not including Windows.h header.will look into fixing this asap

abumq commented 11 years ago

Verbose compilation

>C:\MinGW\bin\g++ -v prog.cc -o prog
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,obj
c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo
mp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-r
untime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.2 (GCC)
COLLECT_GCC_OPTIONS='-v' '-o' 'prog.exe' '-shared-libgcc' '-mtune=i386' '-march=
i386'
 c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/cc1plus.exe -quiet -v -iprefix c:\min
gw\bin\../lib/gcc/mingw32/4.6.2/ prog.cc -quiet -dumpbase prog.cc -mtune=i386 -m
arch=i386 -auxbase prog -version -o C:\Users\Majid\AppData\Local\Temp\ccU3OpfY.s

GNU C++ (GCC) version 4.6.2 (mingw32)
        compiled by GNU C version 4.6.2, GMP version 5.0.1, MPFR version 2.4.1,
MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../.
./mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de"
ignoring duplicate directory "/mingw/lib/gcc/mingw32/4.6.2/../../../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/../
../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++
 c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/mingw32
 c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/backward
 c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include
 c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include
 c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include-fixed
End of search list.
GNU C++ (GCC) version 4.6.2 (mingw32)
        compiled by GNU C version 4.6.2, GMP version 5.0.1, MPFR version 2.4.1,
MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: f7eb4168c2cf10318cc29da8d23b7f3c
In file included from prog.cc:2:0:
easylogging++.h: In static member function 'static const string easyloggingpp::i
nternal::utilities::OSUtils::currentUser()':
easylogging++.h:665:46: error: '_dupenv_s' was not declared in this scope
easylogging++.h: In static member function 'static const string easyloggingpp::i
nternal::utilities::OSUtils::currentHost()':
easylogging++.h:690:50: error: '_dupenv_s' was not declared in this scope
easylogging++.h: In static member function 'static bool easyloggingpp::internal:
:utilities::OSUtils::createPath(const string&)':
easylogging++.h:755:62: error: 'strtok_s' was not declared in this scope
easylogging++.h: In static member function 'static std::string easyloggingpp::in
ternal::utilities::DateUtils::getDateTime(const string&, unsigned int, easyloggi
ngpp::internal::Constants*, unsigned int)':
easylogging++.h:860:60: error: 'sprintf_s' was not declared in this scope
easylogging++.h:867:103: error: 'sprintf_s' was not declared in this scope
easylogging++.h:869:84: error: 'sprintf_s' was not declared in this scope
easylogging++.h: In member function 'easyloggingpp::internal::Writer& easyloggin
gpp::internal::Writer::operator<<(const wchar_t*)':
easylogging++.h:2479:69: error: 'wcsrtombs_s' was not declared in this scope
abumq commented 11 years ago

So windows header is included but mingw version of following versions are not defined

Nuxij commented 11 years ago

From an old 2009 thread, but relevant it seems: "There is no question of MinGW "getting" strtok_s(); as an end user, you may choose to download the appropriate DLLs from Microsoft's own site, but we cannot distribute them. However, we can consider patches to add additional import library references, properly conditionalised to support the functions added in later versions of MSVCRT, but beyond that we cannot go; users who wish to exploit such later runtime versions must acquire the appropriate DLLs for themselves, and developers requiring them must configure their own MinGW installations to deploy them."

This guy defined strtok_r() himself: https://github.com/kwolekr/minetest/commit/69ba4854152415ab3e2ec11cdb6f9c9ce5af9ac8

abumq commented 11 years ago

Joe, yes this is relevant and I believe the solution would be to write my own version of these functions if using minGW in internal::workarounds namespace. The reason why I use these functions instead of standard C functions is because they are deprecated in VC++ and it gives warning. As library author I am concerned with compiler's warnings as this defeats users' motivation towards libraries.

Well I will have a look at better way of resolving this, if not I will go with what I said in the beginning - write custom workarounds

Nuxij commented 11 years ago

No worries man, I understand completely what you're saying :) I'm not knocking your implementation, just looking to use my fav logging library on MinGW :D

Alright, keep us posted! And good luck! ;)

abumq commented 11 years ago

Thanks for that, sure I will

A note, an example from Microsoft MSDN website http://msdn.microsoft.com/en-us/library/ftsafwz3(v=vs.80).aspx does not work with minGW either.

abumq commented 11 years ago

For path creation we can use CreateDirectory(.., ..) for windows so we don't have to write strtok_s func (http://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx)

For username and computer name we can use GetEnvironmentVariable (http://msdn.microsoft.com/en-us/library/windows/desktop/ms683188(v=vs.85).aspx)

Nuxij commented 11 years ago

Nice find!

For sprintf_s, this works from what I'm reading:

define sprintf_s snprintf

Apparently there is snprintf on windows too, as _snprintf, so we could try:

define snprintf _snprintf

Just depends which way round you want to fix it I suppose.

abumq commented 11 years ago

Great so that works with minGW?

abumq commented 11 years ago

oh snprintf is for C++11 apps and I intend to support C++98 as well for EasyLogging++

http://www.cplusplus.com/reference/cstdio/snprintf/

hmm but good finding but will have a look at what could be done :)

abumq commented 11 years ago

ok so because snprintf is C++11 way, I will do something like:

#if defined(_MSC_VER) // VC++
#   define SPRINTF sprintf_s
#else
#   define SPRINTF sprintf
#endif

and then use

SPRINTF(...)

now the only thing left is wcstomb_s()

Nuxij commented 11 years ago

Ah didn't spot that, will keep looking. Maybe we could use sprintf rather than snprintf?

Nuxij commented 11 years ago

Haha, great minds think alike ;D Yup, looking at it :)

abumq commented 11 years ago

Joe, I used sprintf in the first place until realized MS way of doing stuff :) VC++ gives warning of deprecated func. so I believe above way would be good :)

Nuxij commented 11 years ago

Agreed, you just managed to comment faster than me :P

Would wcstombs() be a good replacement for wcsrtombs_s() on mingw?

abumq commented 11 years ago

I will have a look, I am not sure if thats deprecated as well. but surely good idea, even if it is I can do same thing as with SPRINTF macro. I haven't done any coding yet but i guess I will have enough information to code faster once I am ready for it, assigning 8.50 milestone to this ticket

abumq commented 11 years ago

This is completed v8.50, let me know how'd you go :)

Nuxij commented 11 years ago

Yup all working fine, cheers mate :D