我如何链接到libtool静态图书馆? [英] How do I link against libtool static la library?

查看:160
本文介绍了我如何链接到libtool静态图书馆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功汇编此库。它生成一个 libcds2.la 文件,我试图链接到我自己的项目。我有所有文件(包括 .h 文件)在我的项目文件在同一目录。当我尝试链接和使用所述库的功能时,使用:

I have compiled this library successfully. It generates a libcds2.la file that I am trying to link into my own project. I have all files (including the .h file) in the same directory as my project file. When I try to link and use the functions of said library, using:

g++ -o test -I/opt/include/ -L/opt/lib/ -lcds2 libcdsNoptrs.cpp util.cpp

>

comes back with

./test: error while loading shared libraries: libcds2.so.2: 
      cannot open shared object file: No such file or directory

。但关键是,大多数时候它只是不认识图书馆。我假设我做错了文件路径,但不能弄清楚。我的测试文件是一个C ++文件,包括 #includelibcds2 / array.h,一切安装在 opt / lib opt / include ,ugly,我知道,但这是Makefile生成的。

whatever that is. But the point is that most of the time it just doesn't recognize the library. I assume I'm doing something wrong with the file paths, but can't figure it out. My test file is a C++ file including #include "libcds2/array.h" and everything is installed in opt/lib, opt/include, ugly, I know, but that's what the Makefile generated.

任何指针?

推荐答案

libtool .la 是一个元数据文件。在构建 cds2 库之后,期望libtool也将以链接模式使用以构建任何软件包的测试等。

The libtool .la is a 'meta data' file. After building the cds2 library, it's expected that libtool will also be used in 'link' mode to build any of the package's tests, etc.

通常,在目录中找到 .la 文件,你会发现 .a .libs 子目录下的 .so .libs / libcds2.a 文件将在那里找到, configure --enable-static 选项(或默认情况下启用)。但是,我的理解是,您已在 / opt 中安装了该软件包:

Typically, the in the directory you find the .la file, you will find the .a and .so under the .libs subdirectory. The .libs/libcds2.a file will be found there, provided configure was given the --enable-static option (or it is enabled by default). But, my understanding is that you've installed the package in /opt :

g++ -I/opt/include/ libcdsNoptrs.cpp util.cpp -o test /opt/lib/libcds2.a

否则,如果未安装 libcds2 ,只需提供一个路径: ... / libcds2 / lib /。 libs / libcds2.a

Otherwise, if libcds2 isn't installed, just supply a path to: .../libcds2/lib/.libs/libcds2.a

除非您要在 - link 模式与 -static 来处理一切。但是学习libtool的优点通常是一个下雨天的练习:)

Unless you want to use libtool in --link mode with -static to handle everything. But learning the advantages of libtool is usually an exercise for a rainy day:)

这篇关于我如何链接到libtool静态图书馆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆