wisk / medusa

An open source interactive disassembler
Other
1.04k stars 92 forks source link

build fails mingw #26

Closed ghost closed 8 years ago

ghost commented 9 years ago

I try to build using mingw 4.9 using boost 1.5.7

mingw32-make
[ 31%] Built target coin
[ 84%] Built target ogdf
[ 85%] Built target ogdf-test
Scanning dependencies of target Medusa
[ 85%] Building CXX object src/core/CMakeFiles/Medusa.dir/analyzer.cpp.obj
In file included from D:/medusa-dev/inc/medusa/det
ail.hpp:7:0,
                 from D:/medusa-dev/inc/medusa/val
ue.hpp:8,
                 from D:/medusa-dev/inc/medusa/mem
ory_area.hpp:7,
                 from D:/medusa-dev/inc/medusa/doc
ument.hpp:9,
                 from D:/medusa-dev/inc/medusa/ana
lyzer.hpp:6,
                 from D:\medusa-dev\src\core\analy
zer.cpp:1:
D:/medusa-dev/inc/medusa/binary_stream.hpp:248:40:
 error: 'INVALID_HANDLE_VALUE' was not declared in this scope
   TFileHandle             m_FileHandle=INVALID_HANDLE_VALUE;
                                        ^
src\core\CMakeFiles\Medusa.dir\build.make:78: recipe for target 'src/core/CMakeF
iles/Medusa.dir/analyzer.cpp.obj' failed
mingw32-make[2]: *** [src/core/CMakeFiles/Medusa.dir/analyzer.cpp.obj] Error 1
CMakeFiles\Makefile2:455: recipe for target 'src/core/CMakeFiles/Medusa.dir/all'
 failed
mingw32-make[1]: *** [src/core/CMakeFiles/Medusa.dir/all] Error 2
makefile:146: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

D:\medusa-dev\build>mingw32-make >d
mingw32-make[2]: *** [deps/ogdf/CMakeFiles/ogdf.dir/depend] Interrupt
mingw32-make[1]: *** [deps/ogdf/CMakeFiles/ogdf.dir/all] Error 130
mingw32-make: *** [all] Error 130

D:\medusa-dev\build>mingw32-make >d
D:\medusa-dev\src\core\windows_binary_stream.cpp:
In constructor 'medusa::FileBinaryStream::FileBinaryStream(const boost::filesyst
em::path&)':
D:\medusa-dev\src\core\windows_binary_stream.cpp:2
5:22: error: invalid conversion from 'HANDLE {aka void*}' to 'medusa::TFileHandl
e {aka int}' [-fpermissive]
 , m_MapHandle(nullptr)
                      ^
D:\medusa-dev\src\core\windows_binary_stream.cpp:
In member function 'void medusa::FileBinaryStream::Open(const boost::filesystem:
:path&)':
D:\medusa-dev\src\core\windows_binary_stream.cpp:4
1:16: error: invalid conversion from 'HANDLE {aka void*}' to 'medusa::TFileHandl
e {aka int}' [-fpermissive]
   m_FileHandle = INVALID_HANDLE_VALUE;
                ^
D:\medusa-dev\src\core\windows_binary_stream.cpp:5
3:7: error: invalid conversion from 'HANDLE {aka void*}' to 'medusa::TFileHandle
 {aka int}' [-fpermissive]
       );
       ^
In file included from D:/mingw32/i686-w64-mingw32/
include/winbase.h:19:0,
                 from D:/mingw32/i686-w64-mingw32/
include/Windows.h:70,
                 from D:\medusa-dev\src\core\windo
ws_binary_stream.cpp:3:
D:\medusa-dev\src\core\windows_binary_stream.cpp:5
5:23: error: ISO C++ forbids comparison between pointer and integer [-fpermissiv
e]
   if (m_FileHandle == INVALID_HANDLE_VALUE)
                       ^
D:\medusa-dev\src\core\windows_binary_stream.cpp:6
0:44: error: invalid conversion from 'medusa::TFileHandle {aka int}' to 'HANDLE
{aka void*}' [-fpermissive]
   if (GetFileSizeEx(m_FileHandle, &FileSize) == FALSE)
                                            ^
In file included from D:/mingw32/i686-w64-mingw32/
include/winbase.h:18:0,
                 from D:/mingw32/i686-w64-mingw32/
include/Windows.h:70,
                 from D:\medusa-dev\src\core\windo
ws_binary_stream.cpp:3:
D:/mingw32/i686-w64-mingw32/include/fileapi.h:67:2
9: note: initializing argument 1 of 'WINBOOL GetFileSizeEx(HANDLE, PLARGE_INTEGE
R)'
   WINBASEAPI WINBOOL WINAPI GetFileSizeEx (HANDLE hFile, PLARGE_INTEGER lpFileS
ize);
                             ^
D:\medusa-dev\src\core\windows_binary_stream.cpp:7
2:7: error: invalid conversion from 'medusa::TFileHandle {aka int}' to 'HANDLE {
aka void*}' [-fpermissive]
       );
       ^
In file included from D:/mingw32/i686-w64-mingw32/
include/winbase.h:25:0,
                 from D:/mingw32/i686-w64-mingw32/
include/Windows.h:70,
                 from D:\medusa-dev\src\core\windo
ws_binary_stream.cpp:3:
D:/mingw32/i686-w64-mingw32/include/memoryapi.h:63
:28: note: initializing argument 1 of 'void* CreateFileMappingW(HANDLE, LPSECURI
TY_ATTRIBUTES, DWORD, DWORD, DWORD, LPCWSTR)'
   WINBASEAPI HANDLE WINAPI CreateFileMappingW (HANDLE hFile, LPSECURITY_ATTRIBU
TES lpFileMappingAttributes, DWORD flProtect, DWORD dwMaximumSizeHigh, DWORD dwM
aximumSizeLow, LPCWSTR lpName);
                            ^
In file included from D:/mingw32/i686-w64-mingw32/
include/winbase.h:19:0,
                 from D:/mingw32/i686-w64-mingw32/
include/Windows.h:70,
                 from D:\medusa-dev\src\core\windo
ws_binary_stream.cpp:3:
D:\medusa-dev\src\core\windows_binary_stream.cpp:
In member function 'void medusa::FileBinaryStream::Close()':
D:\medusa-dev\src\core\windows_binary_stream.cpp:1
00:23: error: ISO C++ forbids comparison between pointer and integer [-fpermissi
ve]
   if (m_FileHandle != INVALID_HANDLE_VALUE)
                       ^
D:\medusa-dev\src\core\windows_binary_stream.cpp:1
02:29: error: invalid conversion from 'medusa::TFileHandle {aka int}' to 'HANDLE
 {aka void*}' [-fpermissive]
     CloseHandle(m_FileHandle);
                             ^
In file included from D:/mingw32/i686-w64-mingw32/
include/winbase.h:19:0,
                 from D:/mingw32/i686-w64-mingw32/
include/Windows.h:70,
                 from D:\medusa-dev\src\core\windo
ws_binary_stream.cpp:3:
D:/mingw32/i686-w64-mingw32/include/handleapi.h:19
:29: note: initializing argument 1 of 'WINBOOL CloseHandle(HANDLE)'
   WINBASEAPI WINBOOL WINAPI CloseHandle (HANDLE hObject);
                             ^
D:\medusa-dev\src\core\windows_binary_stream.cpp:1
03:18: error: invalid conversion from 'HANDLE {aka void*}' to 'medusa::TFileHand
le {aka int}' [-fpermissive]
     m_FileHandle = INVALID_HANDLE_VALUE;
                  ^
D:\medusa-dev\src\core\windows_binary_stream.cpp:
In member function 'void medusa::MemoryBinaryStream::Open(const void*, medusa::u
32)':
D:\medusa-dev\src\core\windows_binary_stream.cpp:1
24:12: error: 'unique_path' is not a member of 'boost::filesystem'
   m_Path = boost::filesystem::unique_path();
            ^
mingw32-make[2]: *** [src/core/CMakeFiles/Medusa.dir/windows_binary_stream.cpp.o
bj] Error 1
mingw32-make[1]: *** [src/core/CMakeFiles/Medusa.dir/all] Error 2
mingw32-make: *** [all] Error 2
wisk commented 9 years ago

I never tried to compile Medusa with mingw, actually I don't use mingw at all, so I don't have any experience for this kind of issue. Could you make sure WIN32 is defined? If you manage to compile it with mingw, I will gladly add your patch.

ghost commented 9 years ago

changing WIN32 to #if defined WIN32 || defined _WIN32 || defined __CYGWIN__ in types.hpp works fine, but I got another problem std::this_thread::sleep_for mingw implementation using their lastest stable windows header is broken. nanosleep function is not defined. Someone says c++config.h had defined _GLIBCXX_USE_NANOSLEEP to 1 which is not available for non posix system. I'll post another progress

ghost commented 9 years ago

my final patch, sorry Im paste-ing here since I never work with git here before

--- medusa-dev\inc\medusa\binary_stream.hpp 2015-02-23 19:12:44 +0700
+++ medusa-dev1\medusa-dev\inc\medusa\binary_stream.hpp 2015-02-16 05:22:35 +0700
@@ -14,7 +14,6 @@

 #include <boost/type_traits.hpp>
 #include <boost/filesystem/path.hpp>
-#include <boost/filesystem/operations.hpp>

 MEDUSA_NAMESPACE_BEGIN

--- medusa-dev\src\core\windows_module.cpp  2015-02-24 05:28:33 +0700
+++ medusa-dev1\medusa-dev\src\core\windows_module.cpp  2015-02-16 05:22:35 +0700
@@ -31,15 +31,10 @@

   return pModule;
 }
-#ifdef __MINGW32__
-FARPROC WINAPI Module::ImplGetFunctionAddress(void* pModule, std::string const& FunctionName)
-{
-  return GetProcAddress(static_cast<HMODULE>(pModule), FunctionName.c_str());
-}
-#else
-void * Module::ImplGetFunctionAddress(void* pModule, std::string const& FunctionName)
+
+void* Module::ImplGetFunctionAddress(void* pModule, std::string const& FunctionName)
 {
   return GetProcAddress(static_cast<HMODULE>(pModule), FunctionName.c_str());
 }
-#endif
+
 MEDUSA_NAMESPACE_END
\ No newline at end of file
--- medusa-dev\inc\medusa\module.hpp    2015-02-24 05:30:31 +0700
+++ medusa-dev1\medusa-dev\inc\medusa\module.hpp    2015-02-16 05:22:35 +0700
@@ -48,11 +48,8 @@
   typedef std::map< boost::filesystem::path, void* > TModuleMap;

   void* ImplLoadLibrary(boost::filesystem::path const& LibraryPath);
-#ifdef __MINGW32__
-  FARPROC WINAPI ImplGetFunctionAddress(void* pModule, std::string const& FunctionName);
-#else 
-void * ImplGetFunctionAddress(void* pModule, std::string const& FunctionName);
-#endif
+  void* ImplGetFunctionAddress(void* pModule, std::string const& FunctionName);
+
   TModuleMap m_ModuleMap;
 };

--- medusa-dev\inc\medusa\module.hpp    2015-02-24 05:30:31 +0700
+++ medusa-dev1\medusa-dev\inc\medusa\module.hpp    2015-02-16 05:22:35 +0700
@@ -48,11 +48,8 @@
   typedef std::map< boost::filesystem::path, void* > TModuleMap;

   void* ImplLoadLibrary(boost::filesystem::path const& LibraryPath);
-#ifdef __MINGW32__
-  FARPROC WINAPI ImplGetFunctionAddress(void* pModule, std::string const& FunctionName);
-#else 
-void * ImplGetFunctionAddress(void* pModule, std::string const& FunctionName);
-#endif
+  void* ImplGetFunctionAddress(void* pModule, std::string const& FunctionName);
+
   TModuleMap m_ModuleMap;
 };
ghost commented 9 years ago

I have the question,why when doing the dissasembly graph(Ctrl+f), edge vertex color appears to slow?is there delay or something else ?

wisk commented 9 years ago

Thanks for the patch, I'll apply it ASAP. :) Regarding the question, it would be better if you can make a new issue for it. Anyway, the CFG view may appear to be slow because it has to compute the layout of the graph (using OGDF), the problem is this computation is made by the main thread (i.e. the GUI thread) which blocks the entire interface. I think it could be fixed by doing this computation in a asynchronous way (QThread?). Thanks for reporting though!

ghost commented 9 years ago

Like this one you mean?

QMetaObject::invokeMethod(thread, "quit",
                          Qt::QueuedConnection);

Im not familiar with OGDF, but I will see firstly

wisk commented 9 years ago

Hello kangjoni76,

I tried to compiled medusa with MinGW using your patch and I get stuck with coin library:

error: #error "Trying to use configall_system for unknown compiler."
# error "Trying to use configall_system for unknown compiler."
   ^

Did you have the same issue?

ghost commented 9 years ago

Sorry for late answer, I was busy another jobs. No, I didnt, I built fine. Let me clarify this

  1. In types.hpp WIN32 should be changed to something like #if defined WIN32 || defined _WIN32 || defined __CYGWIN__ || __MINGW32__
  2. In boost version 1.57 we need to include additional header #include <boost/filesystem/operations.hpp> to binary_stream.hpp
  3. In windows_module.cpp, mingw got stucked couldnt resolve type void * of FARPROC nasty C callback. As temporary workaround we need to change some statements to something like
#ifdef __MINGW32__
FARPROC WINAPI Module::ImplGetFunctionAddress(void* pModule, std::string const& FunctionName)
{
  return GetProcAddress(static_cast<HMODULE>(pModule), FunctionName.c_str());
}
#else
void * Module::ImplGetFunctionAddress(void* pModule, std::string const& FunctionName)

void* Module::ImplGetFunctionAddress(void* pModule, std::string const& FunctionName)
 {
   return GetProcAddress(static_cast<HMODULE>(pModule), FunctionName.c_str());
 }
#endif

this also should be adjusted to module.hpp for the interface declaration.

And lastly in the c++config.h in mingw 4.9 distribution posix thread _GLIBCXX_USE_NANOSLEEP should be commented Those all working fine for me.

wisk commented 9 years ago

No problem, I'm also busy these days. :) I trust you on this one since I'm still unable to make mingw to compile Medusa, too bad the last patch requires to patch a c++config.h. The commit is https://github.com/wisk/medusa/commit/2f121349f3a2796b6874f62da39a17427b199dbc, please tell me if it's good for you.

Thanks for sharing!

ghost commented 9 years ago

in module.hpp this statement should be changed
FARPROC WINAPI Module::ImplGetFunctionAddress(void* pModule, std::string const& FunctionName) to FARPROC WINAPI ImplGetFunctionAddress(void* pModule, std::string const& FunctionName) and viola yey.. :dancers:

wisk commented 8 years ago

Hi,

This change was made some time ago, I close the issue now. If you still have this issue, feel free to re-open this issue. If you experience another issue when compiling with mingw (which I do not use), please create a new issue.

Thanks.