c++ - 缺少共享库(g++ 编译)

标签 c++ linux g++ shared-libraries

好的。所以我有使用 GMP 库的简单应用程序。这是代码:

#include <gmp.h>
#include <iostream>

using std::cout;
using std::endl;


int main(int argc, char** argv)
{
    int number=100;
    mpz_t a; mpz_init(a);
    mpz_t b; mpz_init(b);
    mpz_set_ui(b, 1);
    cout<<a<<endl;
    for (; number>0; number--)
    {
        cout<<b<<endl;
        mpz_add(b,b,a);
        mpz_sub(a,b,a);
    }
    mpz_clear(a);
    mpz_clear(b);
}

我选择 g++ main.cpp -o app -lgmpxx -lgmp。编译有效,我的意思是没有错误。然后我去 ./app ,这是显示的内容:

enter image description here

好吧,但为什么呢?我的 /usr/local/lib 看起来像这样:

enter image description here

我做错了什么吗?

最佳答案

试试这个:

g++ -L/usr/local/lib main.cpp -o app -lgmpxx -lgmp

您还可以将(作为 sudo)路径添加到/etc/ld.so.conf 中,然后运行(也作为 sudo)ldconfig,以重建缓存。要查看您的库是否已正确添加,请使用此命令:

ldconfig -p | grep libgmp

关于c++ - 缺少共享库(g++ 编译),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35833474/

相关文章:

linux - 在 Windows 编译器、cygwin 和 linux g++ 之间使用编译的库

C++理解循环双向链表

linux - 如何列出未 merge 到给定分支的 `git` 分支?

php - Magento - cron 作业脚本正在运行,但 Magento 订单确认电子邮件未发送

linux - copy_to_user 在 linux 内核版本 4.12.8 中未定义

c++ - 为什么在 C++ 中会发生这种情况?

linux - 在 CentOS5 Box 上运行 Ubuntu 12.04 编译的 C++ 程序

c++ - 使用 IF 语句比使用异常处理更便宜?

c# - 从 C# 调用不安全的 C++ 时出现 System.AccessViolationException

c++ - QLabel 从文件加载图像