Results 1 to 6 of 6
|
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
-
06-03-2009 #1
- Join Date
- Jun 2009
- Posts
- 2
pthread dynamically linked = segmentation fault
I'm using the build tree (is some chroot enviroment) for that distro and when I compilled and execute the app within the build tree it works fine, but when I put the app in a pc whit that distro installed and working it just gives a segmentation fault.
This does not happen when I compile the app whit pthread statically linked.
This works fine:
Code:c++ mypcap.cpp -static -pthread -lpcap -o myapp
Code:c++ mypcap.cpp -pthread -lpcap -o myapp
Hope some one can help me to solve this.
-
06-04-2009 #2
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
- Posts
- 14,038
Try setting the LD_LIBRARY_PATH environment variable to include the path to the shared libraries.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
-
06-04-2009 #3
What are you providing as the arguments to pthread_create()?
When you included pthread.h, did you put it in an extern "C" block?
-
06-04-2009 #4
- Join Date
- Jun 2009
- Posts
- 2
Thanks Rubberman, for your help.
Thanks tetsujin, nope, I didn't have use extern "C" in the include macro of pthread.h and that did the trick!!!, now it works fine... Man I spend 2 days googling looking for any answer... I'm very happy, thanks alot.
-
06-04-2009 #5
Hey, cool, I'm glad it worked. I was just grabbing at straws, really...
Since it segfaulted only once it hit that function, I figured the dynamic linker was finding the lib OK - so I thought maybe something was wrong with the arguments. Since it works when linked in statically, it seemed like probably the arguments must be basically OK (though not necessarily - maybe doing the dynamic link somehow would cause a borderline-bad invocation to segfault?) But then also I noticed you were doing C++ - it didn't seem likely that function name mangling was the problem (if it were, then wouldn't it fail at the linking step?) but it occurred to me that it could be a C/C++ ABI issue with the structures being passed, a mismatch between the structure as constructed by the header when interpreted in C++ and C... But, then, why would it work when you do the static link? I'm not so sure about that bit...
I don't know if that was it exactly - but, whatever. It's working, that's what counts.
-
06-05-2009 #6
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
- Posts
- 14,038
Interesting. Most GNU C library headers have macros that detect when you are building for C++ and #ifdef the extern "C" directive. In any case, I just looked at pthread.h and find that it is not so implemented. Good catch tetsujin! You should post that as a bug to the pthread working group. Sorry that I don't know off-hand what the proper URL is, but you should be able to find it on the Welcome! - Free Software Foundation or The GNU Operating System web sites.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!