C / C++ Resolving Undefined Reference Errors in C++

danieldelex

New member
Joined
Sep 24, 2024
Messages
4
Reaction score
0
Location
USA
Hello

I'm currently facing issues with my C++ project; where I keep encountering 'undefined reference to calculateSum(int, int)' errors during the linking phase. I've double-checked my header files and source files; but I still can't pinpoint the problem.

I'm using GCC 9.3. The error occurs when I try to link the function calculateSum in math_functions.cpp.

I've ensured that all required libraries are included in my project settings; particularly the standard math library. I have checked https://stackoverflow.com/questions/46920150/calling-c-function-from-c-code-linkage-errors-using-gcc-for-linking-powerapps reference guide but still need help.

Can anyone provide guidance on common causes of this error & effective troubleshooting steps?

Any help would be greatly appreciated!

Thank you! :)
 

Expl01T3R

Active member
Joined
Nov 20, 2022
Messages
133
Reaction score
21
Location
Czech Republic
.cpp file - body of the calculateSum
.h file - on top - extern declaration

example:
cpp file:
double calculateSum(std::vector<double> input)
{
//body
}

header file (on top of the content):
extern double calculateSum(std::vector<double> input);

in cpp that should work, that's how iam using to prevent this sh*t and unresolved externals etc.

Also if you need further help maybe you should give us your math_functions(.cpp/.h) code.
 
Top