flexInit() Stack Smashing

I am somewhat new to cuda development, but I am have been unable to use flexInit() on any version of Flex that I try (0.8, 1.0, 1.1) without getting a Stack Smashing Error. I am Using Ubuntu 18.04, I have a GT 710, I have installed libcuda1-384, libcudart9.1, libnvidia-compute-390, the nvidia-390 driver, nvidia-common, I have linked against flexRelease, flexExt, cuda, and cudart libraries, but I have been unable to avoid this error at flexInit(). I have the c++ code for flex 0.8 here:

#include <cuda.h>
#include <cuda_runtime_api.h>

#include “flex.h”
#include “flexExt.h”


int pCudaDeviceCount;
int cudaDeviceCount;
int cudahostDevice;
CUcontext flexCudaCtx;

int main(){

if (pCudaDeviceCount > 0){
    bool CUDA_GPU_PRESENT = true;
    printf("CUDA devices present!\n");
    printf("Number of Cuda Devices: %i\n", pCudaDeviceCount);

    printf("Getting Host Thread CUDA Device!: %i\n", cudahostDevice);

    cuCtxCreate(&flexCudaCtx, CU_CTX_SCHED_AUTO, cudahostDevice);
    printf("Creating CUDA Ctx!\n");



return 0;


Any advice would be greatly appreciated,