I recently tried compiling an example linked at Mongoose project's website using code::blocks and got certain errors. As I do not know where I went wrong I will list everything that I did in the process.
- Created a new C++ console application project in Code::Blocks for Windows
- Copy pasted code from this example to my main.cpp https://github.com/valenok/mongoose/blob/master/examples/hello.c
- Created and added a new C++ header file called mongoose.h and copy pasted code from mongoose.h file linked on the project's website: https://github.com/valenok/mongoose/blob/master/mongoose.h
- Created and added a new C file called mongoose.h and copy pasted code from mongoose.c file linked on the projects' website: https://github.com/valenok/mongoose/blob/master/mongoose.c
- Saved all the files and the project
- Clicked the compile button on Code::Blocks for Windows
OS in use: Microsoft Windows 8 (64 bit)
Version of Code::Blocks in use: codeblocks-12.11 with MinGW
Compiler to be used by Code::Blocks: GNU GCC Compiler
Following is the Build Messages generated by 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) ===|
Please help me understand where I went wrong. My motive is to impliment the use of Mongooser web server API for Windows and Linux in the project that I am currently working on.
You have a linking problem, you need to link with the winsock library Ws2_32.lib, you can find a tutorial about adding libs to code::blocks here, you don't need to set any directory, just add Ws2_32.lib to the linker from step 5