Skip to content

Commit bfce098

Browse files
committed
Fixed benchmarks failing to compile in debug mode
1 parent cf94efc commit bfce098

12 files changed

Lines changed: 86 additions & 4 deletions
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (C) 2014 Davis E. King (davis@dlib.net)
2+
// License: Boost Software License See LICENSE.txt for the full license.
3+
#ifndef DLIB_TEST_FOR_ODR_VIOLATIONS_CPp_
4+
#define DLIB_TEST_FOR_ODR_VIOLATIONS_CPp_
5+
6+
#include "test_for_odr_violations.h"
7+
8+
extern "C"
9+
{
10+
// The point of this block of code is to cause a link time error that will prevent a user
11+
// from compiling part of their application with DLIB_ASSERT enabled and part with them
12+
// disabled since doing that would be a violation of C++'s one definition rule.
13+
#ifdef ENABLE_ASSERTS
14+
const int USER_ERROR__inconsistent_build_configuration__see_dlib_faq_1 = 0;
15+
#else
16+
const int USER_ERROR__inconsistent_build_configuration__see_dlib_faq_1_ = 0;
17+
#endif
18+
19+
20+
// The point of this block of code is to cause a link time error if someone builds dlib via
21+
// cmake as a separately installable library, and therefore generates a dlib/config.h from
22+
// cmake, but then proceeds to use the default unconfigured dlib/config.h from version
23+
// control. It should be obvious why this is bad, if it isn't you need to read a book
24+
// about C++. Moreover, it can only happen if someone manually copies files around and
25+
// messes things up. If instead they run `make install` or `cmake --build . --target
26+
// install` things will be setup correctly, which is what they should do. To summarize: DO
27+
// NOT BUILD A STANDALONE DLIB AND THEN GO CHERRY PICKING FILES FROM THE BUILD FOLDER AND
28+
// MIXING THEM WITH THE SOURCE FROM GITHUB. USE CMAKE'S INSTALL SCRIPTS TO INSTALL DLIB.
29+
// Or even better, don't install dlib at all and instead build your program as shown in
30+
// examples/CMakeLists.txt
31+
#if defined(DLIB_NOT_CONFIGURED) && !defined(DLIB__CMAKE_GENERATED_A_CONFIG_H_FILE)
32+
const int USER_ERROR__inconsistent_build_configuration__see_dlib_faq_2 = 0;
33+
#endif
34+
35+
36+
37+
38+
39+
#ifdef DLIB_CHECK_FOR_VERSION_MISMATCH
40+
const int DLIB_CHECK_FOR_VERSION_MISMATCH = 0;
41+
#endif
42+
43+
}
44+
45+
46+
#endif // DLIB_TEST_FOR_ODR_VIOLATIONS_CPp_
47+

build/makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ bin/fuzztests$(EXT): ../concurrentqueue.h ../tests/fuzztests/fuzztests.cpp ../te
3838
test -d bin || mkdir bin
3939
g++ -std=c++11 -Wall -pedantic-errors -Wpedantic $(BENCH_OPTS) ../tests/common/simplethread.cpp ../tests/common/systemtime.cpp ../tests/fuzztests/fuzztests.cpp -o bin/fuzztests$(EXT) $(LD_OPTS)
4040

41-
bin/benchmarks$(EXT): bin/libtbb.a ../concurrentqueue.h ../benchmarks/benchmarks.cpp ../benchmarks/cpuid.h ../benchmarks/cpuid.cpp ../benchmarks/lockbasedqueue.h ../benchmarks/simplelockfree.h ../tests/common/simplethread.h ../tests/common/simplethread.cpp ../tests/common/systemtime.h ../tests/common/systemtime.cpp makefile
41+
bin/benchmarks$(EXT): bin/libtbb.a ../concurrentqueue.h ../benchmarks/benchmarks.cpp ../benchmarks/cpuid.h ../benchmarks/cpuid.cpp ../benchmarks/lockbasedqueue.h ../benchmarks/simplelockfree.h ../tests/common/simplethread.h ../tests/common/simplethread.cpp ../tests/common/systemtime.h ../tests/common/systemtime.cpp ../benchmarks/dlib/test_for_odr_violations.cpp makefile
4242
test -d bin || mkdir bin
43-
g++ -std=c++11 -Wall -pedantic-errors -Wpedantic $(BENCH_OPTS) -I../benchmarks ../benchmarks/cpuid.cpp ../tests/common/simplethread.cpp ../tests/common/systemtime.cpp ../benchmarks/benchmarks.cpp -o bin/benchmarks$(EXT) -Lbin -ltbb $(LD_OPTS)
43+
g++ -std=c++11 -Wall -pedantic-errors -Wpedantic $(BENCH_OPTS) -I../benchmarks ../benchmarks/cpuid.cpp ../tests/common/simplethread.cpp ../tests/common/systemtime.cpp ../benchmarks/dlib/test_for_odr_violations.cpp ../benchmarks/benchmarks.cpp -o bin/benchmarks$(EXT) -Lbin -ltbb $(LD_OPTS)
4444

4545
bin/libtbb.a: makefile
4646
test -d bin || mkdir bin

build/msvc11/benchmarks.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4244;4800</DisableSpecificWarnings>
169169
</ClCompile>
170170
<ClCompile Include="..\..\benchmarks\cpuid.cpp" />
171+
<ClCompile Include="..\..\benchmarks\dlib\test_for_odr_violations.cpp" />
171172
<ClCompile Include="..\..\benchmarks\tbb\cache_aligned_allocator.cpp">
172173
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">__TBB_BUILD=1;USE_WINTHREAD;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
173174
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">__TBB_BUILD=1;USE_WINTHREAD;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>

build/msvc11/benchmarks.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<Filter Include="Source Files\tbb">
1313
<UniqueIdentifier>{6d3507c8-0e7e-45de-90d5-9daacabc8d2b}</UniqueIdentifier>
1414
</Filter>
15+
<Filter Include="Source Files\dlib">
16+
<UniqueIdentifier>{3dfee594-40d0-4fea-992a-3958d8494fdd}</UniqueIdentifier>
17+
</Filter>
1518
</ItemGroup>
1619
<ItemGroup>
1720
<ClCompile Include="..\..\benchmarks\benchmarks.cpp">
@@ -47,6 +50,9 @@
4750
<ClCompile Include="..\..\benchmarks\tbb\spin_mutex.cpp">
4851
<Filter>Source Files\tbb</Filter>
4952
</ClCompile>
53+
<ClCompile Include="..\..\benchmarks\dlib\test_for_odr_violations.cpp">
54+
<Filter>Source Files\dlib</Filter>
55+
</ClCompile>
5056
</ItemGroup>
5157
<ItemGroup>
5258
<ClInclude Include="..\..\tests\common\simplethread.h">

build/msvc12/benchmarks.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4244;4800</DisableSpecificWarnings>
169169
</ClCompile>
170170
<ClCompile Include="..\..\benchmarks\cpuid.cpp" />
171+
<ClCompile Include="..\..\benchmarks\dlib\test_for_odr_violations.cpp" />
171172
<ClCompile Include="..\..\benchmarks\tbb\cache_aligned_allocator.cpp">
172173
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">__TBB_BUILD=1;USE_WINTHREAD;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
173174
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">__TBB_BUILD=1;USE_WINTHREAD;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>

build/msvc12/benchmarks.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<Filter Include="Source Files\tbb">
1313
<UniqueIdentifier>{6d3507c8-0e7e-45de-90d5-9daacabc8d2b}</UniqueIdentifier>
1414
</Filter>
15+
<Filter Include="Source Files\dlib">
16+
<UniqueIdentifier>{3dfee594-40d0-4fea-992a-3958d8494fdd}</UniqueIdentifier>
17+
</Filter>
1518
</ItemGroup>
1619
<ItemGroup>
1720
<ClCompile Include="..\..\benchmarks\benchmarks.cpp">
@@ -47,6 +50,9 @@
4750
<ClCompile Include="..\..\benchmarks\tbb\spin_mutex.cpp">
4851
<Filter>Source Files\tbb</Filter>
4952
</ClCompile>
53+
<ClCompile Include="..\..\benchmarks\dlib\test_for_odr_violations.cpp">
54+
<Filter>Source Files\dlib</Filter>
55+
</ClCompile>
5056
</ItemGroup>
5157
<ItemGroup>
5258
<ClInclude Include="..\..\tests\common\simplethread.h">

build/msvc14/benchmarks.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4244;4800</DisableSpecificWarnings>
169169
</ClCompile>
170170
<ClCompile Include="..\..\benchmarks\cpuid.cpp" />
171+
<ClCompile Include="..\..\benchmarks\dlib\test_for_odr_violations.cpp" />
171172
<ClCompile Include="..\..\benchmarks\tbb\cache_aligned_allocator.cpp">
172173
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">__TBB_BUILD=1;USE_WINTHREAD;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
173174
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">__TBB_BUILD=1;USE_WINTHREAD;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>

build/msvc14/benchmarks.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<Filter Include="Source Files\tbb">
1313
<UniqueIdentifier>{6d3507c8-0e7e-45de-90d5-9daacabc8d2b}</UniqueIdentifier>
1414
</Filter>
15+
<Filter Include="Source Files\dlib">
16+
<UniqueIdentifier>{3dfee594-40d0-4fea-992a-3958d8494fdd}</UniqueIdentifier>
17+
</Filter>
1518
</ItemGroup>
1619
<ItemGroup>
1720
<ClCompile Include="..\..\benchmarks\benchmarks.cpp">
@@ -47,6 +50,9 @@
4750
<ClCompile Include="..\..\benchmarks\tbb\spin_mutex.cpp">
4851
<Filter>Source Files\tbb</Filter>
4952
</ClCompile>
53+
<ClCompile Include="..\..\benchmarks\dlib\test_for_odr_violations.cpp">
54+
<Filter>Source Files\dlib</Filter>
55+
</ClCompile>
5056
</ItemGroup>
5157
<ItemGroup>
5258
<ClInclude Include="..\..\tests\common\simplethread.h">

build/msvc15/benchmarks.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4244;4800</DisableSpecificWarnings>
170170
</ClCompile>
171171
<ClCompile Include="..\..\benchmarks\cpuid.cpp" />
172+
<ClCompile Include="..\..\benchmarks\dlib\test_for_odr_violations.cpp" />
172173
<ClCompile Include="..\..\benchmarks\tbb\cache_aligned_allocator.cpp">
173174
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">__TBB_BUILD=1;USE_WINTHREAD;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
174175
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">__TBB_BUILD=1;USE_WINTHREAD;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>

build/msvc15/benchmarks.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<Filter Include="Source Files\tbb">
1313
<UniqueIdentifier>{6d3507c8-0e7e-45de-90d5-9daacabc8d2b}</UniqueIdentifier>
1414
</Filter>
15+
<Filter Include="Source Files\dlib">
16+
<UniqueIdentifier>{3dfee594-40d0-4fea-992a-3958d8494fdd}</UniqueIdentifier>
17+
</Filter>
1518
</ItemGroup>
1619
<ItemGroup>
1720
<ClCompile Include="..\..\benchmarks\benchmarks.cpp">
@@ -47,6 +50,9 @@
4750
<ClCompile Include="..\..\benchmarks\tbb\spin_mutex.cpp">
4851
<Filter>Source Files\tbb</Filter>
4952
</ClCompile>
53+
<ClCompile Include="..\..\benchmarks\dlib\test_for_odr_violations.cpp">
54+
<Filter>Source Files\dlib</Filter>
55+
</ClCompile>
5056
</ItemGroup>
5157
<ItemGroup>
5258
<ClInclude Include="..\..\tests\common\simplethread.h">

0 commit comments

Comments
 (0)