# 04-10 Create v.1 of Server
Today I made a first version of the BLE Server program. Honestly it was way harder than I expected it to be. Successfullly building the project with code in subfolders was not straightforward as all. I have had huge issues with linking compiled files from a subfolder and am not sure if it is because the preprocessor or linker is failing. More details down below.
Side note: I have been trying out the batteries for the ESP32 just to see how good battery life is. I never charged any batteries and I don't know how full they were when delivered, but they lasted 12h in any case. Impressive 😃
# Problems
My IDE is Microsoft's Visual Studio Code. I use the Arduino extension, which basically is a VS Code wrapper for the Arduino IDE. I have had many problems with linking header files that I put into a folder. The linker throws an error since it claims that the reference to subfolder/example.h does not exist. The linker has no problem finding the files when everything is in the same directory. Compilation works file, linking is the problem. Honestly I am kind of perplexed by this, because I have tried to coerce the linker to work for the past 3 hours. Annoying.
// file: ble-ips-server.ino
// include the display helper, whose member functions initialize the tft display
#include "helpers/displayHelper.h"
/* file tree:
src
|
--- ble-ips-server.ino
|
--- helpers
|--displayHelper.h
|--displayHelper.cc
*/
# Possible Solutions
# Misconfigured includePath
Maybe something is wrong with the includePath of either the Arduino IDE or the VS Code editor's Arduino extension. I have tried so many different things and read so many webpages though, that I doubt that this is the issue. I have set the include paths for my own workspace and the library files. I am pretty sure this is right, since it worked for the third party tft_espi display library this way and it linked everything there too.
// c_cpp_properties.json
{
"name": "Win32",
"includePath": [
"${workspaceFolder}",
"C:\\Users\\marmar\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\**",
"C:\\Users\\marmar\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4\\**",
"C:\\Users\\marmar\\Documents\\Arduino\\libraries\\TFT_eSPI",
"s:\\git-repos\\school-repos\\matura\\ble-ips-server\\src",
"${workspaceFolder}"
],
"intelliSenseMode": "clang-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17"
}
# Ignore the problem alltogether
I do not currently have any issues with the actual BLE Server functionality. The problem causing code provides functions to interface with the display and configure it to my liking. I consider logging something to the display nonessential. But I do want the code to be clean and the setup function is quite ugly otherwise. I want to delegate the lower level of abstraction involved in setting up a display to a helper method, there is no reason why my main BLE Server creator should be responsible for that. I think this is a bad option, since I will need to create subfolders in the future anyway.
# Read some serious documentation
I should read some real documentation about linking and compiling files. Stackoverflow does not teach you about how the code works, it just lets you copy paste some code that you wont understand. I dont want to be that kind of a person. I think linking, compiling and header files are a very basic concept of C++ and I will need this pretty soon.
I doubt that the Arduino IDE is making a mistake when linking or that my Arduino Extension is corrupted. Most likely I am making a stupid error with including the path or defining the function. When I see hoof prints, I should think of horses and not of Zebras.
# Further Actions
I think I will do just that. I will have a quick read about the fundamentals of the c++ compiler and linker and then carry on from there.