Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, I'm developing an application in C++ that uses pthread for a small linux distro called brazil firewall and router, it (the distro) uses uclibc... I'm using the build tree ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2009
    Posts
    2

    pthread dynamically linked = segmentation fault


    Hi, I'm developing an application in C++ that uses pthread for a small linux distro called brazil firewall and router, it (the distro) uses uclibc...

    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
    This doesn't:
    Code:
     c++ mypcap.cpp -pthread -lpcap -o myapp
    Doesn't matter how complex is the app, if just call pthread_create and put a "cout << "hello" << endl;" in the callback function it crashes with a segmentation fault...

    Hope some one can help me to solve this.

  2. #2
    Linux Guru Rubberman's Avatar
    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
    11,709
    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!

  3. #3
    Linux Newbie tetsujin's Avatar
    Join Date
    Oct 2008
    Posts
    117
    What are you providing as the arguments to pthread_create()?
    When you included pthread.h, did you put it in an extern "C" block?

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    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.

  6. #5
    Linux Newbie tetsujin's Avatar
    Join Date
    Oct 2008
    Posts
    117
    Quote Originally Posted by Cavernicola View Post
    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.
    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.

  7. #6
    Linux Guru Rubberman's Avatar
    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
    11,709
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •