如何解决opencv C ++编程中未解析的外部符号问题? [英] How to solve the issue of unresolved external symbol in opencv C++ programming ?

查看:85
本文介绍了如何解决opencv C ++编程中未解析的外部符号问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个错误提到:错误LNK2001未解析的外部符号'void_cdecl function1(....)在使用C ++语言在opencv-visual studio平台上编写程序时.function1.cpp文件是一个函数包含在头文件中,因为它是作为主程序之外的单独程序编写的。该函数的.cpp文件在另一个函数void function2(...)中调用,该函数在原始程序的主要部分上面定义。 br />
代码的粗略结构如下所示:





#includefunction1.hpp

#include< iostream>

...

void function2(.....)

{

function1(....);

}



int main()

{

int a,b,c;

..

...

function2(.. ..);

..

返回0;

}





请帮助理解和解决原因 void function1(..)显示为未解析的外部符号,虽然我已将function1.cpp保存在主程序的同一目录中。



我是什么尝试过:



尝试在程序中编写define function1(...),以便它不应该被链接。

解决方案

尝试更换

  #include     function1.hpp  



with

  #include     function1.cpp  


Quote:

function1.cpp文件是一个包含在头文件中的函数,因为它是作为一个单独的程序编写的外主程序。在构建C / C ++应用程序时(除了启动其他可执行文件之外)没有像单独程序这样的东西。



你必须编译 function1.cpp 文件也将创建的目标文件与应用程序中的其他文件链接起来。使用Visual Studio,只需将文件添加到项目中(项目 - 添加现有文件)。



还请注意源文件( * .cpp )不应包括在内。这是不好的做法,可能会导致其他问题。


I have come across an error mentioned as: error LNK2001 "unresolved external symbol 'void_cdecl function1(....) while writing a program in opencv-visual studio platform using C++ language. The function1.cpp file is a function that is included as header file because it is written as a separate program outside main program. The .cpp file of this function is called within another function "void function2(...)" which is defined above the main section of original program.
The rough structure of the code is as shown:


#include"function1.hpp"
#include<iostream>
...
void function2(.....)
{
function1(....);
}

int main()
{
int a,b,c;
..
...
function2(....);
..
return 0;
}


Kindly help to understand and solve why "void function1(..)" is shown as unresolved external symbol although I have kept the function1.cpp in the same directory of main program.

What I have tried:

Tried to write define function1(...) inside the program so that it should not be linked.

解决方案

Try to replace

#include"function1.hpp"


with

#include"function1.cpp"


Quote:

The function1.cpp file is a function that is included as header file because it is written as a separate program outside main program.

There is no such thing like a "separate program" when building C/C++ applications (besides starting other executables).

You have to compile the function1.cpp file too and link the created object file with the others from your application. With Visual Studio, just add the file to your project (Project - Add existing).

Note also that source files (*.cpp) should not be included. It is bad practice and may lead to additional problems.


这篇关于如何解决opencv C ++编程中未解析的外部符号问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆