t0tott 2019-10-22 16:46 采纳率: 0%
浏览 714
已采纳

导入*.cpp文件后,编译出现错误error LNK2005

seg.cpp的代码功能是预处理图片/检测图片
现在Cpig.cpp中加入include < seg.cpp >
出现如下错误:

1>------ 已启动全部重新生成: 项目: AnimalsFatMeasure, 配置: Release x64 ------
1>stdafx.cpp
1>AnimalsFatMeasure.cpp
1>AnimalsFatMeasureDlg.cpp
1>Cpig.cpp
1>INFOR.cpp
1>seg.cpp
1>seg.obj : error LNK2005: "class cv::Mat g_srcImage" (?g_srcImage@@3VMat@cv@@A) 已经在 Cpig.obj 中定义
1>seg.obj : error LNK2005: "class cv::Mat g_grayImage" (?g_grayImage@@3VMat@cv@@A) 已经在 Cpig.obj 中定义
1>seg.obj : error LNK2005: "class cv::Mat out_therImage" (?out_therImage@@3VMat@cv@@A) 已经在 Cpig.obj 中定义
1>seg.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > saveImage" (?saveImage@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) 已经在 Cpig.obj 中定义
1>seg.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > file_save" (?file_save@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) 已经在 Cpig.obj 中定义
1>Cpig.obj : error LNK2005: "float __cdecl Zfhanliang(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Zfhanliang@@YAMV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 已经在 Cpig.obj 中定义
1>Cpig.obj : error LNK2005: "bool __cdecl Jh12(int,int)" (?Jh12@@YA_NHH@Z) 已经在 Cpig.obj 中定义

具体代码如下
seg.cpp

#include"stdafx.h"
#include <iostream>
#include<opencv2\opencv.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<vector>
#include<math.h>
#include<algorithm>
#include<time.h>
#include<io.h>
#include<stdio.h>
#include<string>
//#include<squares.cpp>

using namespace cv;
using namespace std;

Mat g_srcImage, g_grayImage, out_therImage;
string saveImage = "preidentify/save";
string file_save = "middleidentify/";

Cpig.cpp代码如下

#include "Resource.h"
#include "stdafx.h"
#include "AnimalsFatMeasure.h"
#include "Cpig.h"
#include "afxdialogex.h"
#include "INFOR.h"
#include <opencv2/opencv.hpp>
#include "seg.cpp"
  • 写回答

1条回答 默认 最新

  • 泡视界 2019-10-22 17:08
    关注

    朋友,.cpp可不是用来include的,你需要整理出一个seg.h来,然后引用这个.h

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 luckysheet
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误