Welcome to ClientVPS Mirrors

Accessing 3rd-Party Libraries

Accessing 3rd-Party Libraries

Introduction

When linking to a third party library it will often be necessary to explicitly specify a number of things:

Example: Linking to zlib

#include <R.h>
#include <Rinternals.h>
#include "zlib.h"
  
SEXP get_zlib_version(void) {
  // const char * ZEXPORT zlibVersion(void);
  return mkString(zlibVersion());
}
Click to show R code
code = r"(
#include <R.h>
#include <Rinternals.h>
#include "zlib.h"
  
SEXP get_zlib_version(void) {
  // const char * ZEXPORT zlibVersion(void);
  return mkString(zlibVersion());
}
)"

callme::compile(code)
# Compile the code with explicit link to library
compile(code, PKG_LIBS = "-lz")
# Call the function
get_zlib_version()
#> [1] "1.2.12"

Possible variations

# include a search path for the library
compile(code, PKG_LIBS = "-L/local/libs -lz")

# Include a search path for the header
compile(code, PKG_LIBS = "-lz", PKG_CPPFLAGS = "-I/usr/local/include")

# Link to a drop-in replacement
compile(code, PKG_LIBS = "-lzlibng")

# Use "pkg-config" to automatically determine appropriate flags
compile(code, PKG_LIBS = "`pkg-config --libs zlib`", 
        PKG_CPPFLAGS = "`pkg-config --cflags zlib`")

Need a high-speed mirror for your open-source project?
Contact our mirror admin team at info@clientvps.com.

This archive is provided as a free public service to the community.
Proudly supported by infrastructure from VPSPulse , RxServers , BuyNumber , UnitVPS , OffshoreName and secure payment technology by ArionPay.