安装 cuda 工具包后 glfwCreateWindow() 失败
glfwCreateWindow() fails after installing cuda toolkit
我使用 glew 和 glfw 的程序曾经在 Ubuntu 上运行良好。然后我安装了 cuda 工具包,突然它失败了,因为 glfwCreateWindow() 没有 return 一个指向 GLFWwindow 对象的正确指针。
我使用此处的说明安装了 cuda 工具包:
https://medium.com/geekculture/installing-cudnn-and-cuda-toolkit-on-ubuntu-20-04-for-machine-learning-tasks-f41985fcf9b2
这是一个极简主义的例子:
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(proj)
set (CMAKE_CXX_STANDARD 14)
set(CMAKE_VERBOSE_MAKEFILE ON)
#### use glew ####
find_package(GLEW)
include_directories(${GLEW_INCLUDE_DIRS})
#### use glfw ####
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
ADD_EXECUTABLE(
proj
main.cpp
)
target_link_libraries(proj ${GLFW_STATIC_LIBRARIES} GLEW GLU GL ${GLEW_LIBRARIES} )
main.cpp
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main()
{
int GlobalW=1024;
int GlobalH=800;
if (!glfwInit())
{
std::cout << "GLFW Initialization failed" << std::endl;
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
GLFWwindow* myWindow = glfwCreateWindow(GlobalW, GlobalH, "DDS-Layers", NULL, NULL);
if (!myWindow)
{
std::cout << "failed to create GLFW Window" << std::endl;
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(myWindow);
glfwSwapInterval(0);
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
exit(EXIT_FAILURE);
}
return 1;
}
输出
failed to create GLFW Window
制作
/usr/bin/cmake -S/home/mradwan/c++/play/tryglfw -B/home/mradwan/c++/play/tryglfw/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/mradwan/c++/play/tryglfw/build/CMakeFiles /home/mradwan/c++/play/tryglfw/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/mradwan/c++/play/tryglfw/build'
make -f CMakeFiles/proj.dir/build.make CMakeFiles/proj.dir/depend
make[2]: Entering directory '/home/mradwan/c++/play/tryglfw/build'
cd /home/mradwan/c++/play/tryglfw/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/mradwan/c++/play/tryglfw /home/mradwan/c++/play/tryglfw /home/mradwan/c++/play/tryglfw/build /home/mradwan/c++/play/tryglfw/build /home/mradwan/c++/play/tryglfw/build/CMakeFiles/proj.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/mradwan/c++/play/tryglfw/build'
make -f CMakeFiles/proj.dir/build.make CMakeFiles/proj.dir/build
make[2]: Entering directory '/home/mradwan/c++/play/tryglfw/build'
[ 50%] Linking CXX executable proj
/usr/bin/cmake -E cmake_link_script CMakeFiles/proj.dir/link.txt --verbose=1
/usr/bin/c++ -rdynamic CMakeFiles/proj.dir/main.cpp.o -o proj -lglfw -lrt -lm -ldl -lGLEW -lGLU -lGL -lGLEW
make[2]: Leaving directory '/home/mradwan/c++/play/tryglfw/build'
[100%] Built target proj
make[1]: Leaving directory '/home/mradwan/c++/play/tryglfw/build'
/usr/bin/cmake -E cmake_progress_start /home/mradwan/c++/play/tryglfw/build/CMakeFiles 0
我也定义
export CUDACXX=/usr/local/cuda-11.3/nvcc
export CUDA_LIBRARY_DIRECTORY=/usr/local/cuda-11.3/lib64
export CUDA_INCLUDE_DIRECTORY=/usr/local/cuda-11.3/include
环境:Ubuntu20.04,GeForce RTX 2070
ok,正如@t.niese在评论中所建议的那样,解决方案只是重新启动计算机。我是 Linux 的初学者,但我听说 Linux 优于 Windows 的一个优点是,对于前者,安装 package/software 后无需重新启动].显然,情况并非总是如此。
我使用 glew 和 glfw 的程序曾经在 Ubuntu 上运行良好。然后我安装了 cuda 工具包,突然它失败了,因为 glfwCreateWindow() 没有 return 一个指向 GLFWwindow 对象的正确指针。
我使用此处的说明安装了 cuda 工具包: https://medium.com/geekculture/installing-cudnn-and-cuda-toolkit-on-ubuntu-20-04-for-machine-learning-tasks-f41985fcf9b2
这是一个极简主义的例子:
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(proj)
set (CMAKE_CXX_STANDARD 14)
set(CMAKE_VERBOSE_MAKEFILE ON)
#### use glew ####
find_package(GLEW)
include_directories(${GLEW_INCLUDE_DIRS})
#### use glfw ####
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
ADD_EXECUTABLE(
proj
main.cpp
)
target_link_libraries(proj ${GLFW_STATIC_LIBRARIES} GLEW GLU GL ${GLEW_LIBRARIES} )
main.cpp
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main()
{
int GlobalW=1024;
int GlobalH=800;
if (!glfwInit())
{
std::cout << "GLFW Initialization failed" << std::endl;
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
GLFWwindow* myWindow = glfwCreateWindow(GlobalW, GlobalH, "DDS-Layers", NULL, NULL);
if (!myWindow)
{
std::cout << "failed to create GLFW Window" << std::endl;
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(myWindow);
glfwSwapInterval(0);
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
exit(EXIT_FAILURE);
}
return 1;
}
输出
failed to create GLFW Window
制作
/usr/bin/cmake -S/home/mradwan/c++/play/tryglfw -B/home/mradwan/c++/play/tryglfw/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/mradwan/c++/play/tryglfw/build/CMakeFiles /home/mradwan/c++/play/tryglfw/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/mradwan/c++/play/tryglfw/build'
make -f CMakeFiles/proj.dir/build.make CMakeFiles/proj.dir/depend
make[2]: Entering directory '/home/mradwan/c++/play/tryglfw/build'
cd /home/mradwan/c++/play/tryglfw/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/mradwan/c++/play/tryglfw /home/mradwan/c++/play/tryglfw /home/mradwan/c++/play/tryglfw/build /home/mradwan/c++/play/tryglfw/build /home/mradwan/c++/play/tryglfw/build/CMakeFiles/proj.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/mradwan/c++/play/tryglfw/build'
make -f CMakeFiles/proj.dir/build.make CMakeFiles/proj.dir/build
make[2]: Entering directory '/home/mradwan/c++/play/tryglfw/build'
[ 50%] Linking CXX executable proj
/usr/bin/cmake -E cmake_link_script CMakeFiles/proj.dir/link.txt --verbose=1
/usr/bin/c++ -rdynamic CMakeFiles/proj.dir/main.cpp.o -o proj -lglfw -lrt -lm -ldl -lGLEW -lGLU -lGL -lGLEW
make[2]: Leaving directory '/home/mradwan/c++/play/tryglfw/build'
[100%] Built target proj
make[1]: Leaving directory '/home/mradwan/c++/play/tryglfw/build'
/usr/bin/cmake -E cmake_progress_start /home/mradwan/c++/play/tryglfw/build/CMakeFiles 0
我也定义
export CUDACXX=/usr/local/cuda-11.3/nvcc
export CUDA_LIBRARY_DIRECTORY=/usr/local/cuda-11.3/lib64
export CUDA_INCLUDE_DIRECTORY=/usr/local/cuda-11.3/include
环境:Ubuntu20.04,GeForce RTX 2070
ok,正如@t.niese在评论中所建议的那样,解决方案只是重新启动计算机。我是 Linux 的初学者,但我听说 Linux 优于 Windows 的一个优点是,对于前者,安装 package/software 后无需重新启动].显然,情况并非总是如此。