undefined reference to "..."

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zqiang320

    #1

    undefined reference to "..."

    Hello:

    I execute make ,then get error:

    $ make
    Making all in libsbml/src
    make[1]: Entering directory `/home/internet/mydoc/test_pj/libsbml/src'
    ........
    /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o test test.o
    libsbml/src/libsbml.la -lsbml -lstdc++ -lm
    mkdir .libs
    gcc -g -O2 -o .libs/test test.o libsbml/src/.libs/libsbml.so -lstdc++
    -lm -Wl,--rpath -Wl,/usr/local/lib
    libsbml/src/.libs/libsbml.so: undefined reference to `safe_strdup'
    libsbml/src/.libs/libsbml.so: undefined reference to
    `util_bsearchSt ringsI'
    libsbml/src/.libs/libsbml.so: undefined reference to `safe_malloc'
    libsbml/src/.libs/libsbml.so: undefined reference to `util_PosInf'
    libsbml/src/.libs/libsbml.so: undefined reference to `util_isInf'
    libsbml/src/.libs/libsbml.so: undefined reference to `util_NaN'
    libsbml/src/.libs/libsbml.so: undefined reference to `safe_calloc'
    libsbml/src/.libs/libsbml.so: undefined reference to
    `strcmp_insensi tive'
    libsbml/src/.libs/libsbml.so: undefined reference to `c_locale_strto d'

    Why system can not find these function ,they are system file
    <stdlib.h<new<c math>
    which has been included in my app.c.
    What should I do?
    Eager to receive your reply!

    my configure.in file:

    AC_INIT(main, 0.1, zqiang320@gmail .com)
    AM_INIT_AUTOMAK E(foreign)
    AC_PROG_CC
    AC_PROG_CXX
    AM_PROG_LIBTOOL
    AC_OUTPUT(Makef ile libsbml/src/Makefile)

    my Makefile.am file:

    bin_PROGRAMS = test
    SUBDIRS = libsbml/src .
    test_SOURCES = test.c

    test_LDADD = libsbml/src/libsbml.la -lsbml -lstdc++ -lm

    AM_CPPFLAGS = -Ilibsbml/include

    my libsbml/src/Makefile.am

    AUTOMAKE_OPTS = gnu
    lib_LTLIBRARIES = libsbml.la
    libsbml_la_SOUR CES = common/libsbml-version.cpp math/ASTNode.cpp math/
    FormulaTokenize r.c util/List.cpp
    AM_CPPFLAGS = -I../include -lsbml -lstdc++ -lm
  • Ian Collins

    #2
    Re: undefined reference to &quot;...&qu ot;

    zqiang320 wrote:
    Hello:
    >
    I execute make ,then get error:
    >
    $ make
    Making all in libsbml/src
    make[1]: Entering directory `/home/internet/mydoc/test_pj/libsbml/src'
    ........
    /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o test test.o
    libsbml/src/libsbml.la -lsbml -lstdc++ -lm
    mkdir .libs
    >
    Why system can not find these function ,they are system file
    <stdlib.h<new<c math>
    which has been included in my app.c.
    You are building something as C++ and this is a C group. If you should
    be building as C, fix things so you do, if you are building C++ code,
    try a platform or gnu list where you will get better help. Tool
    problems are as off topic on c.l.c++ as they are here.

    --
    Ian Collins.

    Comment

    • William Pursell

      #3
      Re: undefined reference to &quot;...&qu ot;

      On 27 Sep, 04:08, zqiang320 <zqiang...@gmai l.comwrote:
      I execute make ,then get error:
      <snip>
      libsbml/src/.libs/libsbml.so: undefined reference to `safe_strdup'
      <snip>
      >
      Why system can not find these function ,they are system file
      <stdlib.h<new<c math>
      which has been included in my app.c.
      What should I do?
      Your questions are not about the C language, and you will
      get better answers if you ask elsewhere. However, this
      question indicates a fundamental misunderstandin g about
      header files and libraries. If a function is declared
      in the header and you include that header, then the
      compiler has a declaration of the function, but
      the linker does not necessarily have a definition
      of the function. Consider this example:

      /* BROKEN CODE */
      extern int foo( int );
      int main( void )
      {
      return foo( 5 );
      }

      Would you expect this to build? Chances are good you'll
      get an error something like:

      Undefined symbols:
      "_foo", referenced from:
      _main in cc46tCIn.o
      ld: symbol(s) not found
      collect2: ld returned 1 exit status

      The situation is the same if foo is declared in foo.h and
      you write:
      #include <foo.h>
      int main( void ) { return foo(); }

      Declarations appearing in the header files have (almost)
      absolutely nothing to do with the error you are seeing.

      Comment

      Working...