n2n icon indicating copy to clipboard operation
n2n copied to clipboard

Dev branch for windows MINGW build not well support extra library build

Open GreatMichaelLee opened this issue 1 year ago • 7 comments

as title, currnet dev build which using MINGW on the windows build, it is not support to specify the extra library compile flag which used like on linux build e.g --enable-natmap --enable-miniupnpc etc.

This seems will block those features applicable on windows.

GreatMichaelLee avatar May 11 '23 06:05 GreatMichaelLee

These features are still available, just not in a simple and integrated fashion. Until this integration has been improved, if you want to both follow the development branch and use these features on windows, you can use something like the following workaround:

cd n2n

git submodule update --init

./scripts/hack_fakeautoconf.sh

export CC=gcc

cd thirdparty/libnatpmp
sed -i -E -e 's/(CC = i686-w64-mingw32-gcc)/#\1/' Makefile
sed -i -E -e '3a#define NATPMP_STATICLIB 1' natpmp_declspec.h
make libnatpmp.a
cd ../..

cd thirdparty/miniupnp/miniupnpc
sed -i -E -e '3a#define MINIUPNP_STATICLIB 1' include/miniupnpc_declspec.h
make -f Makefile.mingw libminiupnpc.a
cp -a include miniupnpc
cd ../../../

echo "#define HAVE_NATPMP 1" >>include/config.h
echo 'LDLIBS_EXTRA+=-lnatpmp' >>config.mak
echo 'CFLAGS+=-I$(realpath thirdparty/libnatpmp/)' >>config.mak
echo 'LDFLAGS+=-L$(realpath thirdparty/libnatpmp/)' >>config.mak

echo "#define HAVE_MINIUPNP 1" >>include/config.h
echo 'LDLIBS_EXTRA+=-lminiupnpc' >>config.mak
echo 'CFLAGS+=-I$(realpath thirdparty/miniupnp/miniupnpc/)' >>config.mak
echo 'LDFLAGS+=-L$(realpath thirdparty/miniupnp/miniupnpc/)' >>config.mak

make

hamishcoleman avatar May 11 '23 07:05 hamishcoleman

OK.Got.I will have a try. Thank you.Looking forward to a simplified integration build way

---Original--- From: "Hamish @.> Date: Thu, May 11, 2023 15:27 PM To: @.>; Cc: "michael @.@.>; Subject: Re: [ntop/n2n] Dev branch for windows MINGW build not well supportextra library build (Issue #1110)

These features are still available, just not in a simple and integrated fashion. Until this integration has been improved, if you want to both follow the development branch and use these features on windows, you can use something like the following workaround: cd n2n git submodule update --init ./scripts/hack_fakeautoconf.sh export CC=gcc cd thirdparty/libnatpmp sed -i -E -e 's/(CC = i686-w64-mingw32-gcc)/#\1/' Makefile sed -i -E -e '3a#define NATPMP_STATICLIB 1' natpmp_declspec.h make libnatpmp.a cd ../.. cd thirdparty/miniupnp/miniupnpc sed -i -E -e '3a#define MINIUPNP_STATICLIB 1' include/miniupnpc_declspec.h make -f Makefile.mingw libminiupnpc.a cp -a include miniupnpc cd ../../../ echo "#define HAVE_NATPMP 1" >>include/config.h echo 'LDLIBS_EXTRA+=-lnatpmp' >>config.mak echo 'CFLAGS+=-I$(realpath thirdparty/libnatpmp/)' >>config.mak echo 'LDFLAGS+=-L$(realpath thirdparty/libnatpmp/)' >>config.mak echo "#define HAVE_MINIUPNP 1" >>include/config.h echo 'LDLIBS_EXTRA+=-lminiupnpc' >>config.mak echo 'CFLAGS+=-I$(realpath thirdparty/miniupnp/miniupnpc/)' >>config.mak echo 'LDFLAGS+=-L$(realpath thirdparty/miniupnp/miniupnpc/)' >>config.mak make
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

GreatMichaelLee avatar May 11 '23 09:05 GreatMichaelLee

I have tested your steps, looks good. thanks. maybe you can make it in a build script and integrated it.

GreatMichaelLee avatar May 14 '23 08:05 GreatMichaelLee

I have tested your steps, looks good. thanks. maybe you can make it in a build script and integrated it.

Have we gotta any further steps on this? thanks.

GreatMichaelLee avatar Jun 23 '23 05:06 GreatMichaelLee

That's... eww.

CMake anyone?

sduensin avatar Sep 23 '23 00:09 sduensin

Yes, this is eww - it was never supposed to be anything else, and the long term goal is to have an answer for this before the next stable release.

We used to have cmake, but it made debugging harder, optimisation almost impossible, multi-architecture/multi-os support inscrutible and worst of all - when things broke, the maintainers didnt want to have to deal with cmake.

hamishcoleman avatar Sep 23 '23 09:09 hamishcoleman

But cross-compiling is what CMake is good at! All you need is a simple toolchain file. For example:

set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

set(triple x86_64-w64-mingw32)

set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc-10-posix)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-c++-posix)
set(CMAKE_CXX_COMPILER_TARGET ${triple})

I feed that to cmake along with the CMakeList and out pops a Windows build from my Linux box. Seeing as how the two NAT libraries N2N uses already use CMake, it wouldn't be hard to tie it all together into a single build.

I know CMake is ... odd. But AutoTools? Egads! :grinning:

sduensin avatar Sep 23 '23 22:09 sduensin