静态库和共享库有什么区别?
我使用Eclipse,有几种项目类型,包括静态库和共享库?一个人比另一个人有优势吗?
参考以下代码
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)