acl-dev / acl

C/C++ server and network library, including coroutine,redis client,http/https/websocket,mqtt, mysql/postgresql/sqlite client with C/C++ for Linux, Android, iOS, MacOS, Windows, etc..
https://acl-dev.cn
GNU Lesser General Public License v3.0
2.88k stars 936 forks source link

Unable to compile on windows using MSYS2 or MINGW and throws Linux header file error #286

Closed BT185070 closed 2 years ago

BT185070 commented 2 years ago

Trying to build the libraries on windows using MSYS2 or MINGW64 terminals.

Installed all the dependencies on MSYS2 and MINGW64 but still no luck.

Below is the error I am facing when compiling

-># make building src/init/acl_init.c building src/private/private_array.c building src/private/private_fifo.c building src/private/private_thread_mutex.c building src/private/private_vstream.c building src/private/sem.c building src/stdlib/acl_atomic.c building src/stdlib/acl_chunk_chain.c building src/stdlib/acl_debug.c building src/stdlib/acl_file.c building src/stdlib/acl_getopt.c building src/stdlib/acl_mbox.c building src/stdlib/acl_mbox.c src/stdlib/acl_mbox.c:19:11: fatal error: linux/version.h: No such file or directory 19 | # include <linux/version.h> | ^~~~~

am I doing it right to compile the libraries on windows using MSYS2? Can you please shed some light on how to compile the libraries on windows using MSYS2 or MINGW64?

zhengshuxin commented 2 years ago

I'v just fixed this problem add adding "MINGW" macro in acl_mbox in order to support MSYS2 on Windows platform.

BT185070 commented 2 years ago

@zhengshuxin Found cast error this time

-> # make building src/init/acl_init.c building src/private/private_array.c building src/private/private_fifo.c building src/private/private_thread_mutex.c building src/private/private_vstream.c building src/private/sem.c building src/stdlib/acl_atomic.c building src/stdlib/acl_chunk_chain.c building src/stdlib/acl_debug.c building src/stdlib/acl_file.c building src/stdlib/acl_getopt.c building src/stdlib/acl_mbox.c building src/stdlib/acl_meter_time.c building src/stdlib/acl_msg.c building src/stdlib/acl_myflock.c building src/stdlib/acl_mylog.c src/stdlib/acl_mylog.c: In function ‘file_vsyslog’: src/stdlib/acl_mylog.c:818:25: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast] 818 | (unsigned int) acl_pthread_self(), info); | ^ src/stdlib/acl_mylog.c: In function ‘net_vsyslog’: src/stdlib/acl_mylog.c:869:25: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast] 869 | (unsigned int) acl_pthread_self(), info); | ^ cc1: all warnings being treated as errors make: *** [Makefile:395: debug/acl_mylog.o] Error 1

BT185070 commented 2 years ago

Added the below conversion instead of (unsigned int) to resolve the above cast error (unsigned long long int) acl_pthread_self()

BT185070 commented 2 years ago

Found another error in MSYS2 compilation. Please help to resolve this.

src/master/template/ifmonitor.c:10:10: fatal error: linux/netlink.h: No such file or directory 10 | #include <linux/netlink.h> | ^~~~~ compilation terminated. make: *** [Makefile:527: debug/ifmonitor.o] Error 1

BT185070 commented 2 years ago

Added "MINGW" macro in ifmonitor as well in order to support MSYS2 on Windows platform.

zhengshuxin commented 2 years ago

I downloaded and installed msys2-x86_64-20220603.exe, and got one error " #error Only Win32 target is supported!" that I don't know why. How did you make your msys2 working well?

BT185070 commented 2 years ago

I am using the msys2 console to compile the code.

zhengshuxin commented 2 years ago

Which version msys2 are you using? And can you tell me the process of installing msys2? I've spent many times according the msys2's official guidance, but got the same error.

BT185070 commented 2 years ago

image

I followed the below steps,

  1. Installing MSYS2
  2. Installed the development packages
  3. executing make from the respective project folder.
zhengshuxin commented 2 years ago

I've tried many times to install msys2, but still can't compile acl with gcc. The installing steps are below:

  1. Download from url: https://github.com/msys2/msys2-installer/releases/download/2022-06-03/msys2-x86_64-20220603.exe
  2. Install msys2-x86_64-20220603.exe
  3. Run "MSYS2 MSYS" from Start menu
  4. $pacman -Syu
  5. Run "MSYS2 MSYS" from Start menu again
  6. $pacman -Syu
  7. pacman -S --needed base-devel mingw-w64-x86_64-toolchain
  8. Download acl and enter acl/lib_acl, type make, and got below:
    $ make
    building src/init/acl_init.c
    In file included from D:/msys64/mingw64/include/corecrt.h:10,
                 from D:/msys64/mingw64/include/crtdefs.h:10,
                 from D:/msys64/mingw64/include/stddef.h:7,
                 from D:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/12.1.0/include/stddef.h:1,
                 from ./include/stdlib/acl_define_linux.h:18,
                 from ./include/stdlib/acl_define_unix.h:4,
                 from ./include/stdlib/acl_define.h:10,
                 from ./StdAfx.h:6,
                 from src/init/acl_init.c:1:
    D:/msys64/mingw64/include/_mingw.h:278:2: error: #error Only Win32 target is supported!
    278 | #error Only Win32 target is supported!
      |  ^~~~~
    ./include/stdlib/acl_define_linux.h:62:18: error: conflicting types for 'ssize_t'; have 'long int'
    62 | typedef long int ssize_t;
      |                  ^~~~~~~
    D:/msys64/mingw64/include/corecrt.h:47:13: note: previous declaration of 'ssize_t' with type 'ssize_t' {aka 'int'}
    47 | typedef int ssize_t;
      |             ^~~~~~~
    In file included from ./include/stdlib/acl_define_unix.h:42:
    D:/msys64/mingw64/include/sys/types.h:10:2: error: #error Only Win32 target is supported!
    10 | #error Only Win32 target is supported!
      |  ^~~~~
    ./include/stdlib/acl_define_unix.h:43:11: fatal error: net/if.h: No such file or directory
    43 | # include <net/if.h>
      |           ^~~~~~~~~~
    compilation terminated.
    make: *** [Makefile:385: debug/acl_init.o] Error 1

    I've tried different msys2 versions, but got the same error. The install process is from the official website. Are there some differences between us? And can you give me the installing process with more details?

BT185070 commented 2 years ago

image

This is the folder structure I have. I have followed the same steps you mentioned. But I have opened mysys2.exe from the folder directly.

zhengshuxin commented 2 years ago

But gcc/g++ are not in mysys2.exe, and they're in mingw64.exe. Are you sure you can run gcc in mysys2.exe? I'll try the older version of mysys2 or cygwin later.

BT185070 commented 2 years ago

I have installed those packages using mysys2.exe. Try the same.

zhengshuxin commented 2 years ago

Yes, I also did it same as you: install those packages in mysys2.exe and run gcc/g++ in mingw64.exe, because gcc/g++ aren't in mysys2.exe.

zhengshuxin commented 2 years ago

I've downloaded Cygwin and built acl ok now, so I think acl should also be built ok on msys2. You can try again.

BT185070 commented 2 years ago

I able to compile using Msys2 now. I have tried compilation on QT mingw today. But facing the below error

image

zhengshuxin commented 2 years ago

You can add cflags += -DMINGW in your Makefile including acl's headers.

BT185070 commented 2 years ago

Gives the same error even after adding the CFLAG

zhengshuxin commented 2 years ago

You can try to compile the demo in acl/lib_acl/samples/vstream_server, if successfully, you can refer the Makefile.in acl/lib_acl/samples/.