How to build library mixing .c and .cpp source files


hi

i made following code tests:

a library class .h file:
code: [select]

#ifndef jtag_h
#define jtag_h

#include "test.h"
#include "test2.h"

class jtagclass{
        public:
                static int soma(int x);
                static int soma2(int x);
                static int mult(int x);
};

extern jtagclass jtag;
#endif


a library class .cpp file:
quote
#include "jtag.h"

int jtagclass::soma(int x){
return x+x;
}

int jtagclass::soma2(int x){
      return sum(x);
}

int jtagclass::mult(int x){
        return x*x;
}


and other include files test.h test.c test2.h test2.cpp respectively:

test.h
quote

static int sum(int x);


test.c
quote

#include "test.h"
extern int sum(int x){
  return x+x;
}


test2.h
quote

#ifndef zamber_h
#define zamber_h

class zamber{
   public :
     int zam(int x);
};
#endif


test2.cpp
quote

#include "test2.h"
int zamber::zam(int x){
  return x*x;
}


well, when compile these codes message arduino compiler:
jtag/jtag.cpp.o: in function `jtagclass::mult(int)':
/usr/share/arduino/libraries/jtag/jtag.cpp:26: undefined reference `sum(int)'
collect2: ld returned 1 exit status

how fix problem, mix c c++ codes?
thanks

your test.c code wrong. use c code c++ code, need tell compiler name mangling not applied c code. done using extern "c" in header file, not extern in source file.

code: [select]
extern "c"
{
  static int sum(int x);
}


code: [select]
#include "test.h"
int sum(int x)
{
  return x+x;
}


Arduino Forum > Using Arduino > Programming Questions > How to build library mixing .c and .cpp source files


arduino

Comments

Popular posts from this blog

CS5 Adobe Media Encoder: Encode failed because the source duration is nil.

cf_sql_integer vs cf_sql_bigint vs cf_sql_int??

localhost/joomla15/administrator doesnt work - Joomla! Forum - community, help and support