当前位置:   article > 正文

Drogon Win11 编译 /MT_drogon 编译

drogon 编译

因为想着编译/MT版本,所以就手动编译了Drogon,记录下。

地址:Drogon

依赖库

  • 内置
    • trantor,non-blocking I/O C++网络库,也是作者开发,已作为git仓库submodule,无需提前安装;
  • 必须
    • jsoncpp,json的c++库,版本不低于1.7
    • libuuid,生成uuid的c库;
    • zlib,用于支持压缩传输;
  • 可选
    • boost,版本不低于1.61,只在C++编译器不支持c++17或STL库不完整支持std::filesystem时才需要安装;
    • OpenSSL,安装后drogon将支持HTTPS,否则drogon只支持HTTP;
    • c-ares, 安装后drogon对DNS的支持会具有更好的性能;
    • libbrotli,安装后drogon的HTTP响应会支持brotli压缩;
    • postgreSQL, mariadb, sqlite3的客户端开发库,安装后drogon会提供对相应的库的访问能力;
    • hiredis, 安装后drogon将支持redis的访问;
    • gtest, 安装后drogon的单元测试代码可以被编译;
    • yaml-cpp, 安装后drogon将支持yaml格式的配置文件;

准备工具:Cmake, Git, Visual Stutio, 

  • Windows 10(11) SDK
  • Cmake
  • Git
  • Visual Stutio 2022(2019)

先下载源码

  1. cd $WORK_PATH
  2. git clone https://github.com/drogonframework/drogon
  3. cd drogon
  4. git submodule update --init

依赖不用conan和vcpkg安装 自己编译 /MT版本

  1. git clone https://github.com/open-source-parsers/jsoncpp
  2. cd jsoncpp
  3. #修改CMakeLists.txt
  4. BUILD_SHARED_LIBS 改为OFF
  5. mkdir build
  6. cd build
  7. cmake -DCMAKE_BUILD_TYPE=Release ..

下面使用vs2022打开编译即可

  • zlib        地址:zlib
git clone -b master https://github.com/madler/zlib.git

使用Cmake也可以,直接使用vs2022新建工程将头文件添加库目录,将src添加进工程,选择库lib

代码生成选择/MT 编译即可。

  • boost  下载VC143 64位 预编译好的即可  地址:boost
  1. git clone https://github.com/c-ares/c-ares
  2. cd c-ares
  3. #修改CMakeLists.txt
  4. CARES_STATIC ON
  5. CARES_SHARED OFF
  6. mkdir build
  7. cd build
  8. cmake -DCMAKE_BUILD_TYPE=Release ..

使用vs2022打开编译即可

  1. git clone https://github.com/google/brotli
  2. cd brotli
  3. #修改CMakeLists.txt
  4. BUILD_SHARED_LIBS OFF
  5. mkdir build
  6. cd build
  7. cmake -DCMAKE_BUILD_TYPE=Release ..

使用vs2022打开编译即可

  • postgreSQL, mariadb

直接下载二进制安装文件,安装后头文件和库文件copy出来即可。

地址:postgresql  下载地址:postgresql-downloads   mariadb

  1. git clone https://github.com/redis/hiredis
  2. cd hiredis
  3. #修改CMakeLists.txt
  4. BUILD_SHARED_LIBS OFF
  5. mkdir build
  6. cd build
  7. cmake -DCMAKE_BUILD_TYPE=Release ..

使用vs2022打开编译即可 

注:预处理器 内容为

  1. %(PreprocessorDefinitions)
  2. WIN32
  3. _WINDOWS
  4. NDEBUG
  5. _CRT_SECURE_NO_WARNINGS
  6. WIN32_LEAN_AND_MEAN
  7. CMAKE_INTDIR="Release"
  8. hiredis_EXPORTS

下载版本为 Source Code 中的 sqlite-amalgamation 其中 sqlite-autoconf这个源码要tcl辅助编译。

源码共4个文件两个c文件两个头文件

新建工程,类型库文件lib 运行库/MT

将c文件添加至工程头文件添加库目录编译即可。

git clone https://github.com/jbeder/yaml-cpp

使用 cmake-gui打开

  • 只勾选下面2个即可,别的都不要勾选
    • YAML_CPP_BUILD_CONTRIB 
    • YAML_CPP_BUILD_TOOLS

生成工程文件后,使用vs2022打开编译即可

  1. git clone https://github.com/google/googletest
  2. cd googletest
  3. mkdir build
  4. cd build
  5. cmake -DCMAKE_BUILD_TYPE=Release ..

重头戏,开始编译Drogon

新建工程文件,分别添加三个项目

  • drogon  类型库文件lib
  • drogon_ctl 类型 应用程序exe
  • trantor 类型库文件lib

将源文件添加至对应的项目中,设置头文件引用库目录,添加链接器库文件编译。

本文源码目录如下

项目包含如下:

  • drogon

源文件

  1. <ItemGroup>
  2. <ClCompile Include="..\..\drogon\lib\src\AccessLogger.cc" />
  3. <ClCompile Include="..\..\drogon\lib\src\AOPAdvice.cc" />
  4. <ClCompile Include="..\..\drogon\lib\src\CacheFile.cc" />
  5. <ClCompile Include="..\..\drogon\lib\src\ConfigAdapterManager.cc" />
  6. <ClCompile Include="..\..\drogon\lib\src\ConfigLoader.cc" />
  7. <ClCompile Include="..\..\drogon\lib\src\Cookie.cc" />
  8. <ClCompile Include="..\..\drogon\lib\src\DrClassMap.cc" />
  9. <ClCompile Include="..\..\drogon\lib\src\drogon_test.cc" />
  10. <ClCompile Include="..\..\drogon\lib\src\DrTemplateBase.cc" />
  11. <ClCompile Include="..\..\drogon\lib\src\FiltersFunction.cc" />
  12. <ClCompile Include="..\..\drogon\lib\src\FixedWindowRateLimiter.cc" />
  13. <ClCompile Include="..\..\drogon\lib\src\GlobalFilters.cc" />
  14. <ClCompile Include="..\..\drogon\lib\src\Histogram.cc" />
  15. <ClCompile Include="..\..\drogon\lib\src\Hodor.cc" />
  16. <ClCompile Include="..\..\drogon\lib\src\HttpAppFrameworkImpl.cc" />
  17. <ClCompile Include="..\..\drogon\lib\src\HttpBinder.cc" />
  18. <ClCompile Include="..\..\drogon\lib\src\HttpClientImpl.cc" />
  19. <ClCompile Include="..\..\drogon\lib\src\HttpControllersRouter.cc" />
  20. <ClCompile Include="..\..\drogon\lib\src\HttpFileImpl.cc" />
  21. <ClCompile Include="..\..\drogon\lib\src\HttpFileUploadRequest.cc" />
  22. <ClCompile Include="..\..\drogon\lib\src\HttpRequestImpl.cc" />
  23. <ClCompile Include="..\..\drogon\lib\src\HttpRequestParser.cc" />
  24. <ClCompile Include="..\..\drogon\lib\src\HttpResponseImpl.cc" />
  25. <ClCompile Include="..\..\drogon\lib\src\HttpResponseParser.cc" />
  26. <ClCompile Include="..\..\drogon\lib\src\HttpServer.cc" />
  27. <ClCompile Include="..\..\drogon\lib\src\HttpSimpleControllersRouter.cc" />
  28. <ClCompile Include="..\..\drogon\lib\src\HttpUtils.cc" />
  29. <ClCompile Include="..\..\drogon\lib\src\HttpViewData.cc" />
  30. <ClCompile Include="..\..\drogon\lib\src\IntranetIpFilter.cc" />
  31. <ClCompile Include="..\..\drogon\lib\src\JsonConfigAdapter.cc" />
  32. <ClCompile Include="..\..\drogon\lib\src\ListenerManager.cc" />
  33. <ClCompile Include="..\..\drogon\lib\src\LocalHostFilter.cc" />
  34. <ClCompile Include="..\..\drogon\lib\src\MultiPart.cc" />
  35. <ClCompile Include="..\..\drogon\lib\src\NotFound.cc" />
  36. <ClCompile Include="..\..\drogon\lib\src\PluginsManager.cc" />
  37. <ClCompile Include="..\..\drogon\lib\src\PromExporter.cc" />
  38. <ClCompile Include="..\..\drogon\lib\src\RangeParser.cc" />
  39. <ClCompile Include="..\..\drogon\lib\src\RateLimiter.cc" />
  40. <ClCompile Include="..\..\drogon\lib\src\RealIpResolver.cc" />
  41. <ClCompile Include="..\..\drogon\lib\src\Redirector.cc" />
  42. <ClCompile Include="..\..\drogon\lib\src\SecureSSLRedirector.cc" />
  43. <ClCompile Include="..\..\drogon\lib\src\SessionManager.cc" />
  44. <ClCompile Include="..\..\drogon\lib\src\SlashRemover.cc" />
  45. <ClCompile Include="..\..\drogon\lib\src\SlidingWindowRateLimiter.cc" />
  46. <ClCompile Include="..\..\drogon\lib\src\StaticFileRouter.cc" />
  47. <ClCompile Include="..\..\drogon\lib\src\TaskTimeoutFlag.cc" />
  48. <ClCompile Include="..\..\drogon\lib\src\TokenBucketRateLimiter.cc" />
  49. <ClCompile Include="..\..\drogon\lib\src\Utilities.cc" />
  50. <ClCompile Include="..\..\drogon\lib\src\WebSocketClientImpl.cc" />
  51. <ClCompile Include="..\..\drogon\lib\src\WebSocketConnectionImpl.cc" />
  52. <ClCompile Include="..\..\drogon\lib\src\WebsocketControllersRouter.cc" />
  53. <ClCompile Include="..\..\drogon\lib\src\YamlConfigAdapter.cc" />
  54. <ClCompile Include="..\..\drogon\nosql_lib\redis\src\RedisClientImpl.cc" />
  55. <ClCompile Include="..\..\drogon\nosql_lib\redis\src\RedisClientLockFree.cc" />
  56. <ClCompile Include="..\..\drogon\nosql_lib\redis\src\RedisClientManager.cc" />
  57. <ClCompile Include="..\..\drogon\nosql_lib\redis\src\RedisConnection.cc" />
  58. <ClCompile Include="..\..\drogon\nosql_lib\redis\src\RedisResult.cc" />
  59. <ClCompile Include="..\..\drogon\nosql_lib\redis\src\RedisSubscriberImpl.cc" />
  60. <ClCompile Include="..\..\drogon\nosql_lib\redis\src\RedisTransactionImpl.cc" />
  61. <ClCompile Include="..\..\drogon\nosql_lib\redis\src\SubscribeContext.cc" />
  62. <ClCompile Include="..\..\drogon\orm_lib\src\ArrayParser.cc" />
  63. <ClCompile Include="..\..\drogon\orm_lib\src\Criteria.cc" />
  64. <ClCompile Include="..\..\drogon\orm_lib\src\DbClient.cc" />
  65. <ClCompile Include="..\..\drogon\orm_lib\src\DbClientImpl.cc" />
  66. <ClCompile Include="..\..\drogon\orm_lib\src\DbClientLockFree.cc" />
  67. <ClCompile Include="..\..\drogon\orm_lib\src\DbClientManager.cc" />
  68. <ClCompile Include="..\..\drogon\orm_lib\src\DbConnection.cc" />
  69. <ClCompile Include="..\..\drogon\orm_lib\src\DbListener.cc" />
  70. <ClCompile Include="..\..\drogon\orm_lib\src\Exception.cc" />
  71. <ClCompile Include="..\..\drogon\orm_lib\src\Field.cc" />
  72. <ClCompile Include="..\..\drogon\orm_lib\src\mysql_impl\MysqlConnection.cc" />
  73. <ClCompile Include="..\..\drogon\orm_lib\src\mysql_impl\MysqlResultImpl.cc" />
  74. <ClCompile Include="..\..\drogon\orm_lib\src\postgresql_impl\PgConnection.cc" />
  75. <ClCompile Include="..\..\drogon\orm_lib\src\postgresql_impl\PgListener.cc" />
  76. <ClCompile Include="..\..\drogon\orm_lib\src\postgresql_impl\PostgreSQLResultImpl.cc" />
  77. <ClCompile Include="..\..\drogon\orm_lib\src\RestfulController.cc" />
  78. <ClCompile Include="..\..\drogon\orm_lib\src\Result.cc" />
  79. <ClCompile Include="..\..\drogon\orm_lib\src\Row.cc" />
  80. <ClCompile Include="..\..\drogon\orm_lib\src\SqlBinder.cc" />
  81. <ClCompile Include="..\..\drogon\orm_lib\src\sqlite3_impl\Sqlite3Connection.cc" />
  82. <ClCompile Include="..\..\drogon\orm_lib\src\sqlite3_impl\Sqlite3ResultImpl.cc" />
  83. <ClCompile Include="..\..\drogon\orm_lib\src\TransactionImpl.cc" />
  84. <ClCompile Include="..\..\drogon\third_party\mman-win32\mman.c" />
  85. </ItemGroup>

头文件

项目属性---c/c++---常规---附加包含目录

地址根据自己存放源代码目录为准!!!!!!

..\..\drogon\third_party\mman-win32;..\..\drogon\nosql_lib\redis\inc;..\..\drogon\orm_lib\inc;..\..\drogon\trantor;..\..\drogon\lib\inc;..\..\drogon\lib\src;..\..\drogon;..\..\drogon\orm_lib\src\mysql_impl;%(AdditionalIncludeDirectories)

预处理器

%(PreprocessorDefinitions);WIN32;_WINDOWS;NDEBUG;USE_BROTLI;DBUG_OFF;USE_REDIS;CMAKE_INTDIR="Release";HAS_YAML_CPP;YAML_CPP_STATIC_DEFINE

代码生成--运行库 /MT

所有选项--附加选项

%(AdditionalOptions) /external:I "..\..\..\3rdsdk\jsoncpp\include" /external:I "..\..\..\3rdsdk\brotli\include" /external:I "..\..\..\3rdsdk\postgresql\include" /external:I "..\..\..\3rdsdk\sqlite3\include" /external:I "..\..\..\3rdsdk\hiredis\include" /external:I "..\..\..\3rdsdk\zlib\include" /external:I "..\..\..\3rdsdk\yaml-cpp\include" /external:I "..\..\..\3rdsdk\mariadb\include\mysql" /external:I "..\..\..\3rdsdk\yaml-cpp\include" /utf-8 /Zc:__cplusplus

文档管理程序---所有选项

附加依赖项

..\..\..\3rdsdk\yaml-cpp\lib\yaml-cpp.lib
  • trantor

源文件

  1. <ItemGroup>
  2. <ClCompile Include="..\..\drogon\third_party\wepoll\Wepoll.c" />
  3. <ClCompile Include="..\..\drogon\trantor\net\Channel.cc" />
  4. <ClCompile Include="..\..\drogon\trantor\net\EventLoop.cc" />
  5. <ClCompile Include="..\..\drogon\trantor\net\EventLoopThread.cc" />
  6. <ClCompile Include="..\..\drogon\trantor\net\EventLoopThreadPool.cc" />
  7. <ClCompile Include="..\..\drogon\trantor\net\InetAddress.cc" />
  8. <ClCompile Include="..\..\drogon\trantor\net\inner\Acceptor.cc" />
  9. <ClCompile Include="..\..\drogon\trantor\net\inner\Connector.cc" />
  10. <ClCompile Include="..\..\drogon\trantor\net\inner\NormalResolver.cc" />
  11. <ClCompile Include="..\..\drogon\trantor\net\inner\Poller.cc" />
  12. <ClCompile Include="..\..\drogon\trantor\net\inner\poller\EpollPoller.cc" />
  13. <ClCompile Include="..\..\drogon\trantor\net\inner\poller\KQueue.cc" />
  14. <ClCompile Include="..\..\drogon\trantor\net\inner\poller\PollPoller.cc" />
  15. <ClCompile Include="..\..\drogon\trantor\net\inner\Socket.cc" />
  16. <ClCompile Include="..\..\drogon\trantor\net\inner\TcpConnectionImpl.cc" />
  17. <ClCompile Include="..\..\drogon\trantor\net\inner\Timer.cc" />
  18. <ClCompile Include="..\..\drogon\trantor\net\inner\TimerQueue.cc" />
  19. <ClCompile Include="..\..\drogon\trantor\net\inner\tlsprovider\OpenSSLProvider.cc" />
  20. <ClCompile Include="..\..\drogon\trantor\net\TcpClient.cc" />
  21. <ClCompile Include="..\..\drogon\trantor\net\TcpServer.cc" />
  22. <ClCompile Include="..\..\drogon\trantor\utils\AsyncFileLogger.cc" />
  23. <ClCompile Include="..\..\drogon\trantor\utils\ConcurrentTaskQueue.cc" />
  24. <ClCompile Include="..\..\drogon\trantor\utils\crypto\openssl.cc" />
  25. <ClCompile Include="..\..\drogon\trantor\utils\Date.cc" />
  26. <ClCompile Include="..\..\drogon\trantor\utils\Logger.cc" />
  27. <ClCompile Include="..\..\drogon\trantor\utils\LogStream.cc" />
  28. <ClCompile Include="..\..\drogon\trantor\utils\MsgBuffer.cc" />
  29. <ClCompile Include="..\..\drogon\trantor\utils\SerialTaskQueue.cc" />
  30. <ClCompile Include="..\..\drogon\trantor\utils\TimingWheel.cc" />
  31. <ClCompile Include="..\..\drogon\trantor\utils\Utilities.cc" />
  32. <ClCompile Include="..\..\drogon\trantor\utils\WindowsSupport.cc" />
  33. </ItemGroup>

头文件

项目属性---c/c++---常规---附加包含目录

地址根据自己存放源代码目录为准!!!!!!

..\..\drogon\trantor;..\..\drogon;..\..\drogon\third_party\wepoll;..\..\drogon\trantor\utils;..\..\drogon\trantor\net;..\..\drogon\trantor\net\inner;%(AdditionalIncludeDirectories)

预处理器

%(PreprocessorDefinitions);WIN32;_WINDOWS;NDEBUG;USE_OPENSSL;TRANTOR_TLS_PROVIDER=OpenSSL;CMAKE_INTDIR="Release";HAS_YAML_CPP

代码生成--运行库 /MT

所有选项--附加选项

%(AdditionalOptions) /external:I "..\..\..\3rdsdk\openssl\include" /utf-8 /Zc:__cplusplus
  • drogon_ctl

源文件

  1. <ItemGroup>
  2. <ClCompile Include="..\..\drogon\drogon_ctl\cmake.cc" />
  3. <ClCompile Include="..\..\drogon\drogon_ctl\cmd.cc" />
  4. <ClCompile Include="..\..\drogon\drogon_ctl\config_json.cc" />
  5. <ClCompile Include="..\..\drogon\drogon_ctl\config_yaml.cc" />
  6. <ClCompile Include="..\..\drogon\drogon_ctl\create.cc" />
  7. <ClCompile Include="..\..\drogon\drogon_ctl\create_controller.cc" />
  8. <ClCompile Include="..\..\drogon\drogon_ctl\create_filter.cc" />
  9. <ClCompile Include="..\..\drogon\drogon_ctl\create_model.cc" />
  10. <ClCompile Include="..\..\drogon\drogon_ctl\create_plugin.cc" />
  11. <ClCompile Include="..\..\drogon\drogon_ctl\create_project.cc" />
  12. <ClCompile Include="..\..\drogon\drogon_ctl\create_view.cc" />
  13. <ClCompile Include="..\..\drogon\drogon_ctl\demoMain.cc" />
  14. <ClCompile Include="..\..\drogon\drogon_ctl\filter_cc.cc" />
  15. <ClCompile Include="..\..\drogon\drogon_ctl\filter_h.cc" />
  16. <ClCompile Include="..\..\drogon\drogon_ctl\gitignore.cc" />
  17. <ClCompile Include="..\..\drogon\drogon_ctl\help.cc" />
  18. <ClCompile Include="..\..\drogon\drogon_ctl\main.cc" />
  19. <ClCompile Include="..\..\drogon\drogon_ctl\model_cc.cc" />
  20. <ClCompile Include="..\..\drogon\drogon_ctl\model_h.cc" />
  21. <ClCompile Include="..\..\drogon\drogon_ctl\model_json.cc" />
  22. <ClCompile Include="..\..\drogon\drogon_ctl\plugin_cc.cc" />
  23. <ClCompile Include="..\..\drogon\drogon_ctl\plugin_h.cc" />
  24. <ClCompile Include="..\..\drogon\drogon_ctl\press.cc" />
  25. <ClCompile Include="..\..\drogon\drogon_ctl\restful_controller_base_cc.cc" />
  26. <ClCompile Include="..\..\drogon\drogon_ctl\restful_controller_base_h.cc" />
  27. <ClCompile Include="..\..\drogon\drogon_ctl\restful_controller_cc.cc" />
  28. <ClCompile Include="..\..\drogon\drogon_ctl\restful_controller_custom_cc.cc" />
  29. <ClCompile Include="..\..\drogon\drogon_ctl\restful_controller_custom_h.cc" />
  30. <ClCompile Include="..\..\drogon\drogon_ctl\restful_controller_h.cc" />
  31. <ClCompile Include="..\..\drogon\drogon_ctl\test_cmake.cc" />
  32. <ClCompile Include="..\..\drogon\drogon_ctl\test_main.cc" />
  33. <ClCompile Include="..\..\drogon\drogon_ctl\version.cc" />
  34. </ItemGroup>

头文件

项目属性---c/c++---常规---附加包含目录

地址根据自己存放源代码目录为准!!!!!!

..\..\drogon\third_party\mman-win32;..\..\drogon\nosql_lib\redis\inc;..\..\drogon\orm_lib\inc;..\..\drogon\trantor;..\..\drogon\lib\inc;..\..\drogon\lib\src;..\..\drogon;..\..\drogon\trantor\utils;..\..\drogon\trantor\net;..\..\drogon\trantor\net\inner;..\..\drogon\orm_lib\src\mysql_impl;%(AdditionalIncludeDirectories)

预处理器

%(PreprocessorDefinitions);WIN32;_WINDOWS;NDEBUG;USE_BROTLI;DBUG_OFF;USE_REDIS;CMAKE_INTDIR="Release";HAS_YAML_CPP

代码生成--运行库 /MT

附加选项

%(AdditionalOptions) /external:I "..\..\..\3rdsdk\jsoncpp\include" /external:I "..\..\..\3rdsdk\mariadb\include\mysql" /utf-8 /Zc:__cplusplus

连接器--附加库目录

$(outputpath);%(AdditionalLibraryDirectories)

输入

ws2_32.lib;Rpcrt4.lib;iphlpapi.lib;Crypt32.lib;Secur32.lib;shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;drogon.lib;trantor.lib;..\..\..\3rdsdk\openssl\lib\libcrypto.lib;..\..\..\3rdsdk\openssl\lib\libssl.lib;..\..\..\3rdsdk\zlib\lib\zlib.lib;..\..\..\3rdsdk\hiredis\lib\hiredis.lib;..\..\..\3rdsdk\sqlite3\lib\sqlite3.lib;..\..\..\3rdsdk\postgresql\lib\libpq.lib;..\..\..\3rdsdk\brotli\lib\brotlicommon.lib;..\..\..\3rdsdk\brotli\lib\brotlidec.lib;..\..\..\3rdsdk\brotli\lib\brotlienc.lib;..\..\..\3rdsdk\jsoncpp\lib\jsoncpp.lib;..\..\..\3rdsdk\mariadb\lib\mariadbclient.lib;..\..\..\3rdsdk\mariadb\lib\mysqlservices.lib;%(AdditionalDependencies)

忽略待定默认库

%(IgnoreSpecificDefaultLibraries)

OK大功告成Enjoy!!!

备注:使用conan管理依赖库,想要/MT版本的在设置前添加 compiler.runtime=static即可。

conan install .. -s compiler="msvc" -s compiler.version=193 -s compiler.cppstd=17 -s build_type=Release  --output-folder . --build=missing -s compiler.runtime=static

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
  

闽ICP备14008679号