Use non-project files

Workspace/
  common_files/
      common_file.h
             void common_function(void);
      common_file.cpp
             void common_function(void) { printf("do something\n"); }
  Project_A/
      main.cpp
      CMakeLists.txt
      mbed-os/
  Project_B/
      main.cpp
      CMakeLists.txt
      mbed-os/

Using the above example Mbed Studio workspace structure, how would I go about including common_file.h into Project_a/main.cpp?

When I include "../common_files/common_file.h" in Project_A/main.cpp and call common_function(); , I get a linker error stating that there is an undefined reference to common_function();.

Hello,

this is possible with MbedOS library in MbedStudio, but not with any others, how I remember.

Shared personal library - Mbed Studio - Arm Mbed OS support forum

BR, Jan

Can I not get my requested functionality (including external files) using CMake?

You have two ways of doing that:

  • add common_file.cpp to your Project_A CMakeLists.txt
  • add a CMakeLists.txt in common_files/ and create a library target there, then target_link project A with the common files library