0

I am writing a C program which uses libext2fs:

#include <ext2fs/ext2fs.h>

int main(int argc, char *argv[]) 
{ 
    char *fsname = argv[1];
    errcode_t err;
    ext2_filsys fs;

    err= ext2fs_open(fsname, 0, 0, 0, unix_io_manager, &fs);

When I compile the program I get following errors:

$ gcc -lext2fs fstest.c -o fstest
/tmp/ccXCSICx.o: In function `main':
openfs.c:(.text+0x1e): undefined reference to `unix_io_manager'
openfs.c:(.text+0x43): undefined reference to `ext2fs_open'
collect2: error: ld returned 1 exit status

System:

  • Ubuntu 12.10
  • gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
  • e2fsprogs, e2fslibs, e2fslibs-dev: 1.42.5-1ubuntu2
  • Smells like you are missing some libraries on the link line. And the provided program won't even compile, BTW. – vonbrand Mar 12 '14 at 14:15
  • enedil@archlinux ~ % cat fstest.c #include <ext2fs/ext2fs.h> int main(int argc, char *argv[]) { char *fsname = argv[1]; errcode_t err; ext2_filsys fs; err= ext2fs_open(fsname, 0, 0, 0, unix_io_manager, &fs); return 0; } enedil@archlinux ~ % gcc -lext2fs fstest.c -o fstest enedil@archlinux ~ % ./fstest [1] 1545 segmentation fault (core dumped) ./fstest You're missing some libraries. Do you have build-essential installed? – enedil Mar 12 '14 at 14:30
  • I have to wait for 8 hours before I can answer my own question, because of newbie restrictions. Will do when the waiting period is over. – goose999 Mar 12 '14 at 15:08
0

Got the solution in the e2fsprogs sourceforge forums. I had to put -lext2fs to the end of the line:

gcc fstest.c -o fstest -lext2fs

With this command it compiles now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.