How do I include .h and .cpp from another directory?

I have some code from another project in a directory outside of my project directory. For example in build.cs, I have this line:

PrivateIncludePaths.Add(C:/foo/);

Where in C:/foo/ is bar.h and bar.cpp

bar.h

#pragma once
#include "projectname.h"
int bar();

bar.cpp

#include "projectname.h"
#include "bar.h"
int bar() {return 1;}

Calling test(); in any of my actor files gives a linker error

error LNK2019: unresolved external symbol

Replace the function with any class, struct, etc. You can declare it but using any implementation in the .cpp file gives a linker error.

Is this possible within UE, or do I have to make it a module? I think that moving all the code into the projects Source/Projectname directory would work, but I would like to avoid that since my UE project and other project rely on the same source, and want to keep one unique copy so any edits do not have to be updated to all other copies. Ideally I would just like to compile source code that is in another directory.

#include “foldername/bar.h” providing it is in the same root folder
#include “…/bar.h” if it is in the folder before
#include “C:/documents/yourname/bar.h” for the full path.

I should imagine.

Thanks for the answer. Looks like those sort of solutions fix it. I went with creating a directory symbolic link between the two folders.

Glad I could help.