- 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.
- programming environment: MS-VSC and PIO
- framework: espidf
- Right now I have these lines in my program:
- const char* filename = __FILE__;
- const char* date = __DATE__;
- const char* time = __TIME__;
- printf("Hello from %s\n", filename);
- printf("Compiled on %s at %s\n", date, time);
- And that results in this output:
- Hello from src/hello_world_main.c
- Compiled on Jan 20 2024 at 23:42:36
- Instead, I want the *entire* filename to print out, like this:
- Hello from C:\Users\Jim\Documents\PlatformIO\Projects\espidf-hello-world\src\hello_world.c
- Compiled on Jan 20 2024 at 23:42:36
- 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:
- src/hello_world.c
- MY QUESTION IS:
- 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).
Enhance "__FILE__" to obtain the *full* path during compile
-
- Posts: 4
- Joined: Sun Jan 21, 2024 8:46 am
Enhance "__FILE__" to obtain the *full* path during compile
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Enhance "__FILE__" to obtain the *full* path during compile
It's an option in menuconfig. Enter menuconfig, go to 'Compiler options', disable 'Replace ESP-IDF and project paths in binaries'.
-
- Posts: 4
- Joined: Sun Jan 21, 2024 8:46 am
Re: Enhance "__FILE__" to obtain the *full* path during compile
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?
"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?
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Enhance "__FILE__" to obtain the *full* path during compile
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?
-
- Posts: 4
- Joined: Sun Jan 21, 2024 8:46 am
Re: Enhance "__FILE__" to obtain the *full* path during compile
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.
I will visit the remote computer and see if it makes a difference using the real arrow keys.
-
- Posts: 4
- Joined: Sun Jan 21, 2024 8:46 am
Re: Enhance "__FILE__" to obtain the *full* path during compile
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?
-
- Posts: 1708
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Enhance "__FILE__" to obtain the *full* path during compile
Alternative in VSCode: Press F1, then enter/select "> ESP-IDF: SDK Confuration editor (menuconfig)". (May take a while to load/start at first.)programming environment: MS-VSC
Who is online
Users browsing this forum: No registered users and 75 guests