I am trying to create a basic program with a user defined header file.I created the project in visual studio.

test1.cpp
#include <stdio.h>
#include "multiply.h"

int main()
{

    int y;
    y=multiply(5,10);
    printf("%d\n",y);
    printf("%s","jigar");
    getch();
    return 0;

}
multiply.h
int multiply(int a,int b);
multiply.c
#include "multiply.h"
int multiply(int a, int b)
{
    return a*b;
}

However while running the program test1.cpp I am getting the error as

Error 1 error LNK2019: unresolved external symbol "int __cdecl multiply(int,int)" (?multiply@@YAHHH@Z) referenced in function _main test1.obj

Some one please help me out ..

a C file always require a main function to execute as in the case of multiply.c

also if your making a C program use the extension .c for your main file .cpp is for c++ programs

a C file always require a main function to execute as in the case of multiply.c

Take another look at test1.cpp. main() is right there!

After changing test.cpp to test.c, add multiply.c to the compile line.

.cpp and .c doesnt make any difference if u r running a C code.
Thanx a lot for replying.
The issue is resolved. In visual studio, we have to add the the .c files which the .h file have calles to the source(in the solution explorer)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.