Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
Hi All, I am getting "Segmentation fault (core dumped)" error in the runtime. I am new this linux please can you tell me why is that i am getting this ...
  1. #1
    Just Joined!
    Join Date
    Jun 2009
    Posts
    12

    Segmentation fault (core dumped)

    Hi All,

    I am getting "Segmentation fault (core dumped)" error in the runtime. I am new this linux please can you tell me why is that i am getting this error and I am not sure of my compilation :

    gcc -c avc_test.c
    gcc -c md5.c
    gcc avc_test.o md5.o -shared -Llibcoreavc_sdk.so -o proj

    ./proj

    error: Segmentation fault (core dumped)

    thanks
    fido

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    You have a memory error in your application. Compile it all with the -g flag to enable debugging of the executable. Then you can run it in the debugger and see where the bad memory access (usually accessing a null pointer) is occuring. Run the program in the debugger with the command: gdb ./proj
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Jun 2009
    Posts
    12
    Hi,
    My program is getting crashed before it starts (function declaration). I am thinking that program is allocated in 0x00000001 memory location. Is there any way that i can set up the memory location in program memory.Here is the code and debug results


    prompt> gcc -g avc_test.c md5.c -shared -L libcoreavc_sdk.so -o proj
    prompt> gdb ./proj

    GNU gdb Red Hat Linux (6.3.0.0-1.62rh)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".

    (gdb) run
    Starting program: /usr/local/projects/mflo/codec3/users/nshivash/core player/proj

    Program received signal SIGSEGV, Segmentation fault.
    0x00000001 in ?? ()

    (gdb) list
    6
    7
    8 static void update(FILE* raw,md5_ctx* md5,const uint8_t* buf,size_t size);
    9 static void updateframe(avc_decode* avc,FILE* raw,md5_ctx* md5,constplanes frame);
    10 static int decode(FILE* in, FILE* raw, uint8_t digest[16]);
    11
    12
    13 int main(void)
    14 {
    15 int dump = 0;
    (gdb)


    And here is the code:
    ------------------------------------------------------------------------------------------------
    #include "base.h"
    #include "md5.h"
    #include "avc.h"
    #include <stdio.h>


    static void update(FILE* raw,md5_ctx* md5,const uint8_t* buf,size_t size);
    static void updateframe(avc_decode* avc,FILE* raw,md5_ctx* md5,constplanes frame);
    static int decode(FILE* in, FILE* raw, uint8_t digest[16]);


    int main(void)
    {
    int dump = 0;
    int create = 0;
    FILE* f;
    const char* list = "regression";
    int i;

    -------------------------------------------------------------------------------------------------------
    thanks
    fido

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Just a swag, but try renaming your variable "dump" to something else. It may be that there is a macro that redefines "dump" to something wonky.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Jun 2009
    Posts
    12
    Hi ,

    I got the problem it is because of the shared object file (library file). I am not sure how to link this file. Currently i am linking this way

    " prompt> gcc -g avc_t.c md5.c -shared -L libcoreavc_sdk.so -o proj "

    if i remove all the function call in the avc_t.c to libcoreavc_sdk.so and remove the libcoreavc_sdk.so linking, it is working fine.

    " prompt> gcc -g avc_t.c md5.c -o proj " -- this works fine...

    If i include the library or shared object i am getting "segemenation fault"

    please let me know is this the correct way to link the .so file. And also how to resolve this issue.

    Thanks
    fido

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Well, you need to add the directory of the shared file to your LD_LIBRARY_PATH environment variable. Also, try this to link the file:
    Code:
    gcc _avc_test.o md5.o -L . -l coreavc_sdk -o proj
    I don't think you need the -shared directive unless you also have a libname.a in the same directory, and even not then, since by default gcc will link a shared library before the static one. You would use the -static directive if you had both and needed to link to the static library.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #7
    Just Joined!
    Join Date
    Jun 2009
    Posts
    12
    Thanks for your reply,

    I hope that i am not bugging you with too many questions...

    I did the same way and now i am getting some error

    prompt> gcc avc_test.o md5.o -L./lib -l coreavc_sdk -o proj
    /usr/bin/ld: warning: libstdc++.so.6, needed by ./lib/libcoreavc_sdk.so, not found (try using -rpath or -rpath-link)

    ./lib/libcoreavc_sdk.so: undefined reference to `__stack_chk_fail@GLIBC_2.4'
    collect2: ld returned 1 exit status


    Thanks
    fido

  8. #8
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Ok. You're getting more information now. Did you build the libcoreavc_sdk.so library, or did you get that from somewhere else? If you got it from somewhere else, then it was created with a version of the stdc++ library your system doesn't have. You might need to build it yourself if that is the case, so that it is linked with your system's resources.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  9. #9
    Just Joined!
    Join Date
    Jun 2009
    Posts
    12
    I have no idea about coding in linux I am having some experience in Visual c++ and visual studio.

    I some how manged to install Ubuntu in my pc and there libstdc++.so.6 was there and it is compiling and able to generate executable file"proj", but if i run the proj it show error in runtime

    ./proj: error while loading shard libraries: libcoreavc_sdk.so: cannot open shared object file: No such file or directory

    I believe the problem is that i need to add the directory of the shared file to LD_LIBRARY_PATH environment variable, but i don't now how to do this.... I searched online it tells me some bashrc... which i am not able to understand.

    my library is in project folder inside lib folder i.e.,

    current_project/lib/libcoreavc_sdk.so

    please can you help me out with this

    thanks
    fido

  10. #10
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    First, try setting your LD_LIBRARY_PATH variable in the shell where you are trying to run the executable:
    Code:
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:path_to_library
    Replace path_to_library with the directory path that contains the shared library. Finally, try to run the program. If it runs, then add the export command as shown to ~/.bash_profile - that is your user account's shell script that is loaded when you log in. Then, logout and log back in. You can then check to see if LD_LIBRARY_PATH is properly set up with the command: echo $LD_LIBRARY_PATH
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Page 1 of 2 1 2 LastLast

Posting Permissions

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