Search code examples
c++11installationhalide

Cannot find -lHalide when compiling a toy program


I've been trying to install and use Halide.

I installed Halide by doing the following:

I cloned the Halide repo then executed the following commands from the root of the repository.

mkdir build
cd build
cmake ..
sudo make install

After the installation finished, I created a file(test.cpp) in an unrelated directory with the following contents:

#include "Halide.h"  // <~~ changing this to <Halide.h> also results in the same error

#include <stdio.h>

int main() {
  return 0;
}

I try to compile it with: gcc -g -Wall -pedantic -o test test.cpp -lHalide -lpthread -ldl -std=c++11 which gives me the following eror message:

/usr/bin/ld: cannot find -lHalide
collect2: error: ld returned 1 exit status

I also tried the following with (surprisingly; given that there's no ../include or ../bin directory) the same result:

g++ test.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o test -std=c++11

Edit:

I can see that I do have a file called Halide.h under /usr/local/include/ how do I make gcc see it?


Solution

  • To compile correctly it needs a bunch of files to be "included"(not sure if this is the right terminology) as well as the environment variable LD_LIBRARY_PATH be set to the parent directory of the file libHalide.so

    The following is a Makefile that works:

    HALIDE_ROOT?=/usr/local/
    HALIDE_BUILD?=${HALIDE_ROOT}
    
    HALIDE_TOOLS_DIR=${HALIDE_ROOT}/tools/
    HALIDE_LIB_CMAKE:=${HALIDE_BUILD}/lib
    HALIDE_LIB_MAKE:=${HALIDE_BUILD}/bin
    
    HALIDE_LIB:=libHalide.so
    
    HALIDE_LIB_DIR=${HALIDE_LIB_MAKE}
    
    HALIDE_INCLUDES:=-I${HALIDE_BUILD}/include -I${HALIDE_ROOT}/tools -L${HALIDE_LIB_DIR}
    
    LIBS:=-ldl -lpthread -lz
    
    .PHONY:         clean
    
    all:        build/test
    
    CC = g++ -Wall -pedantic -O2 -g -std=c++11
    HALIDE_REQ = -lHalide -lpthread -ldl -std=c++11
    
    
    build/test:     test.cpp
        $(CC) ${HALIDE_INCLUDES} intro.cpp -o build/test ${LIBS} -lHalide
    
    
    clean:
        rm ./build/*