Re: undefined reference to "..."



On 27 Sep, 04:08, zqiang320 <zqiang...@xxxxxxxxx> wrote:

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> <cmath>
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 misunderstanding 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.
.



Relevant Pages

  • Re: Question regarding prototypes for 0-ary functions.
    ... int fooint x; ... extern int foo(int, ... ... extern int foo(); is not a valid declaration, ... The definition of foo says it takes one parameter, while the declaration ...
    (comp.lang.c)
  • Re: Strange function use
    ... int a, b, foo; ... int a, b, foo(int); ... the function prototype "foo" expects an integer argument ... foooccurs inside a declaration. ...
    (comp.lang.c)
  • Re: Strange function use
    ... int a, b, foo; ... int a, b, foo(int); ... foooccurs inside a declaration. ... function prototype declaration. ...
    (comp.lang.c)
  • Re: Newbie static class member question [C++]
    ... >and allows subsequent declarations to refer to Foo in certain contexts ... there is a name 'i' which designates an int ... In some contexts a declaration is also a definition. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: newbie::functions calls across multiple cpp files
    ... > int test(); ... Compiler must know that there is a function test defined somewhere when it ... Header files are for that purpose. ... declaration of the test function. ...
    (comp.lang.cpp)