0

A while ago I used the libssh on a Visual Studio project. So far so good.

Now I want to use that library on another project, a Borland Cbuilder project. But now I get a lot of compiler errors.

I started by putting the following includes in the header:

#include <libssh/libssh.h>
#include <libssh/sftp.h>

But this gives the following error:

[C++ Error] libssh.h(59): E2209 Unable to open include file 'unistd.h'

This refers to a unix file, so that isn't good. In the file libssh.h I see the following code:

#ifdef _MSC_VER
  /* Visual Studio hasn't inttypes.h so it doesn't know uint32_t */
  typedef int int32_t;
  typedef unsigned int uint32_t;
  typedef unsigned short uint16_t;
  typedef unsigned char uint8_t;
  typedef unsigned long uint64_t;
  typedef int mode_t;
#else /* _MSC_VER */
  #include <unistd.h>
  #include <inttypes.h>
#endif /* _MSC_VER */

So I tried to include the following line in my header file as a workaround:

#define _MSC_VER   1

But then I get another error:

[C++ Error] types.h(47): E2238 Multiple declaration for 'mode_t'
[C++ Error] libssh.h(57): E2344 Earlier declaration of 'mode_t'

Long story short: whatever next workarounds I try, I always get compiler errors.

Can this be fixed? Or can libssh only be used with Microsoft compilers?

[Edit:] I tried another thing: include the typedefs from the libbssh header into my own header. Then i get the next error:

[C++ Error] sftp.h(50): E2238 Multiple declaration for 'uid_t'

for the following piece from sftp.h:

#ifndef uid_t
  typedef uint32_t uid_t;
#endif /* uid_t */

I'm flabbergasted....

BTW, I'm using Borland C++builder 5.0. (I know it's ancient)

Hneel
  • 95
  • 10

1 Answers1

0

Well, eventually I fixed the header files in the following way:

#ifdef _MSC_VER
  // Do MSVC specific stuff
#else
#ifdef __BCPLUSPLUS__
  // Do Borland specific stuff
#else /* __BCPLUSPLUS__ */
  // Do unix stuff
#endif /* __BCPLUSPLUS__ */
#endif /* _MSC_VER */

I copied the MSVC stuff to the Borland section and after some tweaking it compiled.

Hneel
  • 95
  • 10
  • Use `__BORLANDC__` instead of `__BCPLUSPLUS__`, and `#elif defined(...)` instead of `#else #ifdef`. But if the VC++ and Borland sections are using the same code, merge them together by using `#if defined(_MSC_VER) || defined(__BORLANDC__)` instead of separate `#ifdef`s – Remy Lebeau Nov 16 '17 at 19:59