Closed SuperWangKai closed 3 years ago
It seems you are missing some critical includes in the compiler parameters. The following works for me:
{android}/Sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -target armv7-none-linux-androideabi18 --sysroot {android}/Sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot -march=armv7-a -I{android}/Sdk/ndk/21.3.6528147/sources/android/cpufeatures -I{android}Sdk/ndk/21.3.6528147/sources/cxx-stl/llvm-libc++/include -I{android}/Sdk/ndk/21.3.6528147/sources/cxx-stl/llvm-libc++abi/include -nostdinc++ -DANDROID -D__ANDROID__ -DTRACY_ENABLE -std=c++11 -c TracyClient.cpp -o TracyClient.o
Thank you for the reply.
I have added includes as you did, somehow, issue still exists...
[7/85] Building CXX object Source/ThirdParty/Tracy/CMakeFiles/Tracy.dir/client/TracySysTrace.cpp.o
FAILED: Source/ThirdParty/Tracy/CMakeFiles/Tracy.dir/client/TracySysTrace.cpp.o
D:\AndroidDev\AndroidSDK\ndk\21.0.6113669\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi18 --gcc-toolchain=D:/AndroidDev/AndroidSDK/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/AndroidDev/AndroidSDK/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot -DANDROID -DNOMINMAX=1 -DTRACY_ENABLE=1 -DTRACY_FILESELECTOR=0 -DTRACY_ON_DEMAND=1 -DURHO3D_ANGELSCRIPT -DURHO3D_FILEWATCHER -DURHO3D_IK -DURHO3D_LOGGING -DURHO3D_LUA -DURHO3D_NAVIGATION -DURHO3D_NETWORK -DURHO3D_PHYSICS -DURHO3D_PROFILING -DURHO3D_STATIC_DEFINE -DURHO3D_THREADING -DURHO3D_URHO2D -DURHO3D_WEBP -D__ANDROID__ -ID:/AndroidDev/AndroidSDK/ndk/21.0.6113669/sources/android/cpufeatures -ID:/AndroidDev/AndroidSDK/ndk/21.0.6113669/sources/cxx-stl/llvm-libc++/include -ID:/AndroidDev/AndroidSDK/ndk/21.0.6113669/sources/cxx-stl/llvm-libc++abi/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -std=c++11 -Wno-invalid-offsetof -Qunused-arguments -fcolor-diagnostics -Wno-argument-outside-range -O0 -fno-limit-debug-info -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -nostdinc++ -MD -MT Source/ThirdParty/Tracy/CMakeFiles/Tracy.dir/client/TracySysTrace.cpp.o -MF Source\ThirdParty\Tracy\CMakeFiles\Tracy.dir\client\TracySysTrace.cpp.o.d -o Source/ThirdParty/Tracy/CMakeFiles/Tracy.dir/client/TracySysTrace.cpp.o -c ../../../../../../Source/ThirdParty/Tracy/client/TracySysTrace.cpp
../../../../../../Source/ThirdParty/Tracy/client/TracySysTrace.cpp:638:21: error: use of undeclared identifier '__NR_perf_event_open'
return syscall( __NR_perf_event_open, hw_event, pid, cpu, group_fd, flags );
^
1 error generated.
I don't know why this would fail. In my ndk installation __NR_perf_event_open
is present as follows:
[15:32 wolf@oberon:...ppData/Local/Android/Sdk]% grep __NR_perf_event_open * -r
ndk/21.3.6528147/sysroot/usr/include/arm-linux-androideabi/asm/unistd-common.h:#define __NR_perf_event_open (__NR_SYSCALL_BASE + 364)
ndk/21.3.6528147/sysroot/usr/include/asm-generic/unistd.h:#define __NR_perf_event_open 241
ndk/21.3.6528147/sysroot/usr/include/bits/glibc-syscalls.h:#if defined(__NR_perf_event_open)
ndk/21.3.6528147/sysroot/usr/include/bits/glibc-syscalls.h: #define SYS_perf_event_open __NR_perf_event_open
ndk/21.3.6528147/sysroot/usr/include/i686-linux-android/asm/unistd_32.h:#define __NR_perf_event_open 336
ndk/21.3.6528147/sysroot/usr/include/i686-linux-android/asm/unistd_64.h:#define __NR_perf_event_open 298
ndk/21.3.6528147/sysroot/usr/include/i686-linux-android/asm/unistd_x32.h:#define __NR_perf_event_open (__X32_SYSCALL_BIT + 298)
ndk/21.3.6528147/sysroot/usr/include/x86_64-linux-android/asm/unistd_32.h:#define __NR_perf_event_open 336
ndk/21.3.6528147/sysroot/usr/include/x86_64-linux-android/asm/unistd_64.h:#define __NR_perf_event_open 298
ndk/21.3.6528147/sysroot/usr/include/x86_64-linux-android/asm/unistd_x32.h:#define __NR_perf_event_open (__X32_SYSCALL_BIT + 298)
ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/arm-linux-androideabi/asm/unistd-common.h:#define __NR_perf_event_open (__NR_SYSCALL_BASE + 364)
ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/asm-generic/unistd.h:#define __NR_perf_event_open 241
ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/bits/glibc-syscalls.h:#if defined(__NR_perf_event_open)
ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/bits/glibc-syscalls.h: #define SYS_perf_event_open __NR_perf_event_open
ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/i686-linux-android/asm/unistd_32.h:#define __NR_perf_event_open 336
ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/i686-linux-android/asm/unistd_64.h:#define __NR_perf_event_open 298
ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/i686-linux-android/asm/unistd_x32.h:#define __NR_perf_event_open (__X32_SYSCALL_BIT + 298)
ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/x86_64-linux-android/asm/unistd_32.h:#define __NR_perf_event_open 336
ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/x86_64-linux-android/asm/unistd_64.h:#define __NR_perf_event_open 298
ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/x86_64-linux-android/asm/unistd_x32.h:#define __NR_perf_event_open (__X32_SYSCALL_BIT + 298)
ndk-bundle/sysroot/usr/include/arm-linux-androideabi/asm/unistd-common.h:#define __NR_perf_event_open (__NR_SYSCALL_BASE + 364)
ndk-bundle/sysroot/usr/include/asm-generic/unistd.h:#define __NR_perf_event_open 241
ndk-bundle/sysroot/usr/include/bits/glibc-syscalls.h:#if defined(__NR_perf_event_open)
ndk-bundle/sysroot/usr/include/bits/glibc-syscalls.h: #define SYS_perf_event_open __NR_perf_event_open
ndk-bundle/sysroot/usr/include/i686-linux-android/asm/unistd_32.h:#define __NR_perf_event_open 336
ndk-bundle/sysroot/usr/include/i686-linux-android/asm/unistd_64.h:#define __NR_perf_event_open 298
ndk-bundle/sysroot/usr/include/i686-linux-android/asm/unistd_x32.h:#define __NR_perf_event_open (__X32_SYSCALL_BIT + 298)
ndk-bundle/sysroot/usr/include/x86_64-linux-android/asm/unistd_32.h:#define __NR_perf_event_open 336
ndk-bundle/sysroot/usr/include/x86_64-linux-android/asm/unistd_64.h:#define __NR_perf_event_open 298
ndk-bundle/sysroot/usr/include/x86_64-linux-android/asm/unistd_x32.h:#define __NR_perf_event_open (__X32_SYSCALL_BIT + 298)
ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/arm-linux-androideabi/asm/unistd-common.h:#define __NR_perf_event_open (__NR_SYSCALL_BASE + 364)
ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/asm-generic/unistd.h:#define __NR_perf_event_open 241
ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/bits/glibc-syscalls.h:#if defined(__NR_perf_event_open)
ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/bits/glibc-syscalls.h: #define SYS_perf_event_open __NR_perf_event_open
ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/i686-linux-android/asm/unistd_32.h:#define __NR_perf_event_open 336
ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/i686-linux-android/asm/unistd_64.h:#define __NR_perf_event_open 298
ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/i686-linux-android/asm/unistd_x32.h:#define __NR_perf_event_open (__X32_SYSCALL_BIT + 298)
ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/x86_64-linux-android/asm/unistd_32.h:#define __NR_perf_event_open 336
ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/x86_64-linux-android/asm/unistd_64.h:#define __NR_perf_event_open 298
ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/x86_64-linux-android/asm/unistd_x32.h:#define __NR_perf_event_open (__X32_SYSCALL_BIT + 298)
Yes, it is similar on my system. However, I really have no idea which header should be used.
Can you check if adding #include <sys/syscall.h>
fixes the problem? It should be required, according to the man page.
Thank you @wolfpld !
After adding #include <sys/syscall.h>
in TracySysTrace.cpp
, the compiling issue is solved!
However, now here is the undefined tracy::rpmalloc_initialize()
link issue for Android after fixing the compling issue -
Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi-v7a\lib04_StaticScene.so
FAILED: ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/lib04_StaticScene.so
cmd.exe /C "cd . && D:\AndroidDev\AndroidSDK\ndk\21.0.6113669\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi18 --gcc-toolchain=D:/AndroidDev/AndroidSDK/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/AndroidDev/AndroidSDK/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -std=c++11 -Wno-invalid-offsetof -Qunused-arguments -fcolor-diagnostics -Wno-argument-outside-range -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,lib04_StaticScene.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi-v7a\lib04_StaticScene.so Samples/04_StaticScene/CMakeFiles/04_StaticScene.dir/StaticScene.cpp.o {urho_home}/android/urho3d-lib/build/tree/Debug/armeabi-v7a/lib/libUrho3D.a -ldl -llog -landroid -lGLESv1_CM -lGLESv2 -latomic -lm && cd ."
../../../../../../Source/ThirdParty/Tracy/client/TracyProfiler.cpp:123: error: undefined reference to 'tracy::rpmalloc_initialize()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
The integration for Urho3D already worked very well on Windows before I met the issues on Android.
Thanks, Kai
Forum post in parallel universe -https://discourse.urho3d.io/t/tracy-profiler-integration-for-urho3d/6627
Does a467ef4c fix the issue?
Thank you @wolfpld for the commit. The changes works.
In my case, rprealloc
function also leads linking issue, so I also changed the signature with TRACY_API
-https://github.com/wolfpld/tracy/blob/a467ef4c2b2ffe8047a08c802b363d23c473b66b/client/tracy_rpmalloc.hpp#L226
I’m using the STATIC lib of Urho3D, and lib Tracy is supposed to live inside of lib Urho3D. (Edit:)However, since Tracy is used everywhere in the Samples by including headers and inserting macros, some how, some of the symbols are just got elimiated.
However, Tracy is used in the Samples by including header #include "Tracy/Tracy.hpp"
and currently using these macros -
#define URHO3D_PROFILE(name) ZoneScopedN(#name)
#define URHO3D_PROFILE_FRAME() FrameMark
#define URHO3D_PROFILE_THREAD(name) tracy::SetThreadName(name)
#define URHO3D_PROFILE_FUNCTION() ZoneScopedN(__FUNCTION__)
Some how, some of the symbols are just got elimiated.
It seems I have three choices -
In my case, rprealloc function also leads linking issue,
Fixed in 3d37c686.
I’m using the STATIC lib of Urho3D, and lib Tracy is supposed to live inside of lib Urho3D.
This configuration was not taken into consideration before. So in a way, it's good that you encountered these issues, as fixing them increases the robustness of the library.
Export all missed functions of Tracy, just like this commit (a467ef4) is doing.
This is the way to go. For more information refer to https://gcc.gnu.org/wiki/Visibility.
Thank you @wolfpld !
It's now running on Android as expected.
There are two extra issues -
HAVE_DL_ITERATE_PHDR
for the Android platform I'm building, I have to comment out #define HAVE_DL_ITERATE_PHDR 1
in libbacktrace\config.h
(so a dummy implemetation of dl_iterate_phdr
is used) to make it compile:{ndk}\21.0.6113669\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi18 --gcc-toolchain={ndk}/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64 --sysroot={ndk}/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot -DTRACY_ENABLE=1 -DURHO3D_ANGELSCRIPT -DURHO3D_FILEWATCHER -DURHO3D_IK -DURHO3D_LOGGING -DURHO3D_LUA -DURHO3D_NAVIGATION -DURHO3D_NETWORK -DURHO3D_PHYSICS -DURHO3D_PROFILING -DURHO3D_STATIC_DEFINE -DURHO3D_THREADING -DURHO3D_URHO2D -DURHO3D_WEBP -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -std=c++11 -Wno-invalid-offsetof -Qunused-arguments -fcolor-diagnostics -Wno-argument-outside-range -O0 -fno-limit-debug-info -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -MD -MT Source/ThirdParty/Tracy/CMakeFiles/Tracy.dir/libbacktrace/elf.cpp.o -MF Source\ThirdParty\Tracy\CMakeFiles\Tracy.dir\libbacktrace\elf.cpp.o.d -o Source/ThirdParty/Tracy/CMakeFiles/Tracy.dir/libbacktrace/elf.cpp.o -c ../../../../../../Source/ThirdParty/Tracy/libbacktrace/elf.cpp
../../../../../../Source/ThirdParty/Tracy/libbacktrace/elf.cpp:3483:3: error: use of undeclared identifier 'dl_iterate_phdr'
dl_iterate_phdr (phdr_callback, (void *) &pd);
After studying the implementation, it is related to the TRACY_HAS_CALLSTACK
level for each platform.
I wonder if I can get more information about cherry picking source files from Tracy for each platform?
-Kai
I wonder if I can get more information about cherry picking source files from Tracy for each platform?
You should compile TracyClient.cpp
(and only this file).
Thank you very much. I'd like to close the issue.
Hi,
Thank you for this great solution!
I am integrating Tracy into Urho3D.
However, I find a compiling issue for Android platforms-
__NR_perf_event_open
is not found. NDK 21.0.6113669 and 22.0.7026061 have been tried, no luck.Best regards!