Недавно я попытался скомпилировать пример, связанный с сайтом проекта Mongoose, используя code :: blocks, и получил некоторые ошибки. Поскольку я не знаю, где я ошибся, я перечислю все, что я сделал в процессе.
Используемая ОС: Microsoft Windows 8 (64-разрядная)
Используемая версия Code :: Blocks: codeblocks-12.11 с MinGW
Компилятор, который будет использоваться Code :: Blocks: GNU GCC Compiler
Ниже приведены сообщения сборки, сгенерированные Code :: Blocks:
D:\pdthrow\cppprojects\server\mongoose.c|176|warning: "INT64_MAX" redefined [enabled by default]| e:\8\code blocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\stdint.h|95|note: this is the location of the previous definition|
D:\pdthrow\cppprojects\server\mongoose.c||In function 'set_ports_option':|
D:\pdthrow\cppprojects\server\mongoose.c|4626|warning: format '%d' expects argument of type 'int', but argument 6 has type 'DWORD' [-Wformat]|
D:\pdthrow\cppprojects\server\mongoose.c||In function 'getreq':|
D:\pdthrow\cppprojects\server\mongoose.c|5027|warning: implicit declaration of function '_strtoi64' [-Wimplicit-function-declaration]| obj\Debug\mongoose.o||In function `sockaddr_to_string':|
D:\pdthrow\cppprojects\server\mongoose.c|614|undefined reference to `inet_ntoa@4'| obj\Debug\mongoose.o||In function `poll':|
D:\pdthrow\cppprojects\server\mongoose.c|1258|undefined reference to `select@20'|
D:\pdthrow\cppprojects\server\mongoose.c|1260|undefined reference to `__WSAFDIsSet@8'| obj\Debug\mongoose.o||In function `set_non_blocking_mode':|
D:\pdthrow\cppprojects\server\mongoose.c|1374|undefined reference to `ioctlsocket@12'| obj\Debug\mongoose.o||In function `push':|
D:\pdthrow\cppprojects\server\mongoose.c|1499|undefined reference to `send@16'| obj\Debug\mongoose.o||In function `pull':|
D:\pdthrow\cppprojects\server\mongoose.c|1526|undefined reference to `recv@16'| obj\Debug\mongoose.o||In function `conn2':|
D:\pdthrow\cppprojects\server\mongoose.c|2596|undefined reference to `gethostbyname@4'|
D:\pdthrow\cppprojects\server\mongoose.c|2598|undefined reference to `socket@12'|
D:\pdthrow\cppprojects\server\mongoose.c|2603|undefined reference to `htons@4'|
D:\pdthrow\cppprojects\server\mongoose.c|2605|undefined reference to `connect@12'|
D:\pdthrow\cppprojects\server\mongoose.c|2608|undefined reference to `closesocket@4'| obj\Debug\mongoose.o||In function `prepare_cgi_environment':|
D:\pdthrow\cppprojects\server\mongoose.c|3298|undefined reference to `ntohs@4'| obj\Debug\mongoose.o||In function `get_remote_ip':|
D:\pdthrow\cppprojects\server\mongoose.c|4274|undefined reference to `ntohl@4'| obj\Debug\mongoose.o||In function `redirect_to_https_port':|
D:\pdthrow\cppprojects\server\mongoose.c|4422|undefined reference to `ntohs@4'| obj\Debug\mongoose.o||In function `close_all_listening_sockets':|
D:\pdthrow\cppprojects\server\mongoose.c|4542|undefined reference to `closesocket@4'| obj\Debug\mongoose.o||In function `parse_port_string':|
D:\pdthrow\cppprojects\server\mongoose.c|4568|undefined reference to `htonl@4'|
D:\pdthrow\cppprojects\server\mongoose.c|4569|undefined reference to `htons@4'|
D:\pdthrow\cppprojects\server\mongoose.c|4580|undefined reference to `htons@4'| obj\Debug\mongoose.o||In function `set_ports_option':|
D:\pdthrow\cppprojects\server\mongoose.c|4611|undefined reference to `socket@12'|
D:\pdthrow\cppprojects\server\mongoose.c|4615|undefined reference to `setsockopt@20'|
D:\pdthrow\cppprojects\server\mongoose.c|4622|undefined reference to `bind@12'|
D:\pdthrow\cppprojects\server\mongoose.c|4624|undefined reference to `listen@8'|
D:\pdthrow\cppprojects\server\mongoose.c|4627|undefined reference to `closesocket@4'|
D:\pdthrow\cppprojects\server\mongoose.c|4632|undefined reference to `closesocket@4'| obj\Debug\mongoose.o||In function `close_socket_gracefully':|
D:\pdthrow\cppprojects\server\mongoose.c|4913|undefined reference to `setsockopt@20'|
D:\pdthrow\cppprojects\server\mongoose.c|4917|undefined reference to `shutdown@8'|
D:\pdthrow\cppprojects\server\mongoose.c|4932|undefined reference to `closesocket@4'| obj\Debug\mongoose.o||In function `mg_connect':|
D:\pdthrow\cppprojects\server\mongoose.c|4972|undefined reference to `closesocket@4'|
D:\pdthrow\cppprojects\server\mongoose.c|4977|undefined reference to `closesocket@4'|
D:\pdthrow\cppprojects\server\mongoose.c|4987|undefined reference to `getsockname@12'| obj\Debug\mongoose.o||In function `worker_thread':|
D:\pdthrow\cppprojects\server\mongoose.c|5175|undefined reference to `ntohs@4'|
D:\pdthrow\cppprojects\server\mongoose.c|5178|undefined reference to `ntohl@4'| obj\Debug\mongoose.o||In function `set_sock_timeout':|
D:\pdthrow\cppprojects\server\mongoose.c|5238|undefined reference to `setsockopt@20'|
D:\pdthrow\cppprojects\server\mongoose.c|5239|undefined reference to `setsockopt@20'| obj\Debug\mongoose.o||In function `accept_new_connection':|
D:\pdthrow\cppprojects\server\mongoose.c|5249|undefined reference to `accept@12'|
D:\pdthrow\cppprojects\server\mongoose.c|5250|undefined reference to `ntohl@4'|
D:\pdthrow\cppprojects\server\mongoose.c|5253|undefined reference to `closesocket@4'|
D:\pdthrow\cppprojects\server\mongoose.c|5260|undefined reference to `getsockname@12'|
D:\pdthrow\cppprojects\server\mongoose.c|5267|undefined reference to `setsockopt@20'| obj\Debug\mongoose.o||In function `mg_stop':|
D:\pdthrow\cppprojects\server\mongoose.c|5384|undefined reference to `WSACleanup@0'| obj\Debug\mongoose.o||In function `mg_start':|
D:\pdthrow\cppprojects\server\mongoose.c|5397|undefined reference to `WSAStartup@8'| ||=== Build finished: 41 errors, 3 warnings (0 minutes, 3 seconds) ===|
Пожалуйста, помогите мне понять, где я ошибся. Моя цель — использовать API веб-сервера Mongooser для Windows и Linux в проекте, над которым я сейчас работаю.
У вас есть проблема со связыванием, вам нужно связать ее с библиотекой winsock Ws2_32.lib, вы можете найти учебник по добавлению библиотек в code :: blocks Вот, вам не нужно устанавливать какой-либо каталог, просто добавьте Ws2_32.lib в компоновщик с шага 5
Других решений пока нет …