Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 25-Aug-17 22:17pm

Try to replace
C++
#include"function1.hpp"

with
C++
#include"function1.cpp"
 
Share this answer
 
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.
 
Share this answer
 
Comments
Helal Uddin Mullah 28-Aug-17 2:55am    
Thank you so much @Sir Arndt for your important suggestions.
My problem is now solved by doing according to you. Hope for more help in future.
Jochen Arndt 28-Aug-17 2:58am    
You are welcome and thank you for accepting my solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900