# Help with cmake for mongoose web

**URL:** https://discourse.cmake.org/t/help-with-cmake-for-mongoose-web/13311
**Category:** Usage
**Tags:** os:windows
**Created:** [December 31, 2024, 8:59pm UTC](https://discourse.cmake.org/t/help-with-cmake-for-mongoose-web/13311 "2024-12-31T20:59:42Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![klaarnou](https://discourse.cmake.org/user_avatar/discourse.cmake.org/klaarnou/32/5244_2.png) [@klaarnou](https://discourse.cmake.org/u/klaarnou)
#### Post date: [December 31, 2024, 8:59pm UTC](https://discourse.cmake.org/t/help-with-cmake-for-mongoose-web/13311/1 "2024-12-31T20:59:42Z")

</div>

Hello.

I am new to CMake. I want to use CMake to build mongoose web lib into my project.  
I use VSCode on Windows 11.

CMakeLists.txt and Web.cpp are listed below. The dir structure : CMakeLists.txt and Web.ccp are in root dir. Rest is where Cmake puts it. I use GCC kit to compile as per instruction from mongoose.

**- I cannot get this to build : Web.cpp:1:10: fatal error: mongoose.h: No such file or directory**

Thank you for your help.

CMakeLists.txt

```auto
cmake_minimum_required(VERSION 3.31)
  
project(MongWeb VERSION 0.1 LANGUAGES CXX)
  
include(FetchContent)
  
FetchContent_Declare(Mongoose GIT_REPOSITORY https://github.com/cesanta/mongoose.git GIT_TAG 7.16)
  
FetchContent_MakeAvailable(Mongoose)
  
add_executable(${PROJECT_NAME} Web.cpp)
  
target_link_libraries(${PROJECT_NAME} PRIVATE Mongoose)

```

~CMakeLists.txt

Web.cpp

```auto
  #include "mongoose.h"
  
  // Connection event handler function
  static void fn(struct mg_connection *c, int ev, void *ev_data) {
    if (ev == MG_EV_HTTP_MSG) { // New HTTP request received
      struct mg_http_message *hm = (struct mg_http_message *) ev_data; // Parsed HTTP request
      if (mg_match(hm->uri, mg_str("/api/hello"), NULL)) { // REST API call?
        mg_http_reply(c, 200, "", "{%m:%d}\n", MG_ESC("status"), 1); // Yes. Respond JSON
      } else {
        struct mg_http_serve_opts opts = {.root_dir = "."}; // For all other URLs,
        mg_http_serve_dir(c, hm, &opts); // Serve static files
      }
    }
  }
  
  int main() {
    struct mg_mgr mgr; // Mongoose event manager. Holds all connections
    mg_mgr_init(&mgr); // Initialise event manager
    mg_http_listen(&mgr, "http://0.0.0.0:8000", fn, NULL); // Setup listener
    for (;;) {
      mg_mgr_poll(&mgr, 1000); // Infinite event loop
    }
    return 0;
  }

```

~Web.cpp

---

<div class="post-metadata">

### Author: ![eyalamir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eyalamir/32/5239_2.png) [@eyalamir](https://discourse.cmake.org/u/eyalamir)
#### Post date: [January 1, 2025, 4:58am UTC](https://discourse.cmake.org/t/help-with-cmake-for-mongoose-web/13311/2 "2025-01-01T04:58:14Z")

</div>

mongoose is not built using CMake. That means that you have to create the Mongoose CMake target yourself with the source files and include directories.

Here’s a basic example that does that:

```auto
cmake_minimum_required(VERSION 3.31)

project(MongWeb VERSION 0.1 LANGUAGES C CXX)
include(FetchContent)

FetchContent_Declare(Mongoose GIT_REPOSITORY
        https://github.com/cesanta/mongoose.git GIT_TAG 7.16)
FetchContent_MakeAvailable(Mongoose)

add_library(MongooseStatic STATIC
        ${mongoose_SOURCE_DIR}/mongoose.c)

target_include_directories(MongooseStatic PUBLIC
        ${mongoose_SOURCE_DIR})

add_executable(${PROJECT_NAME} Web.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE MongooseStatic)

```

---

<div class="post-metadata">

### Author: ![klaarnou](https://discourse.cmake.org/user_avatar/discourse.cmake.org/klaarnou/32/5244_2.png) [@klaarnou](https://discourse.cmake.org/u/klaarnou)
#### Post date: [January 1, 2025, 5:02am UTC](https://discourse.cmake.org/t/help-with-cmake-for-mongoose-web/13311/3 "2025-01-01T05:02:54Z")

</div>

Thank you very much for your help.  
Happy new year!

---

<div class="post-metadata">

### Author: ![klaarnou](https://discourse.cmake.org/user_avatar/discourse.cmake.org/klaarnou/32/5244_2.png) [@klaarnou](https://discourse.cmake.org/u/klaarnou)
#### Post date: [January 1, 2025, 6:01am UTC](https://discourse.cmake.org/t/help-with-cmake-for-mongoose-web/13311/4 "2025-01-01T06:01:20Z")

</div>

Ok, I might have bitten off a little more than I can chew here.

I used your example and that gave some problems that I was able to solve. The new problem is the worlds longest compile error.

I think the mongoose.h header file is not seen correctly. I tried to fix this by adding

`set_target_properties(MongooseStatic PROPERTIES PUBLIC_HEADER ${mongoose_SOURCE_DIR}/mongoose.h)`

But this did nothing.

Any Ideas?

New CMakeLists.txt

```auto
cmake_minimum_required(VERSION 3.31)
project(MongWeb VERSION 0.1 LANGUAGES C CXX)
#set(CMAKE_CXX_STANDARD 23)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent) 
FetchContent_Declare(mongoose GIT_REPOSITORY https://github.com/cesanta/mongoose.git GIT_TAG 7.16)
FetchContent_MakeAvailable(mongoose)

add_library(MongooseStatic STATIC
        ${mongoose_SOURCE_DIR}/mongoose.c)

target_include_directories(MongooseStatic PUBLIC
        ${mongoose_SOURCE_DIR})
target_include_directories(MongooseStatic PUBLIC )

set_target_properties(MongooseStatic PROPERTIES PUBLIC_HEADER ${mongoose_SOURCE_DIR}/mongoose.h)

add_executable(${PROJECT_NAME} Web.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC MongooseStatic)

```

Worlds longest error:

```auto
[main] Building folder: d:/programming/cpp/MongWeb/build

[build] Starting build

[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build d:/programming/cpp/MongWeb/build --config Debug --target all -j 26 --

[build] [50%] Built target MongooseStatic

[build] [75%] Linking CXX executable MongWeb.exe

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `mg_mgr_init':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:4044:(.text+0xf027): undefined reference to `__imp_WSAStartup'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `setlocaddr':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7834:(.text+0x13114): undefined reference to `__imp_getsockname'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `mg_io_send':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7869:(.text+0x13331): undefined reference to `__imp_sendto'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7872:(.text+0x13381): undefined reference to `__imp_send'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7874:(.text+0x133bf): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7875:(.text+0x133f8): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7875:(.text+0x13408): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7875:(.text+0x13418): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7876:(.text+0x13435): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj):D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7884: more undefined references to `__imp_WSAGetLastError' follow

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `mg_set_non_blocking_mode':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7898:(.text+0x135ba): undefined reference to `__imp_ioctlsocket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `mg_open_listener':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7938:(.text+0x1371d): undefined reference to `__imp_socket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7939:(.text+0x13760): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7941:(.text+0x137a0): undefined reference to `__imp_setsockopt'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7944:(.text+0x137e7): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7967:(.text+0x13826): undefined reference to `__imp_bind'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7968:(.text+0x1386d): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7970:(.text+0x138a5): undefined reference to `__imp_listen'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7973:(.text+0x138e8): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7982:(.text+0x13954): undefined reference to `__imp_closesocket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `recv_raw':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7991:(.text+0x139e0): undefined reference to `__imp_recvfrom'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7994:(.text+0x13a38): undefined reference to `__imp_recv'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7996:(.text+0x13a76): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7997:(.text+0x13aaf): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7997:(.text+0x13abf): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7997:(.text+0x13acf): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:7998:(.text+0x13aec): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj):D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8051: more undefined references to `__imp_WSAGetLastError' follow

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `close_conn':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8072:(.text+0x13f89): undefined reference to `__imp_closesocket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `connect_conn':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8084:(.text+0x13fd1): undefined reference to `__imp_getpeername'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `setsockopts':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8104:(.text+0x14096): undefined reference to `__imp_setsockopt'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8106:(.text+0x140c4): undefined reference to `__imp_setsockopt'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `mg_connect_resolved':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8116:(.text+0x1413f): undefined reference to `__imp_socket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8119:(.text+0x14175): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8138:(.text+0x1425d): undefined reference to `__imp_connect'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8142:(.text+0x142b0): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8142:(.text+0x142c0): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8142:(.text+0x142d0): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8146:(.text+0x1435f): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `raccept':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8156:(.text+0x143d3): undefined reference to `__imp_accept'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8157:(.text+0x143e7): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `accept_conn':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8173:(.text+0x14476): undefined reference to `__imp_WSAGetLastError'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8182:(.text+0x14502): undefined reference to `__imp_closesocket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `mg_iotest':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8327:(.text+0x14b6d): undefined reference to `__imp_select'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8339:(.text+0x14bf5): undefined reference to `__WSAFDIsSet'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8342:(.text+0x14c42): undefined reference to `__WSAFDIsSet'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8343:(.text+0x14ca1): undefined reference to `__WSAFDIsSet'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `mg_socketpair':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8360:(.text+0x14dd7): undefined reference to `__imp_socket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8361:(.text+0x14e10): undefined reference to `__imp_socket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8362:(.text+0x14e3d): undefined reference to `__imp_bind'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8363:(.text+0x14e70): undefined reference to `__imp_bind'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8364:(.text+0x14e96): undefined reference to `__imp_getsockname'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8365:(.text+0x14eca): undefined reference to `__imp_getsockname'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8366:(.text+0x14ef5): undefined reference to `__imp_connect'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8367:(.text+0x14f1a): undefined reference to `__imp_connect'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8371:(.text+0x14f4d): undefined reference to `__imp_closesocket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8372:(.text+0x14f75): undefined reference to `__imp_closesocket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `wufn':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8396:(.text+0x1506f): undefined reference to `__imp_closesocket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `mg_wakeup_init':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8411:(.text+0x15154): undefined reference to `__imp_closesocket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8412:(.text+0x15164): undefined reference to `__imp_closesocket'

[build] C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libMongooseStatic.a(mongoose.c.obj): in function `mg_wakeup':

[build] D:/programming/cpp/MongWeb/build/_deps/mongoose-src/mongoose.c:8430:(.text+0x152b8): undefined reference to `__imp_send'

[build] collect2.exe: error: ld returned 1 exit status

[build] mingw32-make[2]: *** [CMakeFiles\MongWeb.dir\build.make:103: MongWeb.exe] Error 1

[build] mingw32-make[1]: *** [CMakeFiles\Makefile2:121: CMakeFiles/MongWeb.dir/all] Error 2

[build] mingw32-make: *** [Makefile:90: all] Error 2

[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build d:/programming/cpp/MongWeb/build --config Debug --target all -j 26 -- exited with code: 2

[driver] Build completed: 00:00:00.305

[build] Build finished with exit code 2

```

---

<div class="post-metadata">

### Author: ![eyalamir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eyalamir/32/5239_2.png) [@eyalamir](https://discourse.cmake.org/u/eyalamir)
#### Post date: [January 1, 2025, 7:18pm UTC](https://discourse.cmake.org/t/help-with-cmake-for-mongoose-web/13311/5 "2025-01-01T19:18:28Z")

</div>

The example I gave you compiled right away on my machine with your unchanged Web.cpp.

Which OS/Compiler are you using? Would you perhaps explain exactly what the error is when you’ve used that example as-is?

Also you can add `message(${mongoose_SOURCE_DIR})` to log what it expands to and if it indeed shows the correct path for Mongoose.

---

<div class="post-metadata">

### Author: ![eyalamir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eyalamir/32/5239_2.png) [@eyalamir](https://discourse.cmake.org/u/eyalamir)
#### Post date: [January 1, 2025, 7:20pm UTC](https://discourse.cmake.org/t/help-with-cmake-for-mongoose-web/13311/6 "2025-01-01T19:20:16Z")

</div>

P.S. mingw is a problematic compiler that many libraries are not supporting.

If you can, please use MSVC or Clang to build your code, it will prevent many boring issues.

---

<div class="post-metadata">

### Author: ![klaarnou](https://discourse.cmake.org/user_avatar/discourse.cmake.org/klaarnou/32/5244_2.png) [@klaarnou](https://discourse.cmake.org/u/klaarnou)
#### Post date: [January 2, 2025, 8:46am UTC](https://discourse.cmake.org/t/help-with-cmake-for-mongoose-web/13311/7 "2025-01-02T08:46:36Z")

</div>

Hi Eyal.

Thanks for your help, highly appreciated.

I have compiled with Windows SDK. It works with the attached CMakeLists.txt

I cannot get it to compile with GCC14.2.0 x86-w64-mingw32(ucrt64)  
I use VSCode on Windows 11 and installed the GCC kit with MSYS2  
Mongoose gives a procedure that I followed [Mongoose :: Tutorials :: Tools](https://mongoose.ws/documentation/tutorials/tools/)  
although they use mingwInstaller.exe.

It looks like the build process falls apart at linking (see error attached in previous post)

cheers, Bernard.

**CMakeLists.txt**

```auto
cmake_minimum_required(VERSION 3.31)
project(MongWeb VERSION 0.1 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent) 
FetchContent_Declare(mongoose GIT_REPOSITORY https://github.com/cesanta/mongoose.git GIT_TAG 7.16)
FetchContent_MakeAvailable(mongoose)

add_library(MongooseStatic STATIC
        ${mongoose_SOURCE_DIR}/mongoose.c)

target_include_directories(MongooseStatic PUBLIC
        ${mongoose_SOURCE_DIR})

set_target_properties(MongooseStatic PROPERTIES PUBLIC_HEADER ${mongoose_SOURCE_DIR}/mongoose.h)

add_executable(${PROJECT_NAME} Web.cpp)

target_link_libraries(${PROJECT_NAME} PUBLIC MongooseStatic)

```

---

<div class="post-metadata">

### Author: ![eyalamir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eyalamir/32/5239_2.png) [@eyalamir](https://discourse.cmake.org/u/eyalamir)
#### Post date: [January 6, 2025, 5:17pm UTC](https://discourse.cmake.org/t/help-with-cmake-for-mongoose-web/13311/8 "2025-01-06T17:17:13Z")

</div>

Hard to say, maybe there’s a way to get it work with MinGW/GCC, but for practical reasons I strongly suggest to just use MSVC or Clang on Windows, especially if you don’t want to fix other people’s libraries so they compile with another compiler.
