wolfpld / tracy

Frame profiler

Home Page:https://tracy.nereid.pl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Link error on VS 17.9 RelWithDebInfo but fine in Debug (tracy 0.10)

ahoarau opened this issue · comments

Hi,
Congrats on the impressive tool. I'm trying to integrate it, but I'm facing some link errors on RelWithDebInfo.
Everything is working fine in Debug.

#define TRACY_ENABLE
#include <tracy/Tracy.hpp>

auto main() -> int
{
    ZoneScoped;
}

I build everything in c++20, linking with TracyClient.

[build] [1/1 100% :: 0.271] Linking CXX executable tracy_demo.exe
[build] FAILED: tracy_demo.exe 
[build] C:\Windows\system32\cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=sandboxes\CMakeFiles\tracy_demo.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1439~1.335\bin\Hostx64\x64\link.exe /nologo sandboxes\CMakeFiles\tracy_demo.dir\tracy_demo.cc.obj  /out:tracy_demo.exe /implib:sandboxes\tracy_demo.lib /pdb:tracy_demo.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console  _deps\tracy-build\TracyClient.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
[build] LINK Pass 1: command "C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1439~1.335\bin\Hostx64\x64\link.exe /nologo sandboxes\CMakeFiles\tracy_demo.dir\tracy_demo.cc.obj /out:tracy_demo.exe /implib:sandboxes\tracy_demo.lib /pdb:tracy_demo.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console _deps\tracy-build\TracyClient.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:sandboxes\CMakeFiles\tracy_demo.dir/intermediate.manifest sandboxes\CMakeFiles\tracy_demo.dir/manifest.res" failed (exit code 1120) with the following output:
[build] tracy_demo.cc.obj : error LNK2019: unresolved external symbol "void * __cdecl tracy::rpmalloc(unsigned __int64)" (?rpmalloc@tracy@@YAPEAX_K@Z) referenced in function "private: static struct tracy::moodycamel::ConcurrentQueue<struct tracy::QueueItem,struct tracy::moodycamel::ConcurrentQueueDefaultTraits>::Block * __cdecl tracy::moodycamel::ConcurrentQueue<struct tracy::QueueItem,struct tracy::moodycamel::ConcurrentQueueDefaultTraits>::create<struct tracy::moodycamel::ConcurrentQueue<struct tracy::QueueItem,struct tracy::moodycamel::ConcurrentQueueDefaultTraits>::Block>(void)" (??$create@UBlock@?$ConcurrentQueue@UQueueItem@tracy@@UConcurrentQueueDefaultTraits@moodycamel@2@@moodycamel@tracy@@@?$ConcurrentQueue@UQueueItem@tracy@@UConcurrentQueueDefaultTraits@moodycamel@2@@moodycamel@tracy@@CAPEAUBlock@012@XZ)
[build] tracy_demo.cc.obj : error LNK2019: unresolved external symbol "void __cdecl tracy::InitRpmalloc(void)" (?InitRpmalloc@tracy@@YAXXZ) referenced in function "private: static struct tracy::moodycamel::ConcurrentQueue<struct tracy::QueueItem,struct tracy::moodycamel::ConcurrentQueueDefaultTraits>::Block * __cdecl tracy::moodycamel::ConcurrentQueue<struct tracy::QueueItem,struct tracy::moodycamel::ConcurrentQueueDefaultTraits>::create<struct tracy::moodycamel::ConcurrentQueue<struct tracy::QueueItem,struct tracy::moodycamel::ConcurrentQueueDefaultTraits>::Block>(void)" (??$create@UBlock@?$ConcurrentQueue@UQueueItem@tracy@@UConcurrentQueueDefaultTraits@moodycamel@2@@moodycamel@tracy@@@?$ConcurrentQueue@UQueueItem@tracy@@UConcurrentQueueDefaultTraits@moodycamel@2@@moodycamel@tracy@@CAPEAUBlock@012@XZ)
[build] tracy_demo.cc.obj : error LNK2019: unresolved external symbol "struct tracy::moodycamel::ConcurrentQueue<struct tracy::QueueItem,struct tracy::moodycamel::ConcurrentQueueDefaultTraits>::ExplicitProducer * __cdecl tracy::GetToken(void)" (?GetToken@tracy@@YAPEAUExplicitProducer@?$ConcurrentQueue@UQueueItem@tracy@@UConcurrentQueueDefaultTraits@moodycamel@2@@moodycamel@1@XZ) referenced in function "public: __cdecl tracy::ScopedZone::ScopedZone(struct tracy::SourceLocationData const *,int,bool)" (??0ScopedZone@tracy@@QEAA@PEBUSourceLocationData@1@H_N@Z)
[build] tracy_demo.cc.obj : error LNK2019: unresolved external symbol "class tracy::Profiler & __cdecl tracy::GetProfiler(void)" (?GetProfiler@tracy@@YAAEAVProfiler@1@XZ) referenced in function "public: __cdecl tracy::ScopedZone::ScopedZone(struct tracy::SourceLocationData const *,int,bool)" (??0ScopedZone@tracy@@QEAA@PEBUSourceLocationData@1@H_N@Z)
[build] tracy_demo.cc.obj : error LNK2001: unresolved external symbol ___tracy_RtlWalkFrameChain
[build] tracy_demo.exe : fatal error LNK1120: 5 unresolved externals

I figured out the bug:
TRACY_ENABLE is ON by default and exports it as a PUBLIC definition. In my build, I need it be be disabled by default, and activate it wrt to other cmake options.

It seems that in RelWithDebInfo, this option is required to compile.
image

@wolfpld What do you think the correct fix should be ? Making TRACY_ENABLE private ?

I can't advise you on build system configuration.

I got a workaround by simply not using the embedded CMake, and doing it manually:

    find_package(Threads REQUIRED)
    add_library(tracy STATIC ${tracy_SOURCE_DIR}/public/TracyClient.cpp)
    target_include_directories(tracy PUBLIC ${tracy_SOURCE_DIR}/public)
    target_link_libraries(tracy PUBLIC Threads::Threads)
    if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
        target_compile_definitions(tracy PUBLIC TRACY_ENABLE) # this enables the tracy profiler
    endif()
    target_compile_definitions(tracy PUBLIC TRACY_ON_DEMAND TRACY_NO_CALLSTACK)