1. 安装glew(GL), GLFW, glm, soil2-debug
还需要premake生成visual studio solution
cmake for windows也要安装一个, 但是不用安装MinGW64, bug多
下载源码,找到xxx.sln文件用visual stidio打开solution编译代码,找到xxx.lib, xxx.dll文件
include头文件结构:
编译完了创建目录 OpenGLtemplate/{include,lib,bin}
动态库glew32d.dll放到bin目录下,并把E:\library\OpenGLtemplate\bin追加到path环境变量
lib目录下放静态库*.lib
glew32sd.lib是静态库,glew32d.lib其实是动态库,后缀改成dll放到bin目录
或者把依赖的动态库放到项目编译完了.exe文件同级目录,方便发布
visual studio 2022创建console控制台项目
新建cpp文件
- // simple_glfw.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #pragma comment(lib , "glew32d.lib")
- // E:\library\OpenGLtemplate\bin\glew32d.dll, add "E:\library\OpenGLtemplate\bin" to Path env
-
- #include
- #include
- #include
-
- using namespace std;
-
- void init(GLFWwindow * window) {}
-
- void display(GLFWwindow *window, double currentTime) {
- glClearColor(1.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- }
-
- int main()
- {
- if (!glfwInit()) {
- exit(EXIT_FAILURE);
- }
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
- GLFWwindow* window = glfwCreateWindow(600, 600, "Chapter2 - program1", NULL, NULL);
- glfwMakeContextCurrent(window);
- if (glewInit() != GLEW_OK) {
- exit(EXIT_FAILURE);
- }
- glfwSwapInterval(1);
- init(window);
- while (!glfwWindowShouldClose(window)) {
- display(window, glfwGetTime());
- glfwSwapBuffers(window);
- glfwPollEvents();
- }
- glfwDestroyWindow(window);
- glfwTerminate();
- exit(EXIT_SUCCESS);
- }
-
- // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
- // Debug program: F5 or Debug > Start Debugging menu
-
- // Tips for Getting Started:
- // 1. Use the Solution Explorer window to add/manage files
- // 2. Use the Team Explorer window to connect to source control
- // 3. Use the Output window to see build output and other messages
- // 4. Use the Error List window to view errors
- // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
- // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
直接修改.vcxproj文件,等效于Makefile文件
指定依赖的静态库 -l
指定-I, include目录,-L库的路径
完整版:
- "1.0" encoding="utf-8"?>
"Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> -
"ProjectConfigurations"> -
"Debug|Win32"> -
Debug -
Win32 -
-
"Release|Win32"> -
Release -
Win32 -
-
"Debug|x64"> -
Debug -
x64 -
-
"Release|x64"> -
Release -
x64 -
-
-
"Globals"> -
16.0 -
Win32Proj -
{54721bc3-8a74-4187-8468-d0a3707553f1} -
simpleglfw -
10.0 -
-
"$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> -
"'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> -
Application -
true -
v143 -
Unicode -
-
"'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> -
Application -
false -
v143 -
true -
Unicode -
-
"'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> -
Application -
true -
v143 -
Unicode -
-
"'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> -
Application -
false -
v143 -
true -
Unicode -
-
"$(VCTargetsPath)\Microsoft.Cpp.props" /> -
"ExtensionSettings"> -
-
"Shared"> -
-
"PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> -
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> -
-
"PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> -
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> -
-
"PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> -
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> -
-
"PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> -
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> -
-
"UserMacros" /> -
"'$(Configuration)|$(Platform)'=='Debug|x64'"> -
$(PublicIncludeDirectories);E:\library\OpenLtemplate\include; -
$(IncludePath);E:\library\OpenGLtemplate\include; -
$(ReferencePath) -
$(LibraryPath);E:\library\OpenGLtemplate\lib; -
-
"'$(Configuration)|$(Platform)'=='Debug|Win32'"> -
-
Level3 -
true -
WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) -
true -
-
-
Console -
true -
-
-
"'$(Configuration)|$(Platform)'=='Release|Win32'"> -
-
Level3 -
true -
true -
true -
WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) -
true -
-
-
Console -
true -
true -
true -
-
-
"'$(Configuration)|$(Platform)'=='Debug|x64'"> -
-
Level3 -
true -
_DEBUG;_CONSOLE;%(PreprocessorDefinitions) -
true -
-
-
Console -
true -
%(AdditionalLibraryDirectories);E:\library\OpenGLtemplate\lib -
%(AdditionalDependencies);glew32d.lib;glfw3.lib;opengl32.lib;soil2-debug.lib; -
-
-
"'$(Configuration)|$(Platform)'=='Release|x64'"> -
-
Level3 -
true -
true -
true -
NDEBUG;_CONSOLE;%(PreprocessorDefinitions) -
true -
-
-
Console -
true -
true -
true -
-
-
-
"simple_glfw.cpp" /> -
-
"$(VCTargetsPath)\Microsoft.Cpp.targets" /> -
"ExtensionTargets"> -
在界面上并不好找,不如直接改xml,reload solution
等效进入Properties配置
Build
类似的libevent库安装
wget wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
tar xvzf libevent-2.1.12-stable.tar.gz -C .
cd libevent-2.1.12-stable
./autogen.sh
./configure
make
sudo make install
Libraries have been installed in:
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'