From 6727cc2da407eaa8cdd66b9be5ba0a3bb969aea5 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Tue, 5 May 2020 13:21:59 +0300 Subject: [PATCH] Add empty TRACY_API instead of using dllexport for static builds on windows. Using dllexport is not correct, because it marks APIs in static lib for export and these APIs would get exported from a DLL that links to tracy. Make API use TRACY_EXPORTS, and replace TRACYPROFILER_EXPORTS with TRACY_EXPORTS in vcxproj projects. Swap dllimport with dllexport. Reason for this is a common idiom in CMake: target_compile_definitions(tracy PUBLIC -DTRACY_IMPORTS PRIVATE -DTRACY_EXPORTS). This idiom adds both defines in tracy target, but targets that link to tracy only get TRACY_IMPORTS. Swapped statements ensure that tracy always dllexports it's api and consuming targets always dllimport it. --- common/TracyApi.h | 6 ++++-- library/win32/TracyProfiler.vcxproj | 12 ++++++------ manual/tracy.tex | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/common/TracyApi.h b/common/TracyApi.h index 850ca5c0..a51ee33b 100644 --- a/common/TracyApi.h +++ b/common/TracyApi.h @@ -2,10 +2,12 @@ #define __TRACYAPI_H__ #if defined _WIN32 || defined __CYGWIN__ -# if defined TRACY_IMPORTS +# if defined TRACY_EXPORTS +# define TRACY_API __declspec(dllexport) +# elif defined TRACY_IMPORTS # define TRACY_API __declspec(dllimport) # else -# define TRACY_API __declspec(dllexport) +# define TRACY_API # endif #else # define TRACY_API __attribute__((visibility("default"))) diff --git a/library/win32/TracyProfiler.vcxproj b/library/win32/TracyProfiler.vcxproj index b1e476c3..ef035e22 100644 --- a/library/win32/TracyProfiler.vcxproj +++ b/library/win32/TracyProfiler.vcxproj @@ -124,7 +124,7 @@ Use Level3 true - WIN32;_DEBUG;TRACYPROFILER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + WIN32;_DEBUG;TRACY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true pch.h @@ -139,7 +139,7 @@ Use Level3 true - _DEBUG;TRACYPROFILER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + _DEBUG;TRACY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true pch.h @@ -156,7 +156,7 @@ true true true - WIN32;NDEBUG;TRACYPROFILER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + WIN32;NDEBUG;TRACY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true pch.h @@ -175,7 +175,7 @@ true true true - WIN32;NDEBUG;TRACYPROFILER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + WIN32;NDEBUG;TRACY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true pch.h @@ -194,7 +194,7 @@ true true true - TRACY_ENABLE;NDEBUG;TRACYPROFILER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + TRACY_ENABLE;NDEBUG;TRACY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true @@ -212,7 +212,7 @@ true true true - TRACY_ON_DEMAND;TRACY_ENABLE;NDEBUG;TRACYPROFILER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + TRACY_ON_DEMAND;TRACY_ENABLE;NDEBUG;TRACY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true diff --git a/manual/tracy.tex b/manual/tracy.tex index faed494c..61d3d608 100644 --- a/manual/tracy.tex +++ b/manual/tracy.tex @@ -382,7 +382,7 @@ In projects that consist of multiple DLLs/shared objects things are a bit differ For that you need a \emph{profiler DLL} to which your executable and the other DLLs link. If that doesn't exist you have to create one explicitly for Tracy\footnote{You may also look at the \texttt{library} directory in the profiler source tree.}. This library should contain the \texttt{tracy/TracyClient.cpp} source file. Link the executable and all DLLs which you want to profile to this DLL. -If you are targeting Windows with Microsoft Visual Studio, add the \texttt{TRACY\_IMPORTS} define to your application. While this is an optional step, it enables more efficient code. +If you are targeting Windows with Microsoft Visual Studio or MinGW, add the \texttt{TRACY\_IMPORTS} define to your application. \subsubsection{Problematic platforms}