1

I didn't know how to title this, it's quite unaccurate. Anyway here is the question:

I want to create a CMake project in Visual Studio that has to use glfw. However, I don't want to use the precompiled binaries, I want to compile glfw along with my application using the CMakeLists.txt file.

Here's my CMake file:

# CMakeList.txt : CMake project for BasicMandelbrotAnimation, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)
project(BasicMandelbrotAnimation)

# Set the main file to main.cpp
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:mainCRTStartup")

# Include our different directories
include_directories(include)
include_directories(source)

# Include all source files in source directory
file(GLOB SOURCE source/*)

# Compile GLFW
add_subdirectory(extlibs/GLFW)

# CMake GLFW Settings
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

# Add source to this project's executable.
add_executable (${PROJECT_NAME} ${SOURCE})
target_link_libraries(${PROJECT_NAME} glfw)

find_package(OpenGL REQUIRED)

target_include_directories(${PROJECT_NAME} PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${OPENGL_gl_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${OPENGL_glu_LIBRARY})

# TODO: Add tests and install targets if needed.

The error I get is "Cannot open include file: 'unistd.h': No such file or directory" which is bugging me out because this is a UNIX file so how can I adapt the files to compile in windows?

Thank you.

EDIT:

This questions seemed like a duplicate, but isn't really. unistd.h is only the first problem, let's have a look at the problematic file:

#ifndef _glfw3_x11_platform_h_
#define _glfw3_x11_platform_h_

#include <unistd.h>
#include <signal.h>
#include <stdint.h>
#include <dlfcn.h>

#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xcursor/Xcursor.h>

// The XRandR extension provides mode setting and gamma control
#include <X11/extensions/Xrandr.h>

// The Xkb extension provides improved keyboard support
#include <X11/XKBlib.h>

// The Xinerama extension provides legacy monitor indices
#include <X11/extensions/Xinerama.h>

#if defined(_GLFW_HAS_XF86VM)
 // The Xf86VidMode extension provides fallback gamma control
 #include <X11/extensions/xf86vmode.h>
#endif

Here it is, first of all, unistdh is missing, I replace it with what was proposed in another post, but now it's the others that are missing, specifically dlfcn.h and X11 files and I don't know how to fix that.

Thank you.

EDIT2:

Forget what's inside x11_platform.h. The problem is in this line:

target_link_libraries(${PROJECT_NAME} glfw)

when doing this, cmake need x11_platform.h, that does not exist on windows. Does someone know how to skip this file or link another way?

Thank you.

  • 1
    Possible duplicate of [Is there a replacement for unistd.h for Windows (Visual C)?](https://stackoverflow.com/questions/341817/is-there-a-replacement-for-unistd-h-for-windows-visual-c) – Richard Critten Sep 07 '18 at 06:58
  • I saw that, thing is I'm a learning developper so I don't know where to put that file. Can you help me? –  Sep 07 '18 at 07:04
  • In which file exactly do you get this error? What version of GLFW do you use? `unistd.h` shouldn't be needed on Windows. – joe_chip Sep 07 '18 at 07:19
  • Let me remind that I'm not using precompiled binaries. The version should be 3.2.1, or at least one of the latests. The problematic file is x11_platform.h that's asking for a lot of files that are missing. –  Sep 07 '18 at 07:20
  • `x11_platform.h` this is the problem; there is probably a build configuration you are missing. There is no X11 on MS-Windows. So you need to build for WIn32API and disable X11 support. – Richard Critten Sep 07 '18 at 09:15
  • That's something good to know, I'm gonna search on that thank you! –  Sep 07 '18 at 09:48
  • I can't get it to work. but I know it's this line who's bugged: target_link_libraries(${PROJECT_NAME} glfw) –  Sep 07 '18 at 15:03

0 Answers0