Windows下使用MinGW+Cmake编译n2n

N2N, Windows, 折腾 2018/08/23

此文已过于陈旧,不推荐使用此版本N2N

记录下windows下MinGW+cmake的使用方法,以Win7 32位下编译n2n为例。

一、安装cmake

1.下载并解压

https://cmake.org/download/,以压缩包版为例

解压到任意目录,如解压到C盘根目录:

2.设置环境变量

在环境变量Path的尾部增加 ;C:\cmake-3.12.1-win32-x86\bin 注意路径和前面的分号

重启,打开CMD,输入 cmake,检查是否链接成功

二、安装MinGW

1.下载安装器

https://sourceforge.net/projects/mingw/files/latest/download

运行并指定安装目录后,便会开始在线下载安装器的文件,耐心等待

选择需要下载的包,因为是编译n2n,只需要选择基本的环境包,依然是耐心等待

2.测试

运行 C:\MinGW\msys\1.0\msys.bat 进入命令行窗口

三、开始编译

将下载的n2n源码放至任意文件夹,比如C盘根目 C:\n2n\n2n_v2

依次运行

cd /c/n2n/n2n_v2/
mkdir build
cd build
cmake -G "MSYS Makefiles" --build ./ ../
make

配置成功,执行 make 进行编译,出错,提示wintap.c 的 213行 ERROR_IO_PENDING 未定义

修改win32目录下的wintap.c,头部加入定义

#define ERROR_IO_PENDING 997

再次执行 make 编译

错误已解决,成功编译出可执行文件

本文标签:


6条评论

  • vcan 评论于 回复

    $ cmake -G “MSYS Makefiles” –build ./ ../
    — The C compiler identification is GNU 6.3.0
    — The CXX compiler identification is GNU 6.3.0
    — Check for working C compiler: C:/MinGW/bin/gcc.exe
    — Check for working C compiler: C:/MinGW/bin/gcc.exe — works
    — Detecting C compiler ABI info
    — Detecting C compiler ABI info – done
    — Detecting C compile features
    — Detecting C compile features – done
    — Check for working CXX compiler: C:/MinGW/bin/g++.exe
    — Check for working CXX compiler: C:/MinGW/bin/g++.exe — works
    — Detecting CXX compiler ABI info
    — Detecting CXX compiler ABI info – done
    — Detecting CXX compile features
    — Detecting CXX compile features – done
    CMake Error at C:/Program Files/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
    Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
    system variable OPENSSL_ROOT_DIR (missing: OPENSSL_INCLUDE_DIR)
    Call Stack (most recent call first):
    C:/Program Files/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
    C:/Program Files/CMake/share/cmake-3.13/Modules/FindOpenSSL.cmake:412 (find_package_handle_standard_args)
    CMakeLists.txt:16 (find_package)

    请问下这个要怎么处理 :惊讶:

    • lucktu 评论于 回复

      @vcan
      Could NOT find OpenSSL — 提示你 OpenSSL 没有找到啊,没安装或没链接好

  • lucktu 评论于 回复

    学习了,我也会编 n2n-v1、2 了,多谢!!
    请问“#define ERROR_IO_PENDING 997”,这句是什么意思呢?
    先谢谢了!!

    • Bug侠 评论于 回复

      @lucktu
      我一直用Win10下的VS编译,但是换到Win7下再安装VS就太费事了,所以就了解了一下mingw+cmake。
      =======================
      翻阅他的代码,会看到wintap.c的第213行和243行有case ERROR_IO_PENDING语句,但是没有定义ERROR_IO_PENDING是什么,属于写代码不规范吧 :汗:
      错误定义微软官方有说明:
      https://docs.microsoft.com/en-us/windows/desktop/debug/system-error-codes–500-999-

    评论(本站已开启评论回复邮件通知功能,请如实填写邮箱以便及时收到回复)关闭回复