Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue building binary under Linux #22

Open
greenozon opened this issue Nov 1, 2024 · 11 comments
Open

Issue building binary under Linux #22

greenozon opened this issue Nov 1, 2024 · 11 comments

Comments

@greenozon
Copy link

For some reason I"m not able to build hollow-hunter on Ubuntu using mingw toolchain

issue:

./mingw_build.sh
....

[ 86%] Linking CXX static library libpe-sieve.a
[ 86%] Built target pe-sieve
[ 88%] Building CXX object CMakeFiles/hollows_hunter.dir/main.cpp.obj
In file included from /home/usr/Downloads/gh/hollows_hunter/params_info/params.h:10,
                 from /home/usr/Downloads/gh/hollows_hunter/main.cpp:25:
/home/usr/Downloads/gh/hollows_hunter/params_info/../term_util.h:7:13: error: ‘mutex’ in namespace ‘std’ does not name a type
    7 | extern std::mutex g_stdOutMutex;
      |             ^~~~~
/home/usr/Downloads/gh/hollows_hunter/params_info/../term_util.h:4:1: note: ‘std::mutex’ is defined in header ‘<mutex>’; did you forget to ‘#include <mutex>’?
    3 | #include <mutex>
  +++ |+#include <mutex>
    4 | #include <iostream>
make[2]: *** [CMakeFiles/hollows_hunter.dir/build.make:76: CMakeFiles/hollows_hunter.dir/main.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:154: CMakeFiles/hollows_hunter.dir/all] Error 2
make: *** [Makefile:146: all] Error 2


some sys info

uname -a
Linux tpo347 5.15.0-124-generic #134-Ubuntu SMP Fri Sep 27 20:20:17 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/issue
Ubuntu 22.04.5 LTS \n \l

x86_64-w64-mingw32-g++ --version
x86_64-w64-mingw32-g++ (GCC) 10-win32 20220113
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@greenozon
Copy link
Author

at the same time pe-sieve builds just fine using similar mingw_build.sh script

file ./pe-sieve.exe 
./pe-sieve.exe: PE32+ executable (console) x86-64, for MS Windows


@hasherezade
Copy link
Owner

I added the mutex header explicitly to main.cpp - please check it out and let me know if it helps.
And regarding:

and another issue - I see tons of warnings and you pic is super clean, is it from Windows?

I compiled it on Linux. And yes, indeed there are lot of warnings, all about the same thing: warning: converting to non-pointer type ‘ULONGLONG’ {aka ‘long long unsigned int’} from NULL - I will fix it eventually, but it is a low priority.

@greenozon
Copy link
Author

thanks! very kind of you
I'll check it out shortly

regarding warning you are right! but also lots of other nasty one -

gh/hollows_hunter/pe-sieve/libpeconv/libpeconv/src/imports_loader.cpp:348:45: warning: NULL used in arithmetic [-Wpointer-arith]
  348 |         if (lib_desc->OriginalFirstThunk == NULL && lib_desc->FirstThunk == NULL) {

do you think it would work if use nullptr instead of NULL?
or maybe even boolean logic like using not (!) operator?

the ultimate goal is to drop down the warnings from current to say 2-3 max 5!

lets make it happen?
if you busy I could create some PR...

@greenozon
Copy link
Author

Update on adding
#include into main.cpp -> issue still exists

PS you already had got the include macros for in term_util.h
so I believe adding one more won't help here...
do you think it's up to some Linux specific, eg mingw does not support mutex under Linux for some reason? (sounds crazy but who knows..)

@greenozon
Copy link
Author

I guess you also need to add into https://github.com/hasherezade/hollows_hunter/blob/master/CMakeLists.txt
the define for minimal windows version 0x600

        add_compile_definitions(
                _WIN32_WINNT=1536 # 0x600 aka Windows Vista required
        )

otherwise some modern winapi won't be recognized, eg: QueryFullProcessImageNameW

@hasherezade
Copy link
Owner

Update on adding #include into main.cpp -> issue still exists

PS you already had got the include macros for in term_util.h so I believe adding one more won't help here... do you think it's up to some Linux specific, eg mingw does not support mutex under Linux for some reason? (sounds crazy but who knows..)

Yes, I saw the previous include, and initially thought it should be sufficient, but still gave it a try and added the extra one. I am not sure what the cause because even the error that you've got looks weird - it literally suggest you to add include <mutex> after the mutex that is already there?

home/usr/Downloads/gh/hollows_hunter/params_info/../term_util.h:4:1: note: ‘std::mutex’ is defined in header ‘<mutex>’; did you forget to ‘#include <mutex>’?
    3 | #include <mutex>
  +++ |+#include <mutex>
    4 | #include <iostream>

I cannot reproduce it, on my machine it builds fine - it is Linux Ubuntu (24.04).

@hasherezade
Copy link
Owner

I guess you also need to add into https://github.com/hasherezade/hollows_hunter/blob/master/CMakeLists.txt the define for minimal windows version 0x600

        add_compile_definitions(
                _WIN32_WINNT=1536 # 0x600 aka Windows Vista required
        )

otherwise some modern winapi won't be recognized, eg: QueryFullProcessImageNameW

This is a good point, I will add it.

@greenozon
Copy link
Author

greenozon commented Nov 1, 2024

I cannot reproduce it, on my machine it builds fine - it is Linux Ubuntu (24.04).

what is your compiler version?

mine is a bit older I guess

x86_64-w64-mingw32-g++ -v
Using built-in specs.
COLLECT_GCC=x86_64-w64-mingw32-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-w64-mingw32/10-posix/lto-wrapper
Target: x86_64-w64-mingw32
Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --disable-option-checking --disable-silent-rules --libdir='/usr/lib/x86_64-linux-gnu' --libexecdir='/usr/lib/x86_64-linux-gnu' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --with-headers --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-lto --enable-threads=posix --program-suffix=-posix --program-prefix=x86_64-w64-mingw32- --target=x86_64-w64-mingw32 --with-as=/usr/bin/x86_64-w64-mingw32-as --with-ld=/usr/bin/x86_64-w64-mingw32-ld --enable-libatomic --enable-libstdcxx-filesystem-ts=yes --enable-dependency-tracking SED=/bin/sed
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10-posix 20220113 (GCC) 

@greenozon
Copy link
Author

greenozon commented Nov 1, 2024

I've googled some info about std::mutex in mingw under Linux...
sadly it has limitations, but luckily there are steps to overcome it

fix:
Make sure MinGW-w64 uses the posix threading model.
if you see win32 instead of posix then one need to

sudo apt install g++-mingw-w64-x86-64-posix
and
sudo update-alternatives --config x86_64-w64-mingw32-g++
and select posix in the list

eg: (note the * symbol)

sudo update-alternatives --config x86_64-w64-mingw32-g++ 
There are 2 choices for the alternative x86_64-w64-mingw32-g++ (providing /usr/bin/x86_64-w64-mingw32-g++).

  Selection    Path                                   Priority   Status
------------------------------------------------------------
  0            /usr/bin/x86_64-w64-mingw32-g++-win32   60        auto mode
* 1            /usr/bin/x86_64-w64-mingw32-g++-posix   30        manual mode
  2            /usr/bin/x86_64-w64-mingw32-g++-win32   60        manual mode

Press <enter> to keep the current choice[*], or type selection number: 

@greenozon
Copy link
Author

if you have gcc13 there is a high chance you don't need above change!

https://gcc.gnu.org/gcc-13/changes.html

ref to WIndows section updates

@hasherezade
Copy link
Owner

if you have gcc13 there is a high chance you don't need above change!

https://gcc.gnu.org/gcc-13/changes.html

ref to WIndows section updates

I have GCC 13.2.0 - matching what you found. So updating it should be enough, I am gonna leave this part as is. Maybe just a note in README will be sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants