Skip to content

Commit e041ed1

Browse files
committed
fix compile errors on Linux
On Linux, <sys/time.h> must be included to make struct timeval known. string.h must be included to use memset(). A jump to a label (done_close_file) must not cross local declarations. The corresponding code has been encapsulated in a block. The use of the STRINGIZE macro leads to an error where the compiler sees the #version 430 sequence as an invalid preprocessor directive. Move add_subdirectory(lib/glfw) before examples compile in CmakeList.txt to avoid build dependence error. Reference: jhannemann openglredbook#3 elmindreda openglredbook#5
1 parent 253f197 commit e041ed1

File tree

9 files changed

+13
-3
lines changed

9 files changed

+13
-3
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ set (CMAKE_DEBUG_POSTFIX "_d")
2020

2121
find_package(OpenGL REQUIRED)
2222

23+
add_subdirectory(lib/glfw)
24+
2325
if(WIN32)
2426
set(COMMON_LIBS vermilion ${OPENGL_LIBRARIES} optimized glfw3 debug glfw3_d)
2527
elseif (UNIX)
@@ -101,7 +103,5 @@ ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
101103
include_directories( include )
102104
include_directories(lib/glfw/include)
103105

104-
add_subdirectory(lib/glfw)
105-
106106
ADD_CUSTOM_TARGET(debug ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=Debug ${PROJECT_SOURCE_DIR})
107107
ADD_CUSTOM_TARGET(release ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=Release ${PROJECT_SOURCE_DIR})

include/vapp.h

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#define __VAPP_H__
33

44
#include "vgl.h"
5+
#ifndef _WIN32
6+
#include <sys/time.h>
7+
#endif
58

69
class VermilionApplication
710
{

lib/vbm.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "vgl.h"
55

66
#include <stdio.h>
7+
#include <string.h>
78

89
VBObject::VBObject(void)
910
: m_vao(0),

lib/vdds.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ void vglLoadDDS(const char* filename, vglImageData* image)
603603
if (image->target == GL_NONE)
604604
goto done_close_file;
605605

606+
{
606607
size_t current_pos = ftell(f);
607608
size_t file_size;
608609
fseek(f, 0, SEEK_END);
@@ -641,6 +642,7 @@ void vglLoadDDS(const char* filename, vglImageData* image)
641642
height >>= 1;
642643
depth >>= 1;
643644
}
645+
}
644646

645647
done_close_file:
646648
fclose(f);

src/10-fur/10-fur.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <stdio.h>
1515
#include <stdlib.h>
16+
#include <string.h>
1617

1718
BEGIN_APP_DECLARATION(FurApplication)
1819
// Override functions from base class

src/11-doublewrite/11-doublewrite.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "LoadShaders.h"
1515

1616
#include <stdio.h>
17+
#include <string.h>
1718
#include <string>
1819

1920
#define MAX_FRAMEBUFFER_WIDTH 2048

src/11-oit/11-oit.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "LoadShaders.h"
1515

1616
#include <stdio.h>
17+
#include <string.h>
1718
#include <string>
1819

1920
#define MAX_FRAMEBUFFER_WIDTH 2048

src/11-overdrawcount/11-overdrawcount.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "LoadShaders.h"
1515

1616
#include <stdio.h>
17+
#include <string.h>
1718
#include <string>
1819

1920
#define MAX_FRAMEBUFFER_WIDTH 2048

src/12-particlesimulator/12-particlesimulator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void ComputeParticleSimulator::Initialize(const char * title)
110110
compute_prog = glCreateProgram();
111111

112112
static const char compute_shader_source[] =
113-
STRINGIZE(
113+
STRINGIZE( \
114114
#version 430 core\n
115115

116116
layout (std140, binding = 0) uniform attractor_block

0 commit comments

Comments
 (0)