Can't compile mongoose after add -lpthread -lws2_32 -fopenmp -lwsock32 using MinGw

506 views Asked by At

I using CLion to write my project,Windows 10 is my OS. I use MinGw to compile the source code with CMAKE, and following the wrong message

CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_mgr_init':
C:/Users/admin/Desktop/TB2/mongoose.c:2023: undefined reference to `WSAStartup@8'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_mgr_free':
C:/Users/admin/Desktop/TB2/mongoose.c:2081: undefined reference to `closesocket@4'
C:/Users/admin/Desktop/TB2/mongoose.c:2082: undefined reference to `closesocket@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_resolve2':
C:/Users/admin/Desktop/TB2/mongoose.c:2139: undefined reference to `gethostbyname@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_resolve':
C:/Users/admin/Desktop/TB2/mongoose.c:2151: undefined reference to `inet_ntoa@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_parse_address':
C:/Users/admin/Desktop/TB2/mongoose.c:2226: undefined reference to `htonl@4'
C:/Users/admin/Desktop/TB2/mongoose.c:2227: undefined reference to `htons@4'
C:/Users/admin/Desktop/TB2/mongoose.c:2238: undefined reference to `htons@4'
C:/Users/admin/Desktop/TB2/mongoose.c:2246: undefined reference to `htons@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_do_connect':
C:/Users/admin/Desktop/TB2/mongoose.c:2565: undefined reference to `ntohs@4'
C:/Users/admin/Desktop/TB2/mongoose.c:2565: undefined reference to `inet_ntoa@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_broadcast':
C:/Users/admin/Desktop/TB2/mongoose.c:2763: undefined reference to `send@16'
C:/Users/admin/Desktop/TB2/mongoose.c:2765: undefined reference to `recv@16'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_set_non_blocking_mode':
C:/Users/admin/Desktop/TB2/mongoose.c:2861: undefined reference to `ioctlsocket@12'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_is_error':
C:/Users/admin/Desktop/TB2/mongoose.c:2881: undefined reference to `WSAGetLastError@0'
C:/Users/admin/Desktop/TB2/mongoose.c:2882: undefined reference to `WSAGetLastError@0'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_if_connect_tcp':
C:/Users/admin/Desktop/TB2/mongoose.c:2890: undefined reference to `socket@12'
C:/Users/admin/Desktop/TB2/mongoose.c:2899: undefined reference to `connect@12'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_if_connect_udp':
C:/Users/admin/Desktop/TB2/mongoose.c:2905: undefined reference to `socket@12'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_if_destroy_conn':
C:/Users/admin/Desktop/TB2/mongoose.c:2950: undefined reference to `closesocket@4'
C:/Users/admin/Desktop/TB2/mongoose.c:2953: undefined reference to `closesocket@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_accept_conn':
C:/Users/admin/Desktop/TB2/mongoose.c:2970: undefined reference to `accept@12'
C:/Users/admin/Desktop/TB2/mongoose.c:2977: undefined reference to `closesocket@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_open_listening_socket':
C:/Users/admin/Desktop/TB2/mongoose.c:3001: undefined reference to `socket@12'
C:/Users/admin/Desktop/TB2/mongoose.c:3006: undefined reference to `setsockopt@20'
C:/Users/admin/Desktop/TB2/mongoose.c:3024: undefined reference to `bind@12'
C:/Users/admin/Desktop/TB2/mongoose.c:3025: undefined reference to `listen@8'
C:/Users/admin/Desktop/TB2/mongoose.c:3029: undefined reference to `getsockname@12'
C:/Users/admin/Desktop/TB2/mongoose.c:3032: undefined reference to `closesocket@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_write_to_socket':
C:/Users/admin/Desktop/TB2/mongoose.c:3051: undefined reference to `sendto@24'
C:/Users/admin/Desktop/TB2/mongoose.c:3053: undefined reference to `ntohs@4'
C:/Users/admin/Desktop/TB2/mongoose.c:3053: undefined reference to `inet_ntoa@4'
C:/Users/admin/Desktop/TB2/mongoose.c:3082: undefined reference to `send@16'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_read_from_socket':
C:/Users/admin/Desktop/TB2/mongoose.c:3127: undefined reference to `recv@16'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_recvfrom':
C:/Users/admin/Desktop/TB2/mongoose.c:3149: undefined reference to `recvfrom@24'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_handle_udp_read':
C:/Users/admin/Desktop/TB2/mongoose.c:3162: undefined reference to `ntohs@4'
C:/Users/admin/Desktop/TB2/mongoose.c:3162: undefined reference to `inet_ntoa@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_mgr_handle_conn':
C:/Users/admin/Desktop/TB2/mongoose.c:3227: undefined reference to `getsockopt@20'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_mgr_handle_ctl_sock':
C:/Users/admin/Desktop/TB2/mongoose.c:3287: undefined reference to `recv@16'
C:/Users/admin/Desktop/TB2/mongoose.c:3289: undefined reference to `send@16'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_mgr_poll':
C:/Users/admin/Desktop/TB2/mongoose.c:3547: undefined reference to `select@20'
C:/Users/admin/Desktop/TB2/mongoose.c:3553: undefined reference to `__WSAFDIsSet@8'
C:/Users/admin/Desktop/TB2/mongoose.c:3561: undefined reference to `__WSAFDIsSet@8'
C:/Users/admin/Desktop/TB2/mongoose.c:3562: undefined reference to `__WSAFDIsSet@8'
C:/Users/admin/Desktop/TB2/mongoose.c:3563: undefined reference to `__WSAFDIsSet@8'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_socketpair':
C:/Users/admin/Desktop/TB2/mongoose.c:3604: undefined reference to `htons@4'
C:/Users/admin/Desktop/TB2/mongoose.c:3605: undefined reference to `htonl@4'
C:/Users/admin/Desktop/TB2/mongoose.c:3607: undefined reference to `socket@12'
C:/Users/admin/Desktop/TB2/mongoose.c:3608: undefined reference to `bind@12'
C:/Users/admin/Desktop/TB2/mongoose.c:3609: undefined reference to `listen@8'
C:/Users/admin/Desktop/TB2/mongoose.c:3610: undefined reference to `getsockname@12'
C:/Users/admin/Desktop/TB2/mongoose.c:3611: undefined reference to `socket@12'
C:/Users/admin/Desktop/TB2/mongoose.c:3612: undefined reference to `connect@12'
C:/Users/admin/Desktop/TB2/mongoose.c:3614: undefined reference to `getsockname@12'
C:/Users/admin/Desktop/TB2/mongoose.c:3615: undefined reference to `connect@12'
C:/Users/admin/Desktop/TB2/mongoose.c:3617: undefined reference to `accept@12'
C:/Users/admin/Desktop/TB2/mongoose.c:3622: undefined reference to `closesocket@4'
C:/Users/admin/Desktop/TB2/mongoose.c:3627: undefined reference to `closesocket@4'
C:/Users/admin/Desktop/TB2/mongoose.c:3628: undefined reference to `closesocket@4'
C:/Users/admin/Desktop/TB2/mongoose.c:3629: undefined reference to `closesocket@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_sock_get_addr':
C:/Users/admin/Desktop/TB2/mongoose.c:3643: undefined reference to `getpeername@12'
C:/Users/admin/Desktop/TB2/mongoose.c:3645: undefined reference to `getsockname@12'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `deliver_websocket_data':
C:/Users/admin/Desktop/TB2/mongoose.c:4091: undefined reference to `ntohs@4'
C:/Users/admin/Desktop/TB2/mongoose.c:4094: undefined reference to `ntohl@4'
C:/Users/admin/Desktop/TB2/mongoose.c:4095: undefined reference to `ntohl@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_send_ws_header':
C:/Users/admin/Desktop/TB2/mongoose.c:4193: undefined reference to `htons@4'
C:/Users/admin/Desktop/TB2/mongoose.c:4200: undefined reference to `htonl@4'
C:/Users/admin/Desktop/TB2/mongoose.c:4202: undefined reference to `htonl@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `wait_until_ready':
C:/Users/admin/Desktop/TB2/mongoose.c:5806: undefined reference to `select@20'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `push_to_stdin':
C:/Users/admin/Desktop/TB2/mongoose.c:5815: undefined reference to `recv@16'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `pull_from_stdout':
C:/Users/admin/Desktop/TB2/mongoose.c:5837: undefined reference to `send@16'
C:/Users/admin/Desktop/TB2/mongoose.c:5844: undefined reference to `shutdown@8'
C:/Users/admin/Desktop/TB2/mongoose.c:5845: undefined reference to `closesocket@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `start_process':
C:/Users/admin/Desktop/TB2/mongoose.c:5931: undefined reference to `closesocket@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `handle_cgi':
C:/Users/admin/Desktop/TB2/mongoose.c:6241: undefined reference to `closesocket@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_send_http_file':
C:/Users/admin/Desktop/TB2/mongoose.c:6333: undefined reference to `ntohl@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_sock_addr_to_str':
C:/Users/admin/Desktop/TB2/mongoose.c:6725: undefined reference to `inet_ntoa@4'
C:/Users/admin/Desktop/TB2/mongoose.c:6731: undefined reference to `ntohs@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `parse_mqtt':
C:/Users/admin/Desktop/TB2/mongoose.c:7137: undefined reference to `ntohs@4'
C:/Users/admin/Desktop/TB2/mongoose.c:7141: undefined reference to `ntohs@4'
C:/Users/admin/Desktop/TB2/mongoose.c:7148: undefined reference to `ntohs@4'
C:/Users/admin/Desktop/TB2/mongoose.c:7157: undefined reference to `ntohs@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_send_mqtt_handshake_opt':
C:/Users/admin/Desktop/TB2/mongoose.c:7225: undefined reference to `htons@4'
C:/Users/admin/Desktop/TB2/mongoose.c:7228: undefined reference to `htons@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_mqtt_publish':
C:/Users/admin/Desktop/TB2/mongoose.c:7261: undefined reference to `htons@4'
C:/Users/admin/Desktop/TB2/mongoose.c:7262: undefined reference to `htons@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_mqtt_subscribe':
C:/Users/admin/Desktop/TB2/mongoose.c:7280: undefined reference to `htons@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj):C:/Users/admin/Desktop/TB2/mongoose.c:7285: more undefined references to `htons@4' follow
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_dns_encode_record':
C:/Users/admin/Desktop/TB2/mongoose.c:7699: undefined reference to `htonl@4'
C:/Users/admin/Desktop/TB2/mongoose.c:7714: undefined reference to `htons@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_send_dns_query':
C:/Users/admin/Desktop/TB2/mongoose.c:7751: undefined reference to `htons@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_parse_dns':
C:/Users/admin/Desktop/TB2/mongoose.c:7823: undefined reference to `ntohs@4'
C:/Users/admin/Desktop/TB2/mongoose.c:7824: undefined reference to `ntohs@4'
C:/Users/admin/Desktop/TB2/mongoose.c:7825: undefined reference to `ntohs@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `dns_handler':
C:/Users/admin/Desktop/TB2/mongoose.c:7906: undefined reference to `htons@4'
CMakeFiles\TB2.dir/objects.a(mongoose.c.obj): In function `mg_resolve_from_hosts_file':
C:/Users/admin/Desktop/TB2/mongoose.c:8132: undefined reference to `htonl@4'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\TB2.dir\build.make:225: recipe for target 'TB2.exe' failed
mingw32-make.exe[2]: *** [TB2.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles/TB2.dir/all] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/TB2.dir/all' failed
Makefile:82: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2

and my Cmake write like this

cmake_minimum_required(VERSION 3.3)
project(TB2)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ")

set(CMAKE_C_FLAGS "-std=c99 -static-libgcc -w -lpthread -lws2_32 -fopenmp -lwsock32")

set(SOURCE_FILES main.c r2nat_to_local.h mongoose.c mongoose.h sqlite3.c sqlite3.h TUtility.c TUtility.h cJSON.c cJSON.h url_parser.c url_parser.h)

add_executable(TB2 ${SOURCE_FILES})

target_link_libraries(TB2 sqlite3)

add_definitions(-DUNICODE -D_UNICODE -DMG_ENABLE_THREADS -DDEBUG -DDEBUG -DHAVE_MD5 -DRA100)

I don't know where is worng. After I add -lws2_32 -fopenmp -lwsock32

How to fix the error?

0

There are 0 answers