简体   繁体   English

如何将要在C ++中使用的C库的库路径添加到环境中

[英]How do I add library paths of C libraries that I want to use in C++ to the environment

I want to use the VLFeat Libaries in C from a C++ file. 我想从C ++文件使用C中的VLFeat库。 Their tutorial for g++ presents a basic "Hello World" example which is compiled as follows: 他们的g ++教程提供了一个基本的“ Hello World”示例,其示例如下所示:

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: 我现在想要的是将库添加到我的.bashrc中,因此我不需要额外的标志:

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: 这是教程中的“ Hello World”代码:

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 VLFeat库链接: 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. 从“此C文件包括此标头”到“我最好将此程序与该库链接”之间没有魔术映射,它不能那样工作。

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 . 我可以用一个unwind-mess.h标头创建一个库,该标头声明在三个不同的库文件中实现的函数,然后调用库libcream.alibmeringue.alibberry.a

You still need the -lvl option to tell the compiler there's extra library code that needs to be linked against. 您仍然需要-lvl选项来告诉编译器还有一些需要链接的库代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM