NO

Author Topic: Cesanta / Fossa in Pelle's C v8.0?  (Read 3504 times)

rdtsc

  • Guest
Cesanta / Fossa in Pelle's C v8.0?
« on: February 08, 2017, 03:00:59 AM »
Fossa is an asynchronous, non-blocking multi-protocol networking library for C/C++ from http://cesanta.com. The source is available on Github at https://github.com/cesanta/fossa.

I'm looking into it to simplify creating a chat-like server-client application for a LAN. But trying to build fossa.c and fossa.h (into a shared library, doubt that matters) gives many errors, such as:

Code: [Select]
- - - - - - - - - - common.lib
Building fossa.obj.
C:\Users\Me\Async\Common\fossa.c(1039): warning #2018: Undeclared function 'wcscat' (did you mean 'strcat'?); assuming 'extern' returning 'int'.
C:\Users\Me\Async\Common\fossa.c(2824): warning #2018: Undeclared function 'close' (did you mean 'pclose'?); assuming 'extern' returning 'int'.
C:\Users\Me\Async\Common\fossa.c(3072): warning #2166: Inconsistent linkage for 'ns_forward', previously declared at C:\Users\Me\Async\Common\fossa.c(75).
C:\Users\Me\Async\Common\fossa.c(3288): warning #2018: Undeclared function '_mkdir' (did you mean '(no name)'?); assuming 'extern' returning 'int'.
C:\Users\Me\Async\Common\fossa.c(3368): warning #2018: Undeclared function '_atoi64' (did you mean 'atoi'?); assuming 'extern' returning 'int'.
C:\Users\Me\Async\Common\fossa.c(3562): warning #2117: Old-style function definition for 'ws_random_mask'.
C:\Users\Me\Async\Common\fossa.c(3583): warning #2154: Unreachable code.
C:\Users\Me\Async\Common\fossa.c(4185): error #2152: Unknown field 'st_mtime' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4186): error #2152: Unknown field 'st_size' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4227): error #2152: Unknown field 'st_size' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4247): error #2152: Unknown field 'st_size' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4254): error #2152: Unknown field 'st_size' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4261): error #2152: Unknown field 'st_mtime' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4261): warning #2145: Assignment of 'int *' to 'unsigned long int *'.
C:\Users\Me\Async\Common\fossa.c(4694): error #2152: Unknown field 'st_size' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4695): error #2152: Unknown field 'st_mode' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4715): error #2152: Unknown field 'st_mtime' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4715): warning #2145: Assignment of 'int *' to 'const unsigned long int *'.
C:\Users\Me\Async\Common\fossa.c(4730): error #2149: Undefined size for 'st' with type 'ns_stat_t'.
C:\Users\Me\Async\Common\fossa.c(4796): error #2152: Unknown field 'st_mtime' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4812): error #2152: Unknown field 'st_mode' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4813): error #2152: Unknown field 'st_size' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4829): error #2152: Unknown field 'st_mode' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4837): error #2152: Unknown field 'st_mode' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4865): error #2149: Undefined size for 'st' with type 'ns_stat_t'.
C:\Users\Me\Async\Common\fossa.c(4874): error #2152: Unknown field 'st_mode' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4881): warning #2018: Undeclared function 'rmdir' (did you mean '(no name)'?); assuming 'extern' returning 'int'.
C:\Users\Me\Async\Common\fossa.c(4887): error #2149: Undefined size for 'st' with type 'ns_stat_t'.
C:\Users\Me\Async\Common\fossa.c(4890): error #2152: Unknown field 'st_mode' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(4908): error #2149: Undefined size for 'st' with type 'ns_stat_t'.
C:\Users\Me\Async\Common\fossa.c(4923): error #2149: Undefined size for 'st' with type 'ns_stat_t'.
C:\Users\Me\Async\Common\fossa.c(4946): warning #2018: Undeclared function '_atoi64' (did you mean 'atoi'?); assuming 'extern' returning 'int'.
C:\Users\Me\Async\Common\fossa.c(4975): error #2149: Undefined size for 'st' with type 'ns_stat_t'.
C:\Users\Me\Async\Common\fossa.c(4997): error #2168: Operands of '=' have incompatible types 'ns_stat_t' and 'ns_stat_t'.
C:\Users\Me\Async\Common\fossa.c(5077): warning #2018: Undeclared function '_endthread' (did you mean '_hread'?); assuming 'extern' returning 'int'.
C:\Users\Me\Async\Common\fossa.c(5099): warning #2018: Undeclared function '_endthread' (did you mean '_hread'?); assuming 'extern' returning 'int'.
C:\Users\Me\Async\Common\fossa.c(5109): error #2048: Undeclared identifier 'ns_start_thread' (did you mean 'ns_stat_t'?).
C:\Users\Me\Async\Common\fossa.c(5109): error #2001: Syntax error: expected ')' but found ','.
C:\Users\Me\Async\Common\fossa.c(5109): error #2149: Undefined size for 'func' with type 'ns_stat_t'.
C:\Users\Me\Async\Common\fossa.c(5109): error #2149: Undefined size for 'tp' with type 'ns_stat_t'.
C:\Users\Me\Async\Common\fossa.c(5109): error #2001: Syntax error: expected ';' but found ')'.
C:\Users\Me\Async\Common\fossa.c(5109): warning #2114: Local 'tp' is not referenced.
C:\Users\Me\Async\Common\fossa.c(5109): warning #2114: Local 'func' is not referenced.
C:\Users\Me\Async\Common\fossa.c(5117): warning #2018: Undeclared function 'wcslen' (did you mean '(no name)'?); assuming 'extern' returning 'int'.
C:\Users\Me\Async\Common\fossa.c(5507): error #2149: Undefined size for 'st' with type 'ns_stat_t'.
C:\Users\Me\Async\Common\fossa.c(5510): error #2152: Unknown field 'st_mode' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(5541): error #2152: Unknown field 'st_mode' of 'ns_stat_t' (did you mean '(no name)'?).
C:\Users\Me\Async\Common\fossa.c(5747): warning #2018: Undeclared function '_wstati64' (did you mean '_wstat'?); assuming 'extern' returning 'int'.
C:\Users\Me\Async\Common\fossa.c(5768): warning #2018: Undeclared function '_wopen' (did you mean '_lopen'?); assuming 'extern' returning 'int'.
C:\Users\Me\Async\Common\fossa.c(6963): warning #2030: '=' used in a conditional expression.
C:\Users\Me\Async\Common\fossa.c(6971): warning #2251: Operands of '>=' have types with different signedness: 'int' and 'unsigned int'.
*** Error code: 1 ***
Done.

Now I'd assume this should compile in Windows, and there are several "#ifdef _WIN32" so it must, but there is no mention of the compiler. Some of the included libraries seem like they might be for gcc/linux... "#include <signal.h>" etc. Could all the errors simply be because gcc is required (and is not mentioned)?

And is it worth it to try and "fix" these issues for native Pelle's compilation, or just build into a static library using gcc and link it? (Can polink even link .obj with .o objects?) Some of these I don't see an intuitive solution to, such as "Unknown field 'st_mtime' of 'ns_stat_t' (did you mean '(no name)'?)."  Any ideas? Thanks for taking a look.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Cesanta / Fossa in Pelle's C v8.0?
« Reply #1 on: February 08, 2017, 09:20:34 AM »
some ideas:
change in fossa.c in line 3134
Code: [Select]
struct ns_mgr dummy = {};to
Code: [Select]
struct ns_mgr dummy = {0};try defines
Code: [Select]
NS_ENABLE_THREADS _atoi64=atoll _wstati64=_wstat _stati64=_stat  WIN32_LEAN_AND_MEANand use -MT Multithreaded (LIB) library.

EDIT: simplest_web_server_1_ws.zip
fix for struct stat
Code: [Select]
NS_ENABLE_THREADS WIN32_LEAN_AND_MEAN _atoi64=atoll _wstati64=_wstat _stati64=_stat _OFF_T_DEFINED off_t=__int64 _off_t=__int64
« Last Edit: February 08, 2017, 07:05:46 PM by TimoVJL »
May the source be with you

rdtsc

  • Guest
Re: Cesanta / Fossa in Pelle's C v8.0?
« Reply #2 on: February 09, 2017, 04:25:28 AM »
Thank you much TimoVJL! Tinkering with it,
Code: [Select]
#include <direct.h> /* added */
#include <io.h>
#define wcscat lstrcatW // to fix missing includes
#define wcslen lstrlenW
adding this after #include "fossa.h" in fossa.c seems to solve many of the remaining build issues (but isn't tested.)

Trying to get rid of the warnings,
* Prefixing NS_INTERNAL fixes warning #2166 @ void ns_forward(struct ns_connection *from, struct ns_connection *to) {
* Casting if (off >= msg->pkt.len) { as if (off >= (uint16_t)msg->pkt.len) { fixes warning #2251.
* The warning #2154 "unreachable code" is a real mystery for the following second return statement. Is Pelle's C assuming the second return is impossible because sizeof(long) can only ever be 4?
Code: [Select]
#if NS_DISABLE_WS_RANDOM_MASK
  return 0xefbeadde; /* generated with a random number generator, I swear */
#else
  if (sizeof(long) >= 4) {
    return (uint32_t) random();
  } else if (sizeof(long) == 2) {
    return (uint32_t) random() << 16 | (uint32_t) random();
  }
#endif

Alas, Fossa is several years old. Apparently it is now part of "Mongoose", which is current: https://github.com/cesanta/mongoose

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Cesanta / Fossa in Pelle's C v8.0?
« Reply #3 on: February 09, 2017, 01:02:29 PM »
insert #include <wchar.h> for wcscat and wcslen.
May the source be with you