hard_code
(hard_code)
August 29, 2016, 4:55pm
1
In xcode the following causes a failed build error: use of undeclared identifier ‘L__func__’
#if _MSC_VER
#define FUNC_NAME TEXT(__FUNCTION__)
#else // FIXME - GCC?
#define FUNC_NAME TEXT(__func__) # this causes error on mac
#endif
Note this code is from A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums
I have tried FUNCTION and __PRETTY_FUNCTION. Both same issues. If I remove the TEXT macro then it compiles but viewing the output log in the editor causes the editor to crash if I log the value of FUNC_NAME.
Anyone know how to log function names on a mac?
hard_code
(hard_code)
August 29, 2016, 6:38pm
2
I fixed this by doing this
#define FUNC_NAME *FString(__func__)
I have no idea if that is bad or not but seems to be working
2 Likes
trojanfoe
(trojanfoe)
August 30, 2016, 6:43am
3
Did you see what TEXT() expands to? As you can see it’s just L so that doing TEXT(“Hello”) expands to L"Hello". I would imagine you want to use FName(func ), however I think you want FUNCTION rather than func .
hard_code
(hard_code)
August 30, 2016, 4:37pm
4
FName(FUNCTION ) causes the game to crash when its logged in some low level string class.
*FString(FUNCTION ) does work though so i changed to that…not sure if func is different than function but all seems to be working the same.
trojanfoe
(trojanfoe)
August 30, 2016, 4:56pm
5
What about just FUNCTION ?
hard_code
(hard_code)
August 30, 2016, 5:02pm
6
With only FUNCTION that crashes the editor when viewing the output log.
Its working though with how i have it with *FString so im not going to mess with it anymore.
trojanfoe
(trojanfoe)
August 30, 2016, 5:41pm
7
Well using FString operator * returns const TCHAR *, so there is no point in using it as it must be the same as TEXT(“Hello”). So this should work:
UE_LOG(LogTemp, Log, TEXT("I am in function %s"), TEXT(__FUNCTION__));
hard_code
(hard_code)
August 30, 2016, 5:50pm
8
Well using FString operator * returns const TCHAR *, so there is no point in using it as it must be the same as TEXT(“Hello”). So this should work:
UE_LOG(LogTemp, Log, TEXT("I am in function %s"), TEXT(__FUNCTION__));
I added your UE_LOG(LogTemp, Log, TEXT(“I am in function %s”), TEXT(FUNCTION )); to the player controller begin play function and it wont compile. Same error as in OP.
error: use of undeclared identifier ‘L__FUNCTION__’
trojanfoe
(trojanfoe)
August 30, 2016, 6:26pm
9
Hehe, of course, this is where I came in Sorry. You want something like this .
#define WIDE2(x) L##x
#define WIDECHAR(x) WIDE2(x)
#define WIDE_FUNCTION WIDECHAR(FUNCTION )
I wasn’t able to get any of the above suggestions to work, but found this pattern works
#define CUR_CLASS_FUNC (FString(__FUNCTION__))
UE_LOG(LogTemp, Log, TEXT("I am in function %s:"), *CUR_CLASS_FUNC);
2 Likes
If it helps anyone, you can wrap __FUNCTION__
in a ANSI_TO_TCHAR()
macro like this to print the function name:
UE_LOG( LogMyClass, Error, TEXT( "%s - Something went wrong" ), ANSI_TO_TCHAR( __FUNCTION__ ) );