Compilation error when using a header file
Dylan
dfuentes0027 at gmail.com
Thu Jan 2 15:00:51 UTC 2025
Hello, I hope everyone is having a nice day. i would like to find
a solution to fix my current problem.
I tried using a header file by linking it with my other .cpp
files and when I compile it, I get this message:
"Rebuild started at 09:34...
1>------ Rebuild All started: Project: HelloWorld, Configuration:
Debug x64 ------
1>main.cpp
1>main.obj : error LNK2019: unresolved external symbol "int
__cdecl add(int,int)" (?add@@YAHHH at Z) referenced in function main
1>C:\Users\Dylan\source\repos\HelloWorld\x64\Debug\HelloWorld.exe
: fatal error LNK1120: 1 unresolved externals
1>Done building project "HelloWorld.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped
==========
========== Rebuild completed at 09:34 and took 00.838 seconds
=========="
these are my files:
-----main.cpp-----
#include \<iostream>
#include "add.h"
int main()
{
std::cout \<\< "The sum of 3 and 4 is " \<\< add(3, 4)
\<\< '\n';
return 0;
}
------------------
------add.h-----------
int add(int x, int y);
----------------------
-------add.cpp--------
#include "add.h"
int add(int x, int y)
{
return x + y;
}
----------------------
I'm not sure if this information is relevant, but I'm using
Visual Studio IDE and I haven't made any changes to its settings
More information about the Digitalmars-d-announce
mailing list