Ziti -tunnel-sdk-c compilation steps

Hi Team,
Can someone list all the steps to compile the code after cloning the repository from GitHub - openziti/ziti-tunnel-sdk-c

Thanks.
Shiv

Hi Shiv - you’re just trying to build? Are you familiar with cmake?

I have used it but not too familiar with setting it up.

Assuming you’re not cross-compiling, give this a try after the clone:

$ mkdir ziti-tunnel-sdk-c/build
$ cd ziti-tunnel-sdk-c/build
$ cmake .. && make

Thanks @smilidave, build went through!

Hi Dave,

I have been trying to cross compile Ziti -tunnel-sdk-c for windows using Ubuntu and the following command:

cmake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ WIN32 … && make

but have got stuck and not sure what I need to do toresolve this. I have tried installing libsodium-dev but still get errors with regards to secretstream.

/usr/bin/i686-w64-mingw32-ld: CMakeFiles/ziti_dll.dir/objects.a(connect.c.obj): in function ziti_write_req': /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/connect.c:596: undefined reference to crypto_secretstream_xchacha20poly1305_abytes’
/usr/bin/i686-w64-mingw32-ld: /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/connect.c:598: undefined reference to crypto_secretstream_xchacha20poly1305_push' /usr/bin/i686-w64-mingw32-ld: CMakeFiles/ziti_dll.dir/objects.a(connect.c.obj): in function establish_crypto’:
/home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/connect.c:692: undefined reference to crypto_kx_client_session_keys' /usr/bin/i686-w64-mingw32-ld: /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/connect.c:694: undefined reference to crypto_kx_server_session_keys’
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/ziti_dll.dir/objects.a(connect.c.obj): in function send_crypto_header': /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/connect.c:710: undefined reference to crypto_secretstream_xchacha20poly1305_headerbytes’
/usr/bin/i686-w64-mingw32-ld: /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/connect.c:714: undefined reference to crypto_secretstream_xchacha20poly1305_init_push' /usr/bin/i686-w64-mingw32-ld: /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/connect.c:716: undefined reference to crypto_secretstream_xchacha20poly1305_headerbytes’
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/ziti_dll.dir/objects.a(connect.c.obj): in function conn_inbound_data_msg': /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/connect.c:823: undefined reference to crypto_secretstream_xchacha20poly1305_init_pull’
/usr/bin/i686-w64-mingw32-ld: /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/connect.c:832: undefined reference to crypto_secretstream_xchacha20poly1305_pull' /usr/bin/i686-w64-mingw32-ld: CMakeFiles/ziti_dll.dir/objects.a(connect.c.obj): in function ziti_channel_start_connection’:
/home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/connect.c:1040: undefined reference to crypto_kx_keypair' /usr/bin/i686-w64-mingw32-ld: CMakeFiles/ziti_dll.dir/objects.a(posture.c.obj): in function hash_sha512’:
/home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/posture.c:870: undefined reference to crypto_hash_sha512_bytes' /usr/bin/i686-w64-mingw32-ld: /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/posture.c:886: undefined reference to crypto_hash_sha512_init’
/usr/bin/i686-w64-mingw32-ld: /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/posture.c:901: undefined reference to crypto_hash_sha512_update' /usr/bin/i686-w64-mingw32-ld: /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/posture.c:904: undefined reference to crypto_hash_sha512_final’
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/ziti_dll.dir/objects.a(posture.c.obj): in function check_running': /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/posture.c:937: undefined reference to QueryFullProcessImageNameA’
collect2: error: ld returned 1 exit status
make[2]: *** [_deps/ziti-sdk-c-build/library/CMakeFiles/ziti_dll.dir/build.make:417: _deps/ziti-sdk-c-build/library/ziti.dll] Error 1
make[1]: *** [CMakeFiles/Makefile2:1741: _deps/ziti-sdk-c-build/library/CMakeFiles/ziti_dll.dir/all] Error 2
make: *** [Makefile:171: all] Error 2

thanks

I tried using the toolchains file and get a slightly different error

# install mingw-w64:
sudo apt install mingw-w64

# make/cd the build folder
mkdir build
cd build

# gen the project using cmake and the toolchain file
cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchains/Windows-x86.cmake

# cmake build
cmake --build .

Error I see is at

[ 69%] Generating zlib1rc.obj
/bin/sh: 1: windres: not found
make[2]: *** [_deps/zlib-build/CMakeFiles/zlib.dir/build.make:62: _deps/zlib-build/zlib1rc.obj] Error 127
make[1]: *** [CMakeFiles/Makefile2:1571: _deps/zlib-build/CMakeFiles/zlib.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

@ekoby - can you take a look?

Oh and I just noticed I was building the sdk-c not the tunneler-sdk-c - my bad.

Thanks Clint, as a side note I have also had to fix following in order to be able to compile, not sure if it is something that needs to get fixed from your side or not:

In file included from /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/ziti-socket.c:33:
/home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/…/includes/ziti/socket.h:31:10: fatal error: WinSock2.h: No such file or directory
31 | #include <winSock2.h>
| ^~~~~~~~~~~~

Edited:
vi /home/daniel/ZITI/ziti-tunnel-sdk-c/build/_deps/ziti-sdk-c-src/library/…/includes/ziti/socket.h

Changed:
#include <WinSock2.h>
to read
#include <winsock2.h>

also have had to copy

cp _deps/wintun-src/bin/x86/wintun.dll _deps/wintun-src/bin/

as wintun was missing

I can’t replicate the issue you’re seeing @Danieleb . On my Ubuntu 20 install with cmake 3.16.3 i can generate the project fine with:

cmake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ WIN32 ..

However running just make or cmake --build . both produce the same error for me:

ziti-tunneler-sdk-c/build$ make
make: *** No targets specified and no makefile found.  Stop.

ziti-tunneler-sdk-c/build$ cmake --build .
make: *** No targets specified and no makefile found.  Stop.

I ended up being able to build using:

cmake -DCMAKE_SYSTEM_NAME=Windows --build .

I was going to ask you the wintun dll question too :slight_smile: We only build using a windows build machine in GitHub actions. I don’t know if anyone has tried crosscompiling from Ubuntu for windows yet.

I’ll do what you have tried as well and see if i can get to the same place you’re at

I added an issue to ziti-sdk-c: cross compile from Linux to Win32 fails (using toolchains/Window-x86.cmake) · Issue #390 · openziti/ziti-sdk-c · GitHub
feel free to add additional details

Problem manifests while using

Ubuntu 21.0.4 64bit
cmake version 3.18.4