c++ - main.c:(.text+0x30): undefined reference to `reciprocal' -


I was trying to program ahead of advance Linux programming. Some other people also felt this problem but reading those threads is not helping me. I tried those methods but my problem is still there please help me.

The main thing is here

  #include & lt; Stdio.h & gt; #include "reciprocal.hpp" int main (int argc, char const * argv []) {int i; I = Atoi (argv [1]); Printf ("% d mutual% g \ n", i, reciprocal (i)); Return 0; }  

reciprocal cpp

  #include on listing  

listing Parikropal. HP

  #ifdef _cplusplus extern "c" {#endif extern double reciprocal (int i); #ifdef _cplusplus} #endif  

Listing Makefile:

  reciprocal: main.o reciprocal.o G ++ $ (CFLAGS) -o reciprocal main. O Reciprocal.cpp reciprocal.hpp G ++ $ (CFLAGS) -c reciprocal.cpp: o reciprocal.hpp gcc $ (CFLAGS) -c main.c i ../include reciprocal.cpp I ../include clean: rm -f * .o reciprocal  

is error:

  state $ make gcc -c main.ci ./include G ++ -C reciprocal.cpp i ../include G ++ -o reciprocal main.o reciprocal.o main.o: function in `main ':. Main.c: (text + 0x30): `Undefined reference reciprocal 'collection 2: error: LD created 1 exit position: *** [Reciprocal] error 1  
< P>

You should not have __ cplusplus (a) not _cplusplus in your macro.


How to debug: Undefined reciprocal in main.o :

  nm main.o | Looking for grep reciprocal u reciprocal  

and your reciprocal.o :

  • with __ Cplusplus :

      $ nm reciprocal.o | Grep reciprocal 0000000000000000 t 0000000000000020 r _ZZ10reciprocalE19__PRETTY_FUNCTION__  
  • (with _cplusplus as you wrote):

      $ nm reciprocal.o | Grep reciprocal 0000000000000000 T _Z10reciprocali 0000000000000020 R _ZZ10reciprocaliE19__PRETTY_FUNCTION__  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -