Skip to content

Commit 39a0a68

Browse files
Added support to linux - but with missing GL version error
1 parent 6a30c56 commit 39a0a68

File tree

6 files changed

+108
-15
lines changed

6 files changed

+108
-15
lines changed

CMakeLists.txt

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,40 @@ project(${APP_NAME} LANGUAGES CXX)
66

77
set(CMAKE_CXX_STANDARD 17)
88

9-
# Change this variable to `linux` to compile for linux
10-
set(COMPILE_PLATFORM win)
11-
# Uncomment the following line to compile for x86 architecture (32bit)
12-
# set(USE_X86 TRUE)
9+
# Set to x86 for x86 architecture or x64 for x64 architecture
10+
set(ARCHITECTURE_TO_USE x86)
1311

14-
if (USE_X86)
15-
SET(LINK_GL_LIBS ${CMAKE_SOURCE_DIR}/lib/${COMPILE_PLATFORM}/x86)
16-
file(COPY ${CMAKE_SOURCE_DIR}/bin/${COMPILE_PLATFORM}/x86/glew32.dll DESTINATION ${CMAKE_BINARY_DIR}/)
12+
# Make the executable
13+
add_executable(${APP_NAME} main.cpp)
14+
15+
if(WIN32)
16+
# Neccessary variables
17+
SET(LINK_GL_LIBS ${CMAKE_SOURCE_DIR}/lib/win/${ARCHITECTURE_TO_USE})
18+
set(GLEW_SHARED_LIB ${CMAKE_SOURCE_DIR}/bin/win/${ARCHITECTURE_TO_USE}/glew32.dll)
19+
set(GLEW_STATIC_LIB ${LINK_GL_LIBS}/glew32.lib)
20+
set(GLFW_STATIC_LIB ${LINK_GL_LIBS}/glfw3.lib)
21+
# Copy the GLEW static lib
22+
file(COPY ${GLEW_SHARED_LIB} DESTINATION ${CMAKE_BINARY_DIR}/)
23+
find_package(OpenGL REQUIRED)
24+
# Link libs
25+
target_link_libraries(${APP_NAME} ${OPENGL_LIBRARIES} ${GLEW_SHARED_LIB} ${GLFW_SHARED_LIB})
1726
else()
18-
SET(LINK_GL_LIBS ${CMAKE_SOURCE_DIR}/lib/${COMPILE_PLATFORM}/x64)
19-
file(COPY ${CMAKE_SOURCE_DIR}/bin/${COMPILE_PLATFORM}/x64/glew32.dll DESTINATION ${CMAKE_BINARY_DIR}/)
20-
endif ()
27+
SET(LINK_GL_LIBS ${CMAKE_SOURCE_DIR}/lib/linux)
28+
set(GLFW_STATIC_LIB ${LINK_GL_LIBS}/libglfw3.a)
29+
set(GLEW_STATIC_LIB ${LINK_GL_LIBS}/libGLEW.a)
30+
set(GLEW_SHARED_LIB ${CMAKE_SOURCE_DIR}/bin/linux/libGLEW.so.2.1)
2131

22-
find_package(OpenGL)
23-
add_executable(${APP_NAME} main.cpp)
24-
target_link_libraries(${APP_NAME} ${OPENGL_gl_LIBRARY} ${LINK_GL_LIBS}/glfw3.lib ${LINK_GL_LIBS}/glew32.lib)
32+
# Link linux dependencies
33+
find_package(X11 REQUIRED)
34+
find_package(Threads REQUIRED)
35+
find_package(OpenGL REQUIRED)
36+
include_directories(${X11_INCLUDE_DIR})
37+
target_link_libraries(${APP_NAME}
38+
${OPENGL_LIBRARIES}
39+
${GLEW_SHARED_LIB}
40+
${GLEW_STATIC_LIB}
41+
${GLFW_STATIC_LIB}
42+
Threads::Threads
43+
${X11_LIBRARIES}
44+
${CMAKE_DL_LIBS})
45+
endif()

bin/linux/libGLEW.so.2.1

820 KB
Binary file not shown.

lib/linux/glfw_config.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//========================================================================
2+
// GLFW 3.3 - www.glfw.org
3+
//------------------------------------------------------------------------
4+
// Copyright (c) 2010-2016 Camilla Löwy <[email protected]>
5+
//
6+
// This software is provided 'as-is', without any express or implied
7+
// warranty. In no event will the authors be held liable for any damages
8+
// arising from the use of this software.
9+
//
10+
// Permission is granted to anyone to use this software for any purpose,
11+
// including commercial applications, and to alter it and redistribute it
12+
// freely, subject to the following restrictions:
13+
//
14+
// 1. The origin of this software must not be misrepresented; you must not
15+
// claim that you wrote the original software. If you use this software
16+
// in a product, an acknowledgment in the product documentation would
17+
// be appreciated but is not required.
18+
//
19+
// 2. Altered source versions must be plainly marked as such, and must not
20+
// be misrepresented as being the original software.
21+
//
22+
// 3. This notice may not be removed or altered from any source
23+
// distribution.
24+
//
25+
//========================================================================
26+
// As glfw_config.h.in, this file is used by CMake to produce the
27+
// glfw_config.h configuration header file. If you are adding a feature
28+
// requiring conditional compilation, this is where to add the macro.
29+
//========================================================================
30+
// As glfw_config.h, this file defines compile-time option macros for a
31+
// specific platform and development environment. If you are using the
32+
// GLFW CMake files, modify glfw_config.h.in instead of this file. If you
33+
// are using your own build system, make this file define the appropriate
34+
// macros in whatever way is suitable.
35+
//========================================================================
36+
37+
// Define this to 1 if building GLFW for X11
38+
#define _GLFW_X11
39+
// Define this to 1 if building GLFW for Win32
40+
/* #undef _GLFW_WIN32 */
41+
// Define this to 1 if building GLFW for Cocoa
42+
/* #undef _GLFW_COCOA */
43+
// Define this to 1 if building GLFW for Wayland
44+
/* #undef _GLFW_WAYLAND */
45+
// Define this to 1 if building GLFW for OSMesa
46+
/* #undef _GLFW_OSMESA */
47+
48+
// Define this to 1 if building as a shared library / dynamic library / DLL
49+
/* #undef _GLFW_BUILD_DLL */
50+
// Define this to 1 to use Vulkan loader linked statically into application
51+
/* #undef _GLFW_VULKAN_STATIC */
52+
53+
// Define this to 1 to force use of high-performance GPU on hybrid systems
54+
/* #undef _GLFW_USE_HYBRID_HPG */
55+
56+
// Define this to 1 if xkbcommon supports the compose key
57+
/* #undef HAVE_XKBCOMMON_COMPOSE_H */
58+
// Define this to 1 if the libc supports memfd_create()
59+
/* #undef HAVE_MEMFD_CREATE */
60+

lib/linux/libGLEW.a

961 KB
Binary file not shown.

lib/linux/libglfw3.a

416 KB
Binary file not shown.

main.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1+
#define GLEW_STATIC
12
#include "GL/glew.h"
23
#include "GLFW/glfw3.h"
34
#include <iostream>
45

56
int main() {
6-
if(!glfwInit()) exit(EXIT_FAILURE);
7+
if(!glfwInit()) {
8+
exit(EXIT_FAILURE);
9+
}
710

811
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
912
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
1013
GLFWwindow* window = glfwCreateWindow(600, 300, "Test", NULL, NULL);
1114
glfwMakeContextCurrent(window);
12-
if(glewInit() != GLEW_OK) exit(EXIT_FAILURE);
15+
if(window) {
16+
std::cerr << "Failed to create window" << std::endl;
17+
glfwTerminate();
18+
exit(EXIT_FAILURE);
19+
}
20+
21+
if(GLenum err = glewInit(); err != GLEW_OK) {
22+
std::cout << glewGetErrorString(err) << std::endl;
23+
exit(EXIT_FAILURE);
24+
}
1325
glfwSwapInterval(1); // Allow VSync
1426

1527
while(!glfwWindowShouldClose(window)) {

0 commit comments

Comments
 (0)