Integrate P4 API for Go on Linux

To integrate P4 API for Go on Linux, follow these steps:

Download the relevant files

Depending on the version of Linux you are using determines which files you need to download.

P4 API for C/C++ for Linux x86_64

For Linux x86_64, the P4 API for C/C++ file to download is called p4api-glib<GLIBVER>-openssl<SSLVER>.tgz where:

  • <GLIBVER> is the GLib library version number.

  • <SSLVER> is the OpenSSL version number.

For a Linux x86_64 operating system with GLib library version 2.12 and OpenSSL 3, you would need the following P4 API for C/C++ version: p4api-glibc2.12-openssl3.tgz.

If you are Integrating P4 API for Go 2025.1, search the r25.1 directory in the Perforce archive to find the version of P4 API for C/C++ to download.

In this example, the version of P4 API for C/C++ for Linux x86_64 is found in the following location:

http://ftp.perforce.com/perforce/r25.1/bin.linux26x86_64/p4api-glibc2.12-openssl3.tgz

Use the command line to find the version numbers for GLib library and OpenSSL

To find GLib library version installed on your system, enter ldd --version into the command line. Then use a number that is less than or equal to the returned value. For example, if ldd --version returns 2.23, search the archive for the P4 API for C/C++ that has GLib library version number up to, and including, 2.23, which in this example would be glibc2.23.

To find the OpenSSL version installed on your system, enter openssl --version into the command line.

P4 API for C/C++ for Linux aarch64

For Linux aarch64, the P4 API for C/C++file to download is called p4api-openssl<SSLVER>.tgz where:

  • <SSLVER> is the OpenSSL version number.

For example, for OpenSSL 3, you would need the following P4 API for C/C++ version: p4api-openssl3.tgz.

If you are Integrating P4 API for Go 2025.1, search the r25.1 directory in the Perforce archive to find the version of P4 API for C/C++ to download.

In this example, the version of P4 API for C/C++ for Linux aarch64 is found in the following location:

http://ftp.perforce.com/perforce/r25.1/bin.linux26aarch64/p4api-openssl3.tgz

Build OpenSSL libraries

When you have the relevant version of P4 API for C/C++, ensure that you have pre-built binaries that are tailored for your specific platform. For Linux, ensure that the libssl-dev package is installed.

Unpack archives and configure build flags

Configure the following build flags in the terminal.

Copy
go env -w CGO_CPPFLAGS="-I<absolute path to P4 API for C++>/include -g"
go env -w CGO_LDFLAGS="-L<absolute path to P4 API for C++>/lib -lp4api -lssl -lcrypto"

Replace:

  • <absolute path to P4 API for C++> with the absolute path to the P4 API for C/C++.