如何在ubuntu 12.04中链接C/C++项目中的库

How to link library in C/c++ project in ubuntu 12.04

本文关键字:C++ 项目 链接 ubuntu      更新时间:2023-10-16

我尝试安装libantlr3c-3.4。当我运行sudo make install时,它成功地安装了它,并给出了以下输出:

libtool: install: /usr/bin/install -c .libs/libantlr3c.so /opt/open64/lib/libantlr3c.so
libtool: install: /usr/bin/install -c .libs/libantlr3c.lai /opt/open64/lib/libantlr3c.la
libtool: install: /usr/bin/install -c .libs/libantlr3c.a /opt/open64/lib/libantlr3c.a
libtool: install: chmod 644 /opt/open64/lib/libantlr3c.a
libtool: install: ranlib /opt/open64/lib/libantlr3c.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/sbin" ldconfig -n /opt/open64/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /opt/open64/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

之后,我在另一个项目上运行make,这给了我以下错误:

 fatal error: antlr3.h: No such file or directory

我试图将路径/opt/open64/lib粘贴到/etc/ld.so.conf中,其中包含以下信息:

include /etc/ld.so.conf.d/*.conf
include /opt/open64/lib

我再次运行make,再次出现同样的错误。

我是C的新手,也是设置库路径的新手。有人能指导我如何做我的项目吗。

我用于安装libantlr3c-3.4的程序是:

tar -xzvf libantlr3c-3.4.tar.gz
./configure
make 
make install

编译器不知道.h在哪里。编译时,必须告诉它在哪里查找。来自命令行:

   gcc -I path_to_where_h_file_lives myFile.cpp