Sublime Forum

Strange `undefined reference` error coming from ArrayFire (ST3 for C++ editor/compiler)

#1

I have a simple C++ script titled “helloworld.cpp”:

#include "arrayfire.h"
#include <stdio.h>

using namespace std;
using namespace af;

int main(void)
{
    af::array a = af::randu(10000);
    return 0;
}

For brevity, my .sublime-build is included below. I am using ST3 as my C++ editor and compiler. When I try to use ArrayFire to create a simple aray of random numbers, I am getting a couple weird errors:

C:\WINDOWS\TEMP\ccSsW23x.o:helloworld.cpp:(.text+0x27): undefined reference to `_imp___ZN2af5randuEi8af_dtype'
C:\WINDOWS\TEMP\ccSsW23x.o:helloworld.cpp:(.text+0x39): undefined reference to `_imp___ZN2af5arrayD1Ev'
collect2.exe: error: ld returned 1 exit status

A Google search returns nothing on the weird imp errors, and I believe I have included all correct folders, and properly defined my library folder. Any clues as to what is going on? Or suggestions on how to solve it?

My .sublime-build file is as follows:

{
    "cmd": ["g++", "-Wall", "-Wextra", "-std=c99", "${file}", "-o", "${file_path}/${file_base_name}", "-I", "C:/Program Files/ArrayFire/v3/include", "-I", "C:/Program Files/ArrayFire/v3/include/af"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",

    "variants":
    [
        {
            "name": "Run",
            "shell_cmd": "g++ \"-Wall\" \"${file}\" -o \"${file_path}/${file_base_name}\" -I \"C:/Program Files/ArrayFire/v3/include\" -I \"C:/Program Files/ArrayFire/v3/include/af\" -I \"C:/Program Files/ArrayFire/v3/include/fg\" -I \"C:/package/armadillo74002/include\" -L \"C:/Program Files/ArrayFire/v3/lib\""
        }
    ]
}
0 Likes

#2

I’m not familiar with ArrayFire, but from the looks of your command line you’re missing a -l directive. -L tells the linker where to look for libraries to link with, but -l tells the linker to actually include the library. A symptom of this is the linker telling you about an “undefined reference” (the fact that it is C++ is the reason why the symbol that’s missing is so mangled).

From the looks of this URL (in the section on Makefiles at the bottom) you want to include something like -laf or some derivation thereof to include the appropriate library depending on what back end you’re trying to use.

0 Likes