【发布时间】:2013-11-15 03:46:04
【问题描述】:
我有一个名为 pso.cpp 的 c++ 程序,一个输入和两个输出(通过指针)如下:
void pso(int32_T Iteration, real_T *gbest, real_T *w)
我还有一个名为main.cpp的c++程序如下:
#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;
}
另外,pso.h 如下:
#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
我通过命令g++ main.cpp -o main 执行main.cpp。
但我遇到了这个错误:
main.cpp:(.text+0x29): undefined reference to pso(int, double*, double*)'
collect2: ld returned 1 exit status
如何解决编程错误?
【问题讨论】:
-
这不是问题,但是包含两个连续下划线 (
__PSO_H__) 的名称和以下划线后跟大写字母的名称保留给实现。不要使用它们。 -
我删除了所有 .h 文件中的两个连续下划线。但是你说的是下划线开头的名字。这个结构在我的编码中是否有任何变量?
-
您发布的代码中没有这样的内容。
-
不幸的是,发生了同样的错误。问题不是两个连续的下划线。我至少有 12 小时出现此错误 :-(
-
正如我最初所说:“这不是问题,但是......”
标签: c++ linux compiler-errors