相关疑难解决方法(0)

静态库和共享库之间的区别?

静态库和共享库有什么区别?

我使用Eclipse,有几种项目类型,包括静态库和共享库?一个人比另一个人有优势吗?

c c++ shared-libraries static-libraries

533
推荐指数
8
解决办法
22万
查看次数

在编译和链接C++文件时关于-ldl标志

参考以下代码

test_linker.cpp

int main() {

    srand(time(0));
    for (int i = 0; i < 10; ++i) {
        cout << rand() % 10 << endl;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

urandom.cpp

#include <iostream>
using std::cout;
using std::endl;
#include <dlfcn.h>

int rand() throw() {

    // get the original rand() function
    static auto original_rand = (decltype(&rand)) dlsym(RTLD_NEXT,"rand");

    cout << "Call made to rand()" << endl;
    return original_rand();
}
Run Code Online (Sandbox Code Playgroud)

当我尝试使用以下命令编译代码时

g++ -std=c++11 -Wall -Werror -Wextra -Wvla -pedantic -O3 urandom.cpp -c
g++ -std=c++11 -Wall -O3 test_linker.cpp urandom.o …
Run Code Online (Sandbox Code Playgroud)

c++ linux dynamic-linking c++11

9
推荐指数
1
解决办法
9228
查看次数