Find the answer to your Linux question:
Results 1 to 4 of 4
Code: #include "cgnslib.h" main() { int fn; cg_open("demo.cgns",CG_MODE_WRITE,&fn); cg_close(fn); } Output of the program: /tmp/ccYWbQxX.o: In function `main': demo.c .text+0x2 : undefined reference to `cg_open' demo.c .text+0x33): undefined reference to ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Posts
    2

    undefined reference to 'function' error in gcc

    Code:
    #include "cgnslib.h"
    
    main()
    {
    	int fn;
    	cg_open("demo.cgns",CG_MODE_WRITE,&fn);
    	cg_close(fn);
    }
    Output of the program:


    /tmp/ccYWbQxX.o: In function `main':
    demo.c.text+0x2: undefined reference to `cg_open'
    demo.c.text+0x33): undefined reference to `cg_close'
    collect2: ld returned 1 exit status


    Thanks.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    At compile time, the #include "cgnslib.h" lets the compiler know what the calling interface for each function in the CGNS library, so the compiler can compile your calls to that library correctly.

    But at link time, the linker needs to have access to the actual compiled library; otherwise, your program doesn't include the actual CGNS code.

    I've never used CGNS, but if you've installed it correctly, you'll know where the library is stored and what it is named. You should change your gcc command to include the name (and possibly the directory path) of the compiled library. Your gcc command might look something like this:
    Code:
    gcc sample.c libgcc.a -o sample
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Jun 2008
    Posts
    2
    Thank you very much!

  4. #4
    Just Joined!
    Join Date
    Jul 2008
    Posts
    1
    wje_lf thanks a lot, we are newbies on linux, and nobody say nothing =( you information was helpfull for using libserial with anjuta <--
    just add this ==>CXX = g++ /usr/local/lib/libserial.la<== on makefile or when compile... Thanks

Posting Permissions

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