libsignal-protocol-c icon indicating copy to clipboard operation
libsignal-protocol-c copied to clipboard

Windows compiling error with mvsc

Open Hirobreak opened this issue 6 years ago • 2 comments

I have:

  • [x] searched open and closed issues for duplicates

Bug description

I was unable to compile libsignal-protocol-c using Visual Studio, either with the IDE or the default console compiler msvc.

Steps to reproduce

  • Open PowerShell or Developer Command Prompt for VS 2019
  • Go to the repo's folder, create a folder for the build and open it
  • run cmake ..
  • run cmake --build .

Actual result: I get the following errors:

C:\Users\Unable to decrypt\Documents\Git\libsignal-protocol-c\src\curve25519\ed25519\tests\internal_fast_tests.c(300,28): erro
r C2057:  expected constant expression [C:\Users\Unable to decrypt\Documents\Git\libsignal-protocol-c\myOwnBuild\src\curve2551
9\curve25519.vcxproj]
C:\Users\Unable to decrypt\Documents\Git\libsignal-protocol-c\src\curve25519\ed25519\tests\internal_fast_tests.c(300,28): erro r C2466:  cannot allocate an array of constant size 0 [C:\Users\Unable to decrypt\Documents\Git\libsignal-protocol-c\myOwnBuil d\src\curve25519\curve25519.vcxproj]
C:\Users\Unable to decrypt\Documents\Git\libsignal-protocol-c\src\curve25519\ed25519\tests\internal_fast_tests.c(300,29): erro r C2133:  'msg': unknown size [C:\Users\Unable to decrypt\Documents\Git\libsignal-protocol-c\myOwnBuild\src\curve25519\curve25 519.vcxproj]
C:\Users\Unable to decrypt\Documents\Git\libsignal-protocol-c\src\curve25519\ed25519\tests\internal_fast_tests.c(340,28): erro r C2057:  expected constant expression [C:\Users\Unable to decrypt\Documents\Git\libsignal-protocol-c\myOwnBuild\src\curve2551 9\curve25519.vcxproj]
C:\Users\Unable to decrypt\Documents\Git\libsignal-protocol-c\src\curve25519\ed25519\tests\internal_fast_tests.c(340,28): erro r C2466:  cannot allocate an array of constant size 0 [C:\Users\Unable to decrypt\Documents\Git\libsignal-protocol-c\myOwnBuil d\src\curve25519\curve25519.vcxproj]
C:\Users\Unable to decrypt\Documents\Git\libsignal-protocol-c\src\curve25519\ed25519\tests\internal_fast_tests.c(340,29): erro
r C2133:  'msg': unknown size [C:\Users\Unable to decrypt\Documents\Git\libsignal-protocol-c\myOwnBuild\src\curve25519\curve25
519.vcxproj]

Expected result: I expect to generate signal-protocol-c.lib

Device info

Device: Toshiba (DESKTOP-PKJM3FE) Windows 10 Home 64 bits Signal version: 2.3.2

Link to logs

It seems like msvc doesn't fully support standard c99 which leads to errors in the following code:

const int MSG_LEN = 200;
unsigned char msg[MSG_LEN];

It also doesn't identify #ifndef _WINDOWS so it always ends up trying to include unistd.h.

I have a workaround, changes can be seen here https://github.com/Hirobreak/libsignal-protocol-c/commit/2721ea8694d7678e7edc519a90bffc203fb92e0d.

Which works for me as of now. I did a little research to make my workaround a solution but I've found none yet

Hirobreak avatar Sep 19 '19 20:09 Hirobreak

Note MSVC appears to only support this syntax when compiling a C++ application. I have tried targeting C11 standard with compiler flags using CMake and it still fails. I have not determined the root cause of the parsing/compilation bug using VS2019 either but have a similar work around stashed for when I need to build on Windows.

agauvin-cipherloc avatar Feb 28 '20 16:02 agauvin-cipherloc

The workaround is:

#define MSG_LEN 200 unsigned char msg[MSG_LEN];

and you can add the macro _WINDOWS in your settings.

Windows also gave an an error with unsigned and strdup. I disabled then using the additional command line on VC++: /wd4996 /wd4146

( I managed to compile but I didn't find any complete client sample. I want to send a message this should be very simple. )

thradams avatar Jan 11 '21 19:01 thradams