I have a c++ program with the name pso.cpp
by the one input and two outputs (by pointer) as follows:
void pso(int32_T Iteration, real_T *gbest, real_T *w)
I have another c++ program with the name main.cpp
as follows:
#include <math.h>
#include <stdio.h>
#include <iostream>
#include "pso.h"
using namespace std;
int main()
{
int32_T Iteration = 1000;
real_T gbest;
real_T w;
pso(Iteration, &gbest, &w);
std::cout << gbest << std::endl;
std::cout << w << std::endl;
return 0;
}
Also, the pso.h
is as follows:
#ifndef __PSO_H__
#define __PSO_H__
/* Include files */
#include <math.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "rt_nonfinite.h"
#include "rtwtypes.h"
#include "pso_types.h"
/* Function Declarations */
extern void pso(int32_T Iteration, real_T *gbest, real_T *w);
#endif
I execute the main.cpp
by command g++ main.cpp -o main
.
But i faced with this error:
main.cpp:(.text+0x29): undefined reference to pso(int, double*, double*)'
collect2: ld returned 1 exit status
How can i solve the programming error?