I am trying to import a header file from a project to a .c file in another project. The idea is to have a generic project of headers and functions which can be used by multiple project in the same solution.
These are the header file and it's .c file in their own project:
Util_library.h:
#pragma once
#include <string.h>
void reverse(char *c);
Library.c:
#include "Util_Library.h"
void reverse(char *c) { //reverse function to be called by main functions
size_t len = strlen(c) - 1, i, k = len - 1; //purpose of function is to
char tmp; //reverse a given string
for (i = 0; i < len / 2; i++) {
tmp = c[k];
c[k] = c[i];
c[i] = tmp;
k--;
}
}
This is the main function (in another separate project [but in the same solution]) which by #includeing the header file Util_Library.h, it can make use of the function reverse():
#include <stdio.h>
#include <stdlib.h> //malloc library
#include "C:\Users\...\Library\Util_Library.h" //not real path
void main() {
char ch[100];
printf("Enter a string of characters:");
fgets(ch, sizeof(ch), stdin);
printf("%s", ch);
reverse(ch);
printf("%s", ch);
int chk = getchar();
}
Even though I have no syntax errors (according to the compiler that is), when I try to run the program I get these 2 errors:
Error LNK2019 unresolved external symbol "void __cdecl reverse(char *)" (?reverse@@YAXPEAD@Z) referenced in function main Assignment 1D C:\Users...\Assignment_1D\Assignment_1D.obj 1
Error LNK1120 1 unresolved externals Assignment 1D C:\Users\mmusc\Dropbox\Development\C(++) - Visual Studio\Assignments\x64\Debug\Assignment 1D.exe 1
Thanks for your help!
edit I have included the actual .c file which contains the function reverse(), however is there anyway to import just a header file instead of the whole .c file which might even contain functions you would not need in the specific main function edit