what's the difference between libpthread.so and libpthread.a?
Hi to everyone.
I know the short answer dynamic vs static linking, however, I need a deeper answer because I have a short, stupid test program that works as expected when dynamically linked while sigsegv inside pthread_create when statically linked.
What more?
here is the source
#include <iostream>
#include <unistd.h>
#include <pthread.h>
using namespace std;
void *run(void *arg)
{
cout << "Io sono in run\n";
int i = 0;
while(1)
{
cout << "io sono il thread " << i++ << "\n";
sleep(1);
}
}
int main(int argc, char** argv)
{
int i = 0;
for(i=1;i<argc;i++)
{
cout << argv[i] << "\n";
}
pthread_t *ilThread = (pthread_t*)malloc(sizeof(pthread_t));
cout << "Crea il thread...\n";
cout << "Crea il thread ma per davvero...\n";
cout << pthread_create(ilThread, (pthread_attr_t*)NULL, run, (void*)NULL) << "\n";
cout << "Creato il thread, entro in loop\n";
while(1)
{
cout << "io sono il main " << i++ << "\n";
sleep(1);
}
}
The distribution is fedora release 2 (kernel 2.6)
The compile command that works is:
g++ hello.cpp -lpthread -o hello
The one that does not is:
g++ hello.cpp -static -lpthread -o hello
Thanks in advance and best regards
--Mauro
|