I want to use the VLFeat Libaries in C from a C++ file. Their tutorial for g++ presents a basic "Hello World" example which is compiled as follows:
g++ main.cpp -o vlfeat-test -I /disk/no_backup/lesi/vlfeat-0.9.20/ -L /disk/no_backup/lesi/vlfeat-0.9.20/bin/glnxa64/ -lvl
This works fine. What I want now is to add the library to my .bashrc, so I don't need the extra flags:
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/disk/no_backup/lesi/vlfeat-0.9.20
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/disk/no_backup/lesi/vlfeat-0.9.20/bin/glnxa64
and use it like this:
g++ main.cpp -o vlfeat-test
Unfortunately I get the following error:
/tmp/cc6tzB55.o: In function `main':
main.cpp:(.text+0x10): undefined reference to `vl_get_printf_func'
collect2: error: ld returned 1 exit status
What am I doing wrong?
Here's the "Hello World" code from the tutorial:
extern "C" {
#include <vl/generic.h>
}
int main (int argc, const char * argv[]) {
VL_PRINT ("Hello world!\n") ;
return 0;
}
VLFeat Library Link: http://www.vlfeat.org/index.html
You specify where to find the header, but you don't tell the compiler to link against the library.
There is no magic mapping from "this C file included this header" to "I better link this program with this library", it doesn't work like that.
I could make a library with a single unwind-mess.h
header, that declares functions implemented in three different library files, and call the libraries libcream.a
, libmeringue.a
and libberry.a
.
You still need the -lvl
option to tell the compiler there's extra library code that needs to be linked against.