undefined reference to `Strcpy(char*, char const*)

so basically I have task to create strcpy funtion using header. the function i tested is working but I always keep getting (undefined reference to `Strcpy(char*, char const*)) error when i try to use it in Header way

here is the code.

mystring.h
1
2
3
4
5
#ifndef mystring_h
#define mystring_h

void Strcpy(char dest[],char const src[]);
#endif 


mystring.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream> 
#include <C:\Users\Doublear\Desktop\New folder\New folder\mystring.h>
using namespace std;


void Strcpy(char dest[],char const src[]) {
 int i;

    for (i = 0; src[i] != 0; i++) {
        dest[i] = src[i];
    
    }
}


mystringmain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream> 

#include <C:\Users\Doublear\Desktop\New folder\New folder\mystring.h>
using namespace std;

int main(){
	char str1 []="Samplestring";
  	char str2 [40];
	Strcpy(str2,str1);
	std::cout << str2;
	return 0;
} 


I am using Dev-C++
Make sure 'mystring.cpp' is added to your project, and is being compiled+linked when you do a build. It sounds like it isn't.


Also: full paths in an include is a terrible idea. You should be able to just do:

#include "mystring.h"
got it working thanks a lot!
Topic archived. No new replies allowed.