hasherezade / libpeconv

A library to load, manipulate, dump PE files. See also: https://github.com/hasherezade/libpeconv_tpl
https://hasherezade.github.io/libpeconv
BSD 2-Clause "Simplified" License
1.07k stars 176 forks source link

Compiler error when building with MinGW (2) #21

Closed hillu closed 3 years ago

hillu commented 3 years ago

I found another reinterpret_cast<…>-related compile error when cross-building with x86_64-w64-mingw32-g++ (GCC) 8.3-win32 20190406:

$WORK/libpeconv/src/exports_lookup.cpp: In function ‘INT_PTR (* peconv::get_exported_func(PVOID, LPSTR))()’:
$WORK/libpeconv/src/exports_lookup.cpp:114:85: error: cast from ‘LPSTR’ {aka ‘char*’} to ‘DWORD’ {aka ‘long unsigned int’} loses precision [-fpermissive]
 return get_export_by_ord(modulePtr, exp, reinterpret_cast<DWORD>(wanted_name));
                                                                             ^

$WORK/libpeconv/src/exports_lookup.cpp: In member function ‘virtual INT_PTR (* peconv::export_based_resolver::resolve_func(LPSTR, LPSTR))()’:
$WORK/libpeconv/src/exports_lookup.cpp:158:96: error: cast from ‘LPSTR’ {aka ‘char*’} to ‘DWORD’ {aka ‘long unsigned int’} loses precision [-fpermissive]
 !] Cound not get the function: "<< reinterpret_cast<DWORD>(func_name) <<" from exports!" << std::endl;
hasherezade commented 3 years ago

ok, I fixed it. does it work now?

hillu commented 3 years ago

Yes. No more errors.

Here's the cmake spell I am currently using. (There has been quite a bit of trial&error involved.)

cd $build_dir && \
CC=$1-gcc CXX=$1-g++ CXXFLAGS=-D_WIN32_WINNT=_WIN32_WINNT_WIN7 cmake $src_dir \
        -DCMAKE_INSTALL_PREFIX=$arch_install_dir \
        -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
        -DCMAKE_CROSSCOMPILING=1 \
        -DCMAKE_SYSTEM_NAME=Windows \
        -DPECONV_BUILD_TESTING=0