c++ - 如何编译和链接 cddlib 库?

标签 c++ ubuntu static-linking

我想启动一个小的 c++ projekt,它使用我在目录中安装(加上 GMP)的库 cddlib(http://www.inf.ethz.ch/personal/fukudak/cdd_home/cdd.html)

/some/path/to/libcdd/

在不同的目录中,我有一个包含内容的ma​​in.cpp文件

#include "setoper.h"
#include "cdd.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>

int main()
{
  fprintf(stdout, "start\n");

  dd_set_global_constants();  
  dd_free_global_constants();

  fprintf(stdout, "done\n");

  return 0;
}

这里,两个函数 dd_... 是库 cddlib 中的函数。我尝试使用(天真的?)命令编译它

g++ -o out main.cpp

然而,这产生了

/tmp/ccF7dx0W.o: In function `main':
main.cpp:(.text+0x28): undefined reference to `dd_set_global_constants'
main.cpp:(.text+0x2d): undefined reference to `dd_free_global_constants'
collect2: error: ld returned 1 exit status

通话也是如此

g++ -L/some/path/to/libcdd/lib -I/some/path/to/libcdd/include -lcdd main.cpp

这只是一个愚蠢的错误吗?我正在使用带有 g++ 4.8.2 的 Ubuntu 14.04。

最佳答案

首先,将 cdd-path 添加到您的包含:

#include <cdd/setoper.h>
#include <cdd/cdd.h>

接下来使用如下编译:

g++ -o exe main.cpp -lcdd

如果库在系统库目录中,则不需要其他任何东西。

注意:-lcdd 必须是编译器命令行的最后一个参数才能正常工作。

希望这对你有用。

关于c++ - 如何编译和链接 cddlib 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28268167/

相关文章:

c++ - 使用 EncodePointer/DecodePointer 的好处

c++ - 1.6 的 SFML pollEvent(等效项)

c++ - Win32 应用程序 LNK2001 : unresolved external symbol _main

c++ - 不同机器之间标准时钟的显着性能差异

c++ - Boost Overload 奇怪的行为.. `int (int ), int (std::string )` 与 `int (int ), int (std::string ), std::string (std::string)` 有何不同?

c++ - 在模板类中声明模板成员变量在 Xcode 中不起作用

python - CentOS 在随机时间运行 python 脚本

mysql - 无法使用 qt 4.8.5 和 Ubuntu 12.04 连接到 mariadb 数据库服务器

linux - 基本Unix复习查询: ls -ld

静态库中与 std::string 相关的 C++ undefined symbol