Enhance "__FILE__" to obtain the *full* path during compile

jimluschen
Posts: 4
Joined: Sun Jan 21, 2024 8:46 am

Enhance "__FILE__" to obtain the *full* path during compile

Postby jimluschen » Sun Jan 21, 2024 10:13 pm

  1. How can the entire filename of a source file be *automatically* stored into the compiled binary as a constant string?  Automatically means "by the preprocessor or compiler" and not by me, because I will forget or screw it up.
  2.  
  3. programming environment:  MS-VSC and PIO
  4. framework:  espidf
  5.  
  6. Right now I have these lines in my program:
  7.      const char* filename = __FILE__;
  8.      const char* date = __DATE__;
  9.      const char* time = __TIME__;
  10.      printf("Hello from %s\n", filename);
  11.      printf("Compiled on %s at %s\n", date, time);
  12.  
  13. And that results in this output:
  14.      Hello from src/hello_world_main.c
  15.      Compiled on Jan 20 2024 at 23:42:36
  16.  
  17.  
  18. Instead, I want the *entire* filename to print out, like this:
  19.      Hello from C:\Users\Jim\Documents\PlatformIO\Projects\espidf-hello-world\src\hello_world.c
  20.      Compiled on Jan 20 2024 at 23:42:36
  21.  
  22. HOW THIS CURRENTLY WORKS: The "__FILE__" preprocessor macro expands to the current source file's name as a string literal. But this string is not the complete filename -- it is the filename minus the higher-order path information that extends from the project folder up to the drive identifier.  Since the project folder typically contains a folder named "src", the result of "__FILE__" has this general form:
  23.      src/hello_world.c
  24.  
  25. MY QUESTION IS:
  26. Is there a way to get the rest of the filename the __FILE__ macro does not get?  BTW, the   __BASE_FILE__ macro yields the same result as the __FILE__ macro (I tried it).

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: Enhance "__FILE__" to obtain the *full* path during compile

Postby ESP_Sprite » Mon Jan 22, 2024 1:30 am

It's an option in menuconfig. Enter menuconfig, go to 'Compiler options', disable 'Replace ESP-IDF and project paths in binaries'.

jimluschen
Posts: 4
Joined: Sun Jan 21, 2024 8:46 am

Re: Enhance "__FILE__" to obtain the *full* path during compile

Postby jimluschen » Mon Jan 22, 2024 6:32 am

You write:
"It's an option in menuconfig. Enter menuconfig, go to 'Compiler options', disable 'Replace ESP-IDF and project paths in binaries'."

I am looking forward to discovering you are absolutely right, but I haven't been able to get there yet. When I "Run Menucnfig" in a terminal window I get an arcane 1980's program interface that won't let me move off the first choice "Build type":

Build type --->
Bootloader config --->
Security features --->
Application manager --->
Serial flasher config --->
Partition Table --->
Compiler options --->
Component config --->

[Space/ Enter] Toggle/enter [ESC] Leave menu [a] Save
[O] Load [?] Symbol info [l] Jump to symbol
[F] Toggle show-help mode [C] Toggle show-name mode [A] Toggle show-all mode
[Q] Quit (prompts for save) [D] Save minimal config (advanced)


Arrow keys do nothing, the tab key does nothing, the mouse is useless. I tried all 11 function keys at the bottom of this menu but none move the selection off "Build Type" and so I cannot get down to "Compiler options" -- this is very frustrating. How do you work this thing?

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: Enhance "__FILE__" to obtain the *full* path during compile

Postby ESP_Sprite » Mon Jan 22, 2024 7:41 am

It Just Works for me - arrow keys to go to the proper item, enter to select. What OS (and if applicable, IDE and/or terminal program) are you using?

jimluschen
Posts: 4
Joined: Sun Jan 21, 2024 8:46 am

Re: Enhance "__FILE__" to obtain the *full* path during compile

Postby jimluschen » Mon Jan 22, 2024 8:35 am

I'm using a Windows 10 OS on a Dell laptop...Oh I just thought of something. I'm using Remote Desktop to remotely control the computer that's doing all this MS Visual Studio Code and PlatformIO stuff. I bet the Remote Desktop link is filtering the arrow keys in a way that doesn't affect Windows applications but is messing up this 1980's interface. Which reminds me, in 1980 I wrote a Microsoft Basic program on an Apple II that was at least as good as this menuconfig interface.

I will visit the remote computer and see if it makes a difference using the real arrow keys.

jimluschen
Posts: 4
Joined: Sun Jan 21, 2024 8:46 am

Re: Enhance "__FILE__" to obtain the *full* path during compile

Postby jimluschen » Mon Jan 22, 2024 10:02 am

It still doesn't work using the arrow keys on the actual laptop running MS-VSC/PlatformIO. Is there a command line way to accomplish the same thing?

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Enhance "__FILE__" to obtain the *full* path during compile

Postby MicroController » Mon Jan 22, 2024 1:25 pm

programming environment: MS-VSC
Alternative in VSCode: Press F1, then enter/select "> ESP-IDF: SDK Confuration editor (menuconfig)". (May take a while to load/start at first.)

Who is online

Users browsing this forum: No registered users and 99 guests