<function> referenced; character not found

I have a piece of C code that is used from a C ++ function. At the top of my C ++ file, I have a line:#include "prediction.h"

In prediction.hI have this:

#ifndef prediction  
#define prediction  

#include "structs.h"  

typedef struct {  
    double estimation;  
    double variance;  
} response;

response runPrediction(int obs, location* positions, double* observations,
                        int targets, location* targetPositions);

#endif

I also have prediction.cone that has:

#include "prediction.h"  

response runPrediction(int obs, location* positions, double* observations,
                        int targets, location* targetPositions) {  
    // code here  
}

Now, in my C ++ file (which, as I said, includes prediction.h), I call this function and then compile (via Xcode), I get this error:

"runPrediction (int, location *, double *, int, location *)" referenced:
  mainFrame :: replyTo (char *, int) in mainFrame.o
  ld: character not found
  collect2: ld returned 1 exit status

prediction.c . .cpp. ?

+3
3

, *. :

extern "C" response runPrediction(int obs, location* positions,
                   double* observations, int targets, location* targetPositions);

C.

* ++ , , . C , .


, , extern "C", extern:

extern "C"
{
    response runPrediction(int obs, location* positions,
                   double* observations, int targets, location* targetPositions);

    // other stuff
}

Paul , __cplusplus, :

#ifdef __cplusplus
    #define EXTERN_C extern "C"
#else
    #define EXTERN_C
#endif

EXTERN_C response runPrediction(int obs, location* positions,
                   double* observations, int targets, location* targetPositions);
+5

prediction.h , :

#ifndef prediction  
#define prediction  

#include "structs.h"  

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {  
    double estimation;  
    double variance;  
} response;

response runPrediction(int obs, location* positions, double* observations,
                        int targets, location* targetPositions);

#ifdef __cplusplus
}
#endif

#endif
+3

Is "prediciton" really C, not C ++? You will have different default compilation based on the file extension, GMan covers this.

If it is C ++, and you change the file name, I would still say that runPrediction should be marked extern in the header, it is not defined in the local C ++ module that defines the mainFrame class.

0
source

Source: https://habr.com/ru/post/1750586/


All Articles