home archives github knives links
tags cmake vlfeat
categories
only title title and content
vlfeat笔记

cpp(Linux)

官方C API

参考:https://www.vlfeat.org/gcc.html

/etc/ld.so.conf.d/下任意一个文件(如opencv.conf)添加so库(例如libvl.so)的路径,然后sudo ldconfig

extern "C" {
#include
}

int main (int argc, const char * argv[]) {
VL_PRINT ("Hello world!") ;
return 0;
}
g++ vl_test.cpp -o test -I$(VL) -L$(VL)/bin/glnxa64 -lvl

编译

单独使用sift模块

使用源文件

  1. 保留vl目录下所有文件
  2. 保留src下的sift.cgeneric-driver.h
  3. 注释host.h部分代码(约665行)
    /* Linux: limit glibc to old versions for compatibility */
    // #if defined(VL_COMPILER_GNUC) & defined(VL_OS_LINUX) & ! defined(__DOXYGEN__)
    // __asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
    // #endif
  4. vl下创建一个头文件fuck.h
    #define FUCK_H

    #define VL_DISABLE_AVX
    #define VL_DISABLE_SSE2
  5. vl下的host.h,imopv_sse2.c头部添加
    #if ! defined(FUCK_H)
    #include "fuck.h"
    #endif
  6. CMakeLists.txt编写
    # vlfeat
    set(vlfeat_dir /home/lynx/fuck_mount/vlfeat/vlfeat_android)
    include_directories(${vlfeat_dir})
    aux_source_directory(/home/lynx/fuck_mount/vlfeat/vlfeat_android/src vl_src)
    aux_source_directory(/home/lynx/fuck_mount/vlfeat/vlfeat_android/vl vl_head)
    add_library(
    vlfeat_lib

    SHARED

    ${vl_src}
    ${vl_head}
    )

    # 添加目标文件/目标库
    add_executable(
    entry

    source.cpp )

    # 连接库文件
    target_link_libraries(
    entry

    ${OpenCV_LIBS}
    # ${vlfeat_lib}
    vlfeat_lib
    )

常见错误

  1. 找不到libiomp5.so
apt-file search libiomp5.so
sudo apt install libomp-7-dev
  1. cc1报错:…不是目录

解除挂载的硬盘,make clean后重新编译

  1. 编译错误
vl/mathop.h:92:37: error: ‘vl_infinity_d’ not specified in enclosing ‘parallel’
92 | #define VL_INFINITY_D (vl_infinity_d.value)

解决: /vl/kmeans.c(参考)

// #pragma omp parallel default(none)
#pragma omp parallel \
  1. matlab模块错误

如果安装了texlive,那么makefile在检测时会把pdftex检测为matlab,直接把make/matlab.mak内容清空即可