Ubuntu&Fedora装机&Mac装机(UOS装机将会持续更新)

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
243750496
帖子: 1038
注册时间: 2012-06-09 15:40

Re: Ubuntu&Fedora装机&Mac装机(Mac装机将会持续更新)

#421

帖子 243750496 » 2017-12-17 21:38

sudo sh -c 'echo "deb https://atlassian.artifactoryonline.com ... apt-client $(lsb_release -c -s) main" > /etc/apt/sources.list.d/atlassian-hipchat4.list'

wget -O - https://atlassian.artifactoryonline.com ... key/public | sudo apt-key add -

sudo apt-get update

sudo apt-get install hipchat4

推荐个软件:
gravity designer(Illustrator的替代品,Linux+Mac+Windows+Web)
改头像:community->点击头像->齿轮图标(Preference)->Account->Profile Picture

推荐VPN:
Nord VPN(Purevpn不行了):99美元/3年

photoshop延时显示的bug在configure wine中设置为xp系统即可解决


illustrator中dash line的使用方法:
stroke_5382_3467.jpg
stroke_5382_3467.jpg (46.65 KiB) 查看 17705 次
06tyi91_3840.gif
06tyi91_3840.gif (4.34 KiB) 查看 17705 次
上次由 243750496 在 2018-01-12 18:07,总共编辑 9 次。
243750496
帖子: 1038
注册时间: 2012-06-09 15:40

Re: Ubuntu&Fedora装机&Mac装机(Mac装机将会持续更新)

#422

帖子 243750496 » 2017-12-29 20:25

现代编程语言是用什么语言写成

对于脚本型语言通常是c写的,包括解析器(编译器和执行器)和大部分基础的标准库(比较高阶的库才会用本语言写)。从这个意义上来说,脚本语言只是c的wrapper,正因为如此,所以才会有人喊python的sort居然比go快之类的说法,其实就算是python的sort快,那也只证明了c比go快。但也有一些语言的解析器用c++写(比如V8)。
对于编译型语言,通常编译器也是c写的(但编译器对性能要求不高,理论上可以用任何语言完成)。执行器则分为两种情况:一种编译为机器码的,执行器自然是cpu(比如c++、go这类)。另一种编译为bytecode的,这种执行器一般用c写,但是由于性能方面的考虑,通常会执行器(也就是vm)会把bytecode变成机器码让cpu直接执行。至于标准库,编译型语言通常倾向于用本语言完全重写,而不是去依赖c库。
Go语言是编译型语言里面比较奇葩的。由于Go语言的目标是成为下一个C语言,所以整个Go语言的实现过程中,尽量减少了对c语言的依赖,大部分的工具链都是用Go语言自身来完成。其基本思路是:用gcc或其他标准c的编译器,编译出一个Go特有的c编译器,然后用这个特有的c编译器,来编译Go语言工具链中那些不得不用c写的部分,包括go的编译器。
有人问c是用什么写的。实际上现在多数c编译器都是c写的,大家去看看gcc的代码就知道了。其实,现在汇编编译器一般也是c写的。
从鸡生蛋的角度,编译器的进化史应该是这样的:先用机器码直接写第一个汇编编译器,然后汇编编译器编出第一个c编译器。有c编译器后可以反过来用c重写汇编编译器和c编译器,做更多的功能增强。这个过程理论上每出现一种新cpu指令集、新操作系统就需要重新来一遍。但是人是聪明的。所以交叉编译这样的东西产生了,这就避免需要把整个编译器进化史重新演绎一遍。



什么是交叉编译????????

举个例子来解答。
我们的电脑PC的CPU是intel或者AMD的,这种CPU全部是x86架构的,内在指令是一样的。
而嵌入式linux的CPU一般是ARM的,这种CPU的指令架构和x86完全不同。
如果,你在电脑上写了个C语言程序,然后编译运行,但是这种程序只能在PC上,也就是intel或AMD的CPU上运行。你下载到ARM的机器上是不能运行的。
如果想要运行,就要在PC上根据ARM的指令架构来编译程序。
这种在这种架构的CPU机子上编译另外一种架构CPU的软件,就叫做“交叉”编译。交叉CROSS就是这个意思。


怎么用C++写图形界面程序?
我说的不是控制台,就是有边界有框,正常一点的界面


看的人比较多,所以我觉得还是完善一下回答比较好!//2017年10月17日0点28分

这个问题问得非常好,虽然问题中的描述不准确,但我们都知道他想问的问题是什么意思:就是怎样用C++写一个有窗体界面的程序(很有可能是指在Windows下)。先回答一下这个问题,答案在这儿:从WinMain开始

回想当年,我初学C语言的时候,也有这样的困惑:为啥我写的程序背景是黑不溜秋的,文字也是一行一行显示的,而别人写的程序都带着界面和按钮?

这得从何说起呢?

由于我们最常接触的就是Windows系统中各种带有窗体的程序,使得很多人误以为,这就是程序原本的样子……其实程序原本是没有界面的,就一堆代码在CPU里跑,之所以有界面,是因为人类自身的需要。人类发明了一些硬件设备,来展示程序的过程和结果,最常见的就是普通的电脑显示器。最早我们用一行行的文字来显示界面,俗称CLI(就是控制台,终端,命令行这类界面),随着科技的进步,后来我们发展出了更加人性化的图形界面,俗称GUI。但CLI并没有消失,甚至在某些应用场合,它比GUI方便得多。

其实代码的本质就是控制硬件,比如在显示器上显示一个点,其实是程序对某个硬件进行赋值操作(不同的硬件设备在程序里有着不同的地址,这就是总线结构),所以你要在屏幕上画个点,本质上就是往某个地址上写个值,简单来说就是这样。这个东西也叫作驱动程序。

通过控制屏幕显示各种各样不同的点,我们就可以弄出各种图案,比如窗口啊,按钮啊,文字啊,图片啊,2D或者3D动画啊,这个东西就叫作计算机图形学。

然而我们在Windows这种操作系统下开发程序,并不用关心怎么样去绘制一个窗口或文字,因为已经有人把这部分工作给我们做好了,并且封装成了一个个的函数或类,俗称API(应用程序接口),我们只要调用那个函数,告诉操作系统,给我画个窗口吧,它就屁颠屁颠的去帮你干活了,就是这么简单。

把一堆API打包装在一起,就变成了库。

在命令行上面显示“hello world”和在窗口上显示“hello world”的区别,只是使用了不同库中的不同API而已。对于程序员来说,并没有本质上的区别,仅仅只是调用的函数不一样。

所以,我们实际开发时,需要学习这些API怎么用,有哪些特点,这就属于应用开发的内容了,比如“Windows编程”,“wxWidget应用开发”等等等等……手机软件开发,也是一样的原理。所以,学完C++只是第一步,接下来,如何在相应的操作系统环境下开发软件,还需要学习相应的API。
243750496
帖子: 1038
注册时间: 2012-06-09 15:40

Re: Ubuntu&Fedora装机&Mac装机(Mac装机将会持续更新)

#423

帖子 243750496 » 2018-03-05 19:27

固态硬盘的TRIM功能可以避免SSD在GC时将无用数据进行错误搬运,浪费读取时间,从而起到对固态硬盘寿命的延长作用的。但是,如果操作环境是在机械硬盘中,已删除文件系统会进行逻辑位置的标记,使得以后存储数据时能够直接在这些无用数据的逻辑位置上覆盖。但固态硬盘因为是闪存的原因所以没有这种机制,主控并不知道这些数据已经无用,直到有新的数据要求写入该块。这将导致无用数据在垃圾回收(GC)过程中被当作有用数据对待,这无疑会大大降低硬盘效率和使用寿命。因此TRIM的出现就能够弥补该问题的缺陷。


方法/步骤



1


首先检查自身电脑是否已经开启TRIM

只须一个命令就可查看,步骤如下:

在搜索栏中找到“命令提示符”并以管理员身份运行



win10中TRIM如何开启.

2


然后执行如下命令:

fsutil behavior query disabledeletenotify


如果返回值为“0”证明TRIM已经开启;如果返回值是“1”,则说明当前电脑的SSD尚未开启TRIM



win10中TRIM如何开启.

3


这个时候你就需要重新手动开启,请重新打开命令:

同样以管理员的身份运行“命令提示符”然后手动输入

fsutil behavior set disabledeletenotify 0

Win10下依然可用的软件
CleanMyPC
DataRescue
Picture Rescue
BatchPhoto
wiznote
ITunes
NordVPN
Adobe 系列
Alcohol (需要先付费然后在账户里下载可注册版本,否则有捆绑软件报毒,且无法注册只能试用)
DataColor系列(红蜘蛛、打印蜘蛛、48色卡)
dia(流程图,跨平台,免费,因此方便在任何地方安装和交流使用)
3D Coat
FastRawViewer(查看Raw图片+exif信息的好工具)
RawDigger(一个曝光是否准确的极为严谨的的检测软件)
PCMover(迁移旧PC到新PC的好工具)
Modo(商业3d软件)
steam上的Substance B2M+Designer+Painter(替代Mari,因为Mari现在只允许按月订阅1个软件,否则只能按年)
Autodesk Eagle(电路绘制软件)
BricsCAD
Bitwig Studio(音乐制作软件)
Discord(游戏语音工具)
Dacuda PocketScan(口袋扫描仪应用)
Cura Mostfun专版(Sail专用):机型->机型设置->端口Com3,波特率115200,文件->偏好配置->打印窗口类型:Pronterface UI,View Mode:Layers(如果这里显示不出来就说明是模型的问题而不是软件错误)
QQ
百度输入法(搜狗广告太多)
注:Alt+Shift为切换输入法快捷键
Wacom数位板驱动
罗技C930e驱动
微信
Kindle For PC
SketchBook
Guitar Pro 7
迅雷U享版(迅雷9广告太多了)
工商银行
ArtPose Pro(Steam上参考肌肉的好软件,30RMB)
Snipaste 类似Setuna的截屏参考软件(未来会推出linux版)
openCanvas7(windows下类似Sai画原画的好软件)steam上有 Preference->Documents->Touch Operation->Enable Touch Operation 取消勾选,就不会绘制时平移了
解剖参考(查看肌肉、骨骼的软件)visiblebody出品
Muscle Premium for Windows Desktop
Muscle Premium for Windows Desktop
Anatomy & Physiology for Windows Desktop
Open 3D Model Viewer(免费的查看3d模型的软件)
游戏:
Farm Together(农场)
Tale of Toast(网游)
打印机色彩管理设置(打印蜘蛛在执行打印前对打印机的设置):设置高光纸+选择高质量照片模式+去掉照片增强+去掉高速打印选项+使用ICM无色彩管理选项
主窗口.PNG
高级.PNG
L800 HYMN Diamond.icm->C:\Windows\System32\spool\drivers\color
243750496
帖子: 1038
注册时间: 2012-06-09 15:40

Re: Ubuntu&Fedora装机&Mac装机(Mac装机将会持续更新)

#424

帖子 243750496 » 2018-03-22 12:31

关掉这些,让WIN10快成一道“闪电”

1、替换自带的杀毒软件Windows Defender

这款软件杀毒方面并不是很棒,而且我们使用也不习惯,建议选择第三方杀毒软件。安装后,系统自动关闭自带杀毒软件Windows Defender。因为它开启会消耗CPU资源!


2、关闭IPV6

这个除了大型网络能使用上,家庭或者在日常工作中很少几乎不使用,不光占用系统资源,同时也是很多问题的元凶。

操作:右键单击【此电脑】——【管理】——【计算机管理】,左侧菜单点【服务】,右侧窗口找到【IPHelper】,右击并选择【属性】,将【启动类型】修改为【禁用】,保存即可


3、关闭家庭组

这个给家庭内部电脑共享文件用的,我们多数人家中一到两台电脑,也几乎用不到文件共享,故此功能也可关闭,开着也是占用CPU、导致卡顿的元凶之一。

操作:右键桌面【此电脑】——【管理】——【计算机管理】,在左侧菜单中点击【服务】,右侧窗格找到【HomeGroup Listener】和【HomeGroup Provider】两者都选择属性并禁用,保存!

4、关闭Windows Search

win10会自动在后台建立索引记录Windows Search。像个搜索引擎,搜索本机的所有文件,现在电脑大多数配备了固态盘(SSD)响应很快,Windows Search实际意义不大。

操作跟上方步骤前面相同,在【服务】右侧窗格找到【Windows Search】,右击属性并选择禁用。



5、设置自动登录

使用密码登录Windows的是一个内部安全机制,在家使用或者不担心重要资料外泄,建议关闭设置自动登录,也可加快Win 10运转

操作:点击任务栏左侧Cortana搜索框,输入【netplwiz】回车,选中当前账号,取消”要使用本计算机,用户必须输入用户名和密码“前面的复选框。点击确定后需要再次输入密码。以后就可直接登录电脑了,直接进入桌面!

6、自动优化驱动器

硬盘分为传统盘(HDD)和固态硬盘(SSD)两种。他们都需要定期的维护操作。简单说,HHD用磁盘碎片整理,SSD用则是TRIM。我设置为自动运行后,WIN10会自动根据磁盘类别进行适合的磁盘优化方式,这样大幅度降低系统日常运行时所产生的卡顿情况。

操作:打开【此电脑】,右击某一个硬盘驱动选择【属性】,点击【工具】——【优化】——【已计划的优化】——【更改设置】。保持【按计划运行】复选框勾选。



7、修改默认电源计划

win10自带三组电源模式,分别是”平衡“、”高性能“、”节能“。不同模式的功效不同。我们选这”高性能“发挥全部电脑性能

操作:右击开始按钮,点击【电源选项】——【其他电源选项】,将首选计划改为”高性能“,然后点击”高性能“右侧的【更改计划设置】——【更改高级电源设置】。将【无线适配器设置】修改为【最高性能】、【PCI Express】修改为【关闭】、【处理器电源管理】——【处理器最大频率】修改为【当前电脑CPU最高功率】。

8、开启快速启动

WIN 10具有“快速启动”功能,这项功能简化开机前的一系列检查步骤来提高Win 10的开机用时。

还有,开启“快速启动”后,Win 10还能在每次关机时,自动将一部分内存数据存储到硬盘上,下次开机可直接调用。从而进一步提升Win 10的开机速度。



操作:点击【开始】菜单——【设置】——【系统(显示、通知、电源)】——【电源和睡眠】——【其他电源设置】,在弹出的面板中点击【选择电源按钮的功能】——【更改当前不可用的设置】勾选【启动快速启动】。
243750496
帖子: 1038
注册时间: 2012-06-09 15:40

Re: Ubuntu&Fedora装机&Mac装机(Mac装机将会持续更新)

#425

帖子 243750496 » 2018-03-27 22:54

windows10下编译gimp 2.10源码
下载MSYS2 64bit
运行:pacman -Syu如果按照gimp上说的pacman -Sy pacman则会出现无反馈的情况
然后提示关闭
然后再运行一遍
pacman -Syu
正式进入依赖安装(有的依赖不安会导致其他依赖无法安装从而导致安装失败,所以如果有哪个依赖安装失败就重新执行此命令1遍)
pacman -S mingw-w64-x86_64-atk mingw-w64-x86_64-babl mingw-w64-x86_64-cairo mingw-w64-x86_64-fontconfig mingw-w64-x86_64-freetype mingw-w64-x86_64-gdk-pixbuf2 mingw-w64-x86_64-gegl mingw-w64-x86_64-glib-networking mingw-w64-x86_64-gtk3 mingw-w64-x86_64-harfbuzz mingw-w64-x86_64-libjpeg-turbo mingw-w64-x86_64-libmypaint mingw-w64-x86_64-libpng mingw-w64-x86_64-poppler mingw-w64-x86_64-librsvg mingw-w64-x86_64-libtiff mingw-w64-x86_64-lcms2 mingw-w64-x86_64-libmypaint mingw-w64-x86_64-poppler-data mingw-w64-x86_64-jasper mingw-w64-x86_64-libmng mingw-w64-x86_64-libwebp mingw-w64-x86_64-libwmf mingw-w64-x86_64-icoutils mingw-w64-x86_64-tkimg mingw-w64-x86_64-openexr mingw-w64-x86_64-python2 mingw-w64-x86_64-webkitgtk3 libtool mingw-w64-x86_64-gtk-doc automake1.15 intltool autoconf gtk-doc glib2-devel mingw-w64-x86_64-gtk-engines mingw-w64-x86_64-python3-gobject mingw-w64-x86_64-gtk3 mingw-w64-x86_64-glade mingw-w64-x86_64-devhelp mingw-w64-x86_64-python3-gobject mingw-w64-x86_64-python2-gobject mingw-w64-x86_64-toolchain base-devel

cd 'C:\msys64\home\Anti Chen\'
vim .bash_profile
Next, edit your .bash_profile, and add these lines:
export PREFIX=`realpath ~/prefix`
export PATH="$PREFIX/bin:$PATH"
export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH"
export LD_LIBRARY_PATH="$PREFIX/lib:$LD_LIBRARY_PATH"
然后保存并输入下面命令:
. .bash_profile
然后
cd 'C:\Users\Anti Chen\Downloads'
cd gimp-GIMP_2_10_0_RC1
./autogen.sh
make
make install
但是出了以下错误
AM_PATH_GTK_2_0 not found in library
所以还是等exe正式版放出来吧,在此只做个记录方便需要的人,不费劲捣鼓了
243750496
帖子: 1038
注册时间: 2012-06-09 15:40

Re: Ubuntu&Fedora装机&Mac装机(Mac装机将会持续更新)

#426

帖子 243750496 » 2018-03-30 16:24

notepad++安装plugin manager(默认不带)
下载:https://github.com/bruderstein/nppPlugi ... r/releases
拷贝:
PluginManager.dll到plugins下
gpup到updater下
重启notepad++然后就可以安装NppExec了

注:如果用notepad++转换为ANSI编码编译后运行仍然无法去除乱码,那么你肯定忘保存了

Clangbuilder
下载以下安装包(所有和C++有关的安装包都安上)
1.png
2.png
3.png
Automated tools help developers on Windows platforms building LLVM and clang.

Installation

PowerShell Policy

Often you need to change the Power Shell execution policy

Get-ExecutionPolicy

Output:


Restricted

Please run PowerShell with administrator rights, and Enter:

Set-ExecutionPolicy RemoteSigned

General Setup

Clone clangbuilder on Github

git clone https://github.com/fstudio/clangbuilder.git clangbuilder

Click the script/InitializeEnv.bat

The installation script will compile ClangbuilderUI and create a shortcut, download required packages.
然后在clangbuilder-master根目录下双击ClangbuilderUI 运行就OK了
注意编译时不要干别的否则会在Win10下黑屏
If your need install VisualCppTools.Community.Daily ,click script/VisualCppToolsFetch.bat

Paste this code into the notepad++ run section
cmd /k cd $(CURRENT_DIRECTORY) && clang $(FILE_NAME) -o $(NAME_PART).exe && $(NAME_PART).exe && pause -std=c99




GLEW的安装
为了能够使用openGL的扩展库,我们可以安装glew来实现,介于本人痛苦的安装经历,我打算将我的成功安装心得告诉大家,希望大家能够免受软件的安装痛苦,更多的享受openGL的编程乐趣!!!

我的编译环境为VS2005,系统为win764位。首先我们可以到http://glew.sourceforge.net/下载最新的glew文件,将文件解压后将看到多个文件,将bin\release\Win32\glew32.dll放到C:\Windows\SysWOW64中,再将lib\release\x64里的文件复制到C:\\Program Flies(X86)\Visual Studio8\VC\Platform SDK\Lib中,再将include\GL\glew.h复制到C:\\Program Flies(X86)\Visual Studio8\VC\Platform SDK\Include\gl中。到这里我们还差一步。

在我们的工程文件里#include <gl/glew.h>
#include <GL/glut.h>
#include <stdlib.h>
#pragma comment(lib,"glew32.lib")

注意两点,一、glew.h要放在glut.h前

二、必须加上 #pragma comment(lib,"glew32.lib")

希望对大家能有所帮助!
GLEW是一个跨平台的C++扩展库,基于OpenGL图形接口。使用OpenGL的朋友都知道,window目前只支持OpenGL1.1的涵数,但 OpenGL现在都发展到2.0以上了,要使用这些OpenGL的高级特性,就必须下载最新的扩展,另外,不同的显卡公司,也会发布一些只有自家显卡才支 持的扩展函数,你要想用这数涵数,不得不去寻找最新的glext.h,有了GLEW扩展库,你就再也不用为找不到函数的接口而烦恼,因为GLEW能自动识 别你的平台所支持的全部OpenGL高级扩展涵数。也就是说,只要包含一个glew.h头文件,你就能使用gl,glu,glext,wgl,glx的全 部函数。GLEW支持目前流行的各种操作系统(including Windows, Linux, Mac OS X, FreeBSD, Irix, and Solaris)。

glu是实用库,包含有43个函数,函数名的前缀为glu。Glu 为了减轻繁重的编程工作,封装了OpenGL函数,Glu函数通过调用核心库的函数,为开发者提供相对简单的用法,实现一些较为复杂的操作。
glaux是OpenGL辅助库,包含有31个函数,函数名前缀为aux。这部分函数提供窗口管理、输入输出处理以及绘制一些简单三维物体。
glut是实用工具库,基本上是用于做窗口界面的,并且是跨平台(所以有时你喜欢做简单的demo的话,可以光用glut就ok了)


GLX:OpenGL extension for X.

对于X窗口系统,它所使用的的OpenGL扩展(GLX)是作为OpenGL的一个附件提供的,所有的GLX函数都使用前缀glX。


VS2017中nuget获取的glew安装包是需要新建一个Project并且保存ctrl+Shift+S才能下载的,因此推断并不会在编译clang时候作为一个功能来添加上,因此只能采用拷贝相应文件的方法进行安装

bin/glew32.dll to C:/windows/system32
lib/glew32.lib to D:/Programs/LLVM/lib/clang/4.0.0/lib/windows
include/GL/glew.h to D:/Programs/LLVM/lib/clang/4.0.0/include/GL
include/GL/wglew.h to D:/Programs/LLVM/lib/clang/4.0.0/include/GL

测试程序:
#include <windows.h>
#include <GL/glew.h>
// Add a main function
int main() {}


C语言究竟可不可以使用OpenGL编程?网上多的是VC++的,delphi的等等
可我就是不想学VC++,用C语言又不知道怎么初始化设置,好痛苦的。
比方说VC++中,是这样设置的:
1.将glut.dll和glut32.dll拷贝到windows/system32目录下。
2.将glut.h拷贝到集成环境安装目录的include/gl子目录下(如果不存在gl子目录,则创建它)。
3.将glut32.lib拷贝到集成环境安装目录的lib子目录下.
请进门的指点指点啊......
问题补充:

fengjian 兄台:
你推荐的《OpenGL 超级宝典》我下次就到图书馆去借
下面的话我不理解:
“最后在工程编译时,在工程中加入需要的库,有关命令行加入,glu32 opengl32 glut32库就可以编译了。 ”
我用C语言的时候,就是直接点run,一个简单的hello.c,怎么有工程的概念?上面的3个库glu32 opengl32 glut32加入到哪里,能不能说详细一点,拜托了



最佳答案
OpenGL就是基于C语言的,当然可以使用C语言。关于C语言的一本很好书籍为:《OpenGL 超级宝典》现在有第三版中译本,建议使用第二版。我就是靠它入门的。
你上面所说的步骤是正确的,最后在工程编译时,在工程中加入需要的库,有关命令行加入,glu32 opengl32 glut32库就可以编译了。
注意glut.h文件中已经包含gl.h,glu.h在实际编译中可以只加入头文件glut.h,很多相关的例子都是这样的,但是我在mingwstudio上编译发现,在glut.h前还是需要加入glu.h, gl.h.如:
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
才能成功编译


The OpenGL Extension Wrangler Library (GLEW) is a cross-platform open-source C/C++ extension loading library. GLEW provides efficient run-time mechanisms for determining which OpenGL extensions are supported on the target platform. OpenGL core and extension functionality is exposed in a single header file. GLEW has been tested on a variety of operating systems, including Windows, Linux, Mac OS X, FreeBSD, Irix, and Solaris.


GLX是OpenGL Extension to the X Window System的缩写。它作为x的扩展,是x协议和X server的一部分,已经包含在X server的代码中了。GLX提供了x window system使用的OpenGL接口,允许通过x调用OpenGL库。OpenGL 在使用时,需要与一个实际的窗口系统关联起来。在不同平台上有不同的机制以关联窗口系统,在Windows上是WGL,在Linux上是GLX,在Apple OS上是AGL等。
如果是闭源就不能使用glew了而是使用如下配置文件(放置于/Programs/LLVM/lib/clang/4.0.0/include/GL目录下
<GL/glext.h> - OpenGL 1.2 and above compatibility profile and extension interfaces.
• <GL/glcorearb.h> - OpenGL core profile and ARB extension interfaces, as described in appendix G.2 of the OpenGL 4.3 Specification. Does not include interfaces found only in the compatibility profile.
另外windows自带了gl.h和glu.h(在C盘搜索就行,不然就安装VS2017 Community版再搜索就有了)

常见的OpenGL头文件如下:(Windows系统中可以忽略大小写的区别,我自己也没太注意大小写。同时,文件的路径可能变化,例如不是<GL/gl.h>而是"gl.h",具体情况要看你到底把头文件放到哪了)

<GL/gl.h>:OpenGL所使用的函数和常量声明。

<GL/glu.h>:GLU(OpenGL实用库)所使用的函数和常量声明。GLU库属于OpenGL标准的一部分。(以下各种库则不属于

glu: This is OpenGL utilities library, which has been not updated for long time. Don't need to use this header file.
<GL/glaux.h>:GLAUX(OpenGL辅助库)所使用的函数和常量声明。这个库提供了创建窗口,处理键盘和鼠标事件,设置调色板等OpenGL本身不提供,但在编写OpenGL程序时又经常用到的功能。目前这个库已经过时,只有比较少的编译环境中有提供,例如VC系列。在VC系列编译器中,使用这个头文件之前必须使用#include <windows.h>或者具有类似功能的头文件。

<GL/glut.h>:GLUT(OpenGL实用工具包)所使用的函数和常量声明。这个库的功能大致与GLAUX类似,目前许多OpenGL教程使用这个库来编写演示程序。一些编译系统可能不直接提供这个库(例如VC系列),需要单独下载安装。这个头文件自动包含了<GL/gl.h>和<GL/glu.h>,编程时不必再次包含它们,非开源,GLUT is not open source. Mark Kilgard maintains the copyright

<GL/glext.h>:扩展头文件。因为微软公司对OpenGL的支持不太积极,VC系列编译器虽然有<GL/gl.h>这个头文件,但是里面只有OpenGL 1.1版本中所规定的内容,而没有OpenGL 1.2及其以后版本。对当前的计算机配置而言,几乎都支持OpenGL 1.4版本,更高的则到1.5, 2.0, 2.1,而VC无法直接使用这些功能。为了解决这一问题,就有了<GL/glext.h>头文件。这个头文件提供了高版本OpenGL所需要的各种常数声明以及函数指针声明。

<GL/wglext.h>:扩展头文件。与<GL/glext.h>类似,但这个头文件中只提供适用于Windows系统的各种OpenGL扩展所使用的函数和常量,不适用于其它操作系统。

"glee.h":GLEE开源库的头文件。它的出现是因为<GL/glext.h>虽然可以使用高版本的OpenGL函数,但是使用的形式不太方便。GLEE库则让高版本的OpenGL函数与其它OpenGL函数在使用上同样方便。需要注意的是,这个头文件与<GL/gl.h>是冲突的,在包含"glee.h"之前,不应该包含<GL/gl.h>。
#include <GL/glut.h>
#include "glee.h" // 错误,因为glut.h中含有gl.h,它与glee.h冲突
// 但是如果把两个include顺序交换,则正确
"glos.h":虽然这个也时常见到,但我也不知道它到底是什么,可能是与系统相关的各种功能,也可能只是自己编写的一个文件。我曾经看到一个glos.h头文件中只有一句#include <GL/glut.h>。


glut : 提供对窗口的封装,这是跨平台窗口的,我们就不必自己去编写烦琐的窗口代码。

glee : 方便用来判断当前系统是不是支持某项OpenGL特性,我们就不用自己去写烦琐的先取函数地址然后再判断的代码了。

glew : 因为windows默认只支持OpenGL 1.1,你要想用更高版本的OpenGL,你就需要安装它,它能自动识别你的平台所支持的全部OpenGL高级扩展函数。

OpenGL函数采用了以下格式:
<库前缀><根命令><可选的参数个数><可选的参数类型>
库前缀有gl、glu、aux、glut、wgl、glx、agl等等,分别表示该函数属于OpenGL那个开发库,从函数名后面中还可以看出需要多少个参数以及参数的类型。I代表int型,f代表float型,d代表double型,u代表无符号整型。例如glVertex3fv()表示了该函数属于gl库,参数是三个float型参数指针。我们用glVertex*() 来表示这一类函数。
OpenGL函数库相关的API有核心库(gl)、实用库(glu)、辅助库(aux)、实用工具库(glut)、窗口库(glx、agl、wgl)和扩展函数库等。从图可以看出,gl是核心,glu是对gl的部分封装。glx、agl、wgl 是针对不同窗口系统的函数。glut是为跨平台的OpenGL程序的工具包,比aux功能强大。扩展函数库是硬件厂商为实现硬件更新利用OpenGL的扩展机制开发的函数。

查看opengl版本的工具:opengl extension viewer
http://realtech-vr.com/admin/glview



头文件相当于你告诉别人,我这有个功能你可以按照这个格式调用,具体怎么实现的你不用关心,你用我做好的库就行了。
自己写代码的时候也是这么用。比如,你有一个规模很大的程序,包含了比如统计,日历,文本处理很多不同种类的功能。如果你把所有的函数都写在一个巨大的c文件里也行,但是读起来特别累,也不好调试,这时我们就可以考虑把不同种类的功能放在不同的c文件里,分门别类。那放在不同的文件里的函数如何调用对方呢?这时候我们用头文件做声明,告诉a文件如果包含了b文件的头文件,那么a就能调用b的功能。


#ifndef <标识>#define <标识>
............
#endif

<标识>在理论上来说可以是自由命名的,但每个头文件的这个“标识”都应该是唯一的。标识的命名规则一般(如果需要:大小写都可以,习惯大写,约定俗成用大写,以此与小写的普通变量区分开来.当然如果你故意小写,也是合法的.不过如果你想让你写的程序具有高可读性,那最好遵守此约定是头文件名全大写,前后加下划线,并把文件名中的“.”也变成下划线,如:delay.h
#ifndef _DELAY_H_#define _DELAY_H_
......
#endif
这一个在一般的小型程序中经常用到,在做单片机的的程序时,经常把一些可以独立的模块写成头文件,方便程序的阅读和移植。

我看了老长时间的书,终于明白
为什么是:#ifndef _DELAY_H_#define _DELAY_H_
而不是: #ifndef DELAY.H #define DELAY.H
//////////////////////////
因为,后者,定义一个名称,是用于一个程序中或者头文件中的,名称定义
前者,是关于头文件包含的,不是名称定义的。用下划线代替“.”,是没有办法的办法,只有这样才能防止混乱。
前者的意思是,如果没有包含了这个头文件,就包含它。
后者的意思是,如果没有定义这个名称,就定义它。

其实就是换一种写法 以区分两种意思。
两者是不一样的意思。

#error命令是C/C++语言的预处理命令之一,当预处理器预处理到#error命令时将停止编译并输出用户自定义的错误消息。
#if vs. if(#if用于预处理命令常与#define,#else等连用,而if用于逻辑判断,如if(x>1){};
条件编译是C语言中预处理部分的内容,它是编译器编译代码时最先处理的部分,
条件编译里面有判断语句,比如 #if 、#else 、#elif 及 #endif
它的意思是如果宏条件符合,编译器就编译这段代码,否则,编译器就忽略这段代码而不编译,如
#define A 0 //把A定义为0

#if (A > 1)

printf("A > 1"); //编译器没有编译该语句,该语句不生成汇编代码

#elif (A == 1)

printf("A == 1"); //编译器没有编译该语句,该语句不生成汇编代码

#else

printf("A < 1"); //编译器编译了这段代码,且生成了汇编代码,执行该语句

#endif

而 if 语句则不然,if 是 C 语言中的关键字,它根据表达式的计算结果来觉定执行那个语句,它里面的每个分支都编译了的, 如
#define A 0

if (A > 1)

printf("A > 1"); //编译器编译该语句,但因为A == 0 未执行

else if(A == 1)

printf("A == 1"); //编译器编译该语句,但因为A == 0 未执行

else

printf("A < 1"); //编译器编译该语句,因为A == 0 故执行

作为一个编译“开关”,比如:
#if(条件满足)
执行代码1
#else
执行代码2
#endif
假如编译时,确实满足条件,则生成的程序文件(.exe文件)中不会有执行代码2的。如果用普通if语句,生成的程序文件就会有执行代码2,这个区别看看生成文件大小就可以知道。如果你的条件在程序编译前就已经确定了,那就用#if;如果条件需要在程序运行过程中才能判断,则用if。
所以 简单地讲,条件编译是根据 宏条件 选择性地编译语句,它是编译器在编译代码时完成的;
条件语句是根据条件表达式选择性地执行语句,它是在程序运行时进行的。
#if的使用说明
#if的后面接的是表达式
#if (MAX==10)||(MAX==20)
code...
#endif
它的作用是:如果(MAX==10)||(MAX==20)成立,那么编译器就会把其中的#if 与 #endif之间的代码编译进去(注意:是编译进去,不是执行!!)
#if defined的使用
#if后面接的是一个宏。
#if defined (x)
...code...
#endif

这个#if defined它不管里面的“x”的逻辑是“真”还是“假”它只管这个程序的前面的宏定义里面有没有定义“x”这个宏,如果定义了x这个宏,那么,编译器会编译中间的…code…否则不直接忽视中间的…code…代码。
另外 #if defined(x)也可以取反,也就用 #if !defined(x)
#ifdef的使用
#ifdef的使用和#if defined()的用法一致
#ifndef又和#if !defined()的用法一致。
最后强调两点:
第一:这几个宏定义只是决定代码块是否被编译!
第二:别忘了#endif


#ifdef MY_PRINTF_STANDARD=#if defined(MY_PRINTF_STANDARD)


#else指令用于某个#if指令之后,当前面的#if指令的条件不为真时,就编译#else后面的代码。#endif指令将终止上面的条件块。#elif预处理指令综合了#else和#if指令的作用。

中文名
#elif
使用
用于某个#if指令之后
#elif
使您得以创建复合条件指令
预处理指令
综合了#else和#if指令的作用。
#elif 使您得以创建复合条件指令。如果前面的 #if 和前面的任何 #elif(可选)指令表达式的计算结果都不是 true,则将计算 #elif 表达式。如果 #elif 表达式计算为 true,编译器将计算位于 #elif 和下一个条件指令之间的所有代码。例如:

#defineVC7//...
#ifdebug
Console.Writeline("Debugbuild");
#elifVC7
Console.Writeline("VisualStudio7");
#endif

可以使用运算符 ==(相等)、!=(不相等)、&&(与)及 ||(或)来计算多个符号。还可以用括号将符号和运算符分组
#elif 等效于使用:
#else
#if
使用 #elif 更简单,因为每个 #if 都需要一个 #endif,而 #elif 即使在没有匹配的 #endif 时也可以使用。
有关如何使用 #elif 的示例,请参见 #if。

Microsoft Windows要求在gl.h或glu.h之前包含windows.h头文件,因为MicrosoftWindows版本的gl.h和glu.h文件内部使用的一些宏是在windows.h中定义的。


简单办法,先写完整程序,再把一部分抽出去,抽出去的存到 自己的头文件里,在抽出的地方写 #include ...

例如,完整程序(计算平均值):
#include<stdio.h>

double mean(double *y, int N){
int i;
double s=0.0;
for (i=0;i<N;i++) s=s+y;
s = s / (double) N;
return s;
}
void main()
{
double x[10]={1,2,3,4,5,6,7,8,9,10};
printf("mean = %lf\n", mean(x,10));
}
----------------------------------------------
抽出部分 存入 a_x.h :
double mean(double *y, int N){
int i;
double s=0.0;
for (i=0;i<N;i++) s=s+y;
s = s / (double) N;
return s;
}
--------------------------------
程序变:
#include<stdio.h>
#include "a_x.h"
void main()
{
double x[10]={1,2,3,4,5,6,7,8,9,10};
printf("mean = %lf\n", mean(x,10));
}
=============================================
你要是愿意随便抽一块也可以,例如抽出(也叫 a_x.h):
double mean(double *y, int N){
int i;
double s=0.0;
for (i=0;i<N;i++) s=s+y;
s = s / (double) N;
return s;
}
void main()
{
------------------------
程序变:
#include<stdio.h>
#include "a_x.h"
double x[10]={1,2,3,4,5,6,7,8,9,10};
printf("mean = %lf\n", mean(x,10));
}
==============================
语法上,功能上,两种抽法都可以。但第一种方法较好--程序可读性好,不易出错。

一般情况下,头文件里放 函数原型,全局量声明 和 函数定义。



一般用于将C++代码以标准C形式输出(即以C的形式被调用),这是因为C++虽然常被认为是C的超集,但是C++的编译器还是与C的编译器不同的。C中调用C++中的代码这样定义会是安全的。
一般的考虑跨平台使用方法如下:
#ifdefined(__cplusplus)||defined(c_plusplus) //跨平台定义方法
extern "C"{
#endif
//... 正常的声明段
#ifdefined(__cplusplus)||defined(c_plusplus)
}
#endif

简单的用在windows下可以如下定义:
#ifdef __cplusplus
extern "C"{
//... 正常的声明段
}
#endif


a>b ? printf("a比b大!\n") : printf("b比a大!\n");
相当于:

[plain] view plaincopy
if(a>b)
{
printf("a比b大!\n");
}
else
{
printf("a不比b大!\n");
}


C语言有一种数据类型叫结构体,其定义格式为:

struct 结构体名 {
结构体成员变量定义;
};


有几种访问结构体的方法:
访问结构成员的运算符有两种,一种是结构成员运算符“·”,也称为“圆点运算符”,另一种是结构指针运算符“->”,也称“箭头运算符”。
结构成员运算符通过结构变量名访问结构体的成员。例如:
printf("%s",student.name);
结构指针运算符由减号“-”和“>”组成(中间没有空格),它通过指向结构的指针访问结构的成员。假定声明了指向struct student的指针sPtr,并且把结构student1的地址赋给了sPtr,如下列语句通过指针sPtr打印了结构student1的成员name:
printf("%s",sPtr->name);
不要在结构指针运算符的-和>之间插入空格。
在用指针(->)和结构成员运算符(.)引用结构成员时一定要用圆括号(*sPtr).name,因为结构成员运算符“.”比指针复引用运算符“*”的优先级高,所以圆括号是必须的。
下面的程序演示了结构成员和结构指针运算符的用法:
#include<stdio.h>
struct student
{char *name;
char *sex;
int age;
};
main()
{
char i;
struct student student1;
struct student *sPtr;
student1.name="Tom";
student1.sex="male";
student1.age=18;
sPtr=&student1;
printf("%s%s%s\n%s%s%s\n%s%s%s\n",
student1.name,"'s sex is",student1.sex,
sPtr->name,"'s sex is",sPtr->sex,
(*sPtr).name,"'s sex is",(*sPtr).sex);

i = student1.age;
printf("\n\n\ni=%d||student1.age=%d||(*sPtr).age=%d",i,student1.age,(*sPtr).age);


return 0;
}

1、%lf 双精度浮点型,也就是double型的格式,默认保留6位小数。
如:double a = 1.2; printf("%lf",a); //1.200000。
2、%.2lf 同上,不过限制了,值保留2位小数。
如:double a = 1.2345; printf("%.2lf",a); //1.23。
3、%.2f 表示单精度浮点型,也就是float型的格式。
如:float a = 1.2731; printf("%.2f",a); //1.27。


下面的例子:
int main() {
func();
}
void func() {...}
会报错
,如果把func放在main()函数前,在main()调用它之前先定义,那么就ok,why? 因为编译器发现一个不认识的函数调用,不知道该函数的返回类型,就假设为int类型,等后面编译的时候编译器看到实际的函数,它认为有两个同名的函数,一个是文件中的函数,一个是编译器假设返回int的那个
如何去避免呢:有没有办法让编译器一开始就知道函数的返回值类型呢?为了防止编译器假设函数的返回类型,你可以显式地告诉它。告诉编译器函数会返回什么类型的语句就叫函数声明。

1.声明与定义分离

float func(int age);


函数声明包括:函数名,返回值类型,形参类型,以;结束,没有函数体.
一旦声明了函数,编译器就不需要假设,完全可以先调用函数,再定义函数。
对于上面的问题,可以这样写:
int main(int argc, char *argv[]) {
void func(); //声明
func();
return 0;
}

void func(){
printf("come on baby!");
}
如果有多个这样的玩意,我们就需要在main函数中一次次的声明,比较好的方式是可以放在头文件

2.头文件
创建头文件,func.h, 将函数声明写在此:
#ifndef intoC_func_h
#define intoC_func_h

void func();

#endif
然后上面程序就可以在main函数中不用再函数声明(不是定义!!!,只是不用声明了但是仍需定义!了.


Create C Program with Dynamic Link Library (DLL) using Visual Studio 2012 (Implicit Link)

The following procedure is to create a C program with a dynamic link library using Microsoft Visual Studio Express 2012.

Brief Introduction to Dynamic Link Library (DLL)
The important difference between DLL and static library is that the code of external function is stored in the DLL file, whereas when linking with static library, the code of the external functions is copied to the execution file of the application program. With static library, you just need an execution file whereas with DLL you need both the execution file and the DLL file for the program to work.

Implicit or Explicit Link
When creating DLL, we have the choice of implicit linking or explicit linking. Since implicit linking is easier and common, this article will focus on implicit linking. For additional information please refer to the following:

Linking Implicitly
Linking Explicitly
Determining Which Linking Method to Use

Examples:
The following example is a normal C program with functions without using any custom static library.

#include <stdio.h>
#define PI 3.1415

double PowerOf2 (double UserNumber);
double PowerOf3 (double UserNumber);
double CircleArea (double UserRadius);
double CircleCircum (double UserRadius);

int main ( )
{

double p2 = 10.0;
double p3 = 5.0;
double radius = 4.0;

printf ("The number %.2f to the power of 2 is %.2f. \n", p2, PowerOf2(p2));

printf ("The number %.2f to the power of 3 is %.2f. \n", p3, PowerOf3(p3));

printf ("A circle with a radius of %.2f, the area is %.2f. \n", radius, CircleArea(radius));

printf ("A circle with a radius of %.2f, the circumference is %.2f. \n", radius, CircleCircum(radius));

return 0;

}

double PowerOf2 (double UserNumber)
{
return UserNumber * UserNumber;
}


double PowerOf3 (double UserNumber)
{
return UserNumber * UserNumber * UserNumber;
}

double CircleArea (double UserRadius)
{
return UserRadius * UserRadius * PI;
}

double CircleCircum (double UserRadius)
{
return 2 * UserRadius * PI;
}

We will use the above example to create a dynamic link library and an application program that use this library. We will place the DLL in a shared public folder and place the application in the personal document folder.

To create a dynamic link library, it consist of 2 files MyMathDll.h and MyMathDll.c

To create Dynamic Link Library
Step 1: Create a new project as dynamic link library
Create a new project using MyMathDll as project name

dll (1).png


Click "OK". Then click "Next". On following screen you need to specify that you are creating a DLL and make sure you check Empty project.
dll (2).png


Step 2: Create the headers file
Under Solution Explorer, right click Headers Files >> Add >> New Item as shown below.

dll (3).png

Select header file as file type and rename the header file to MyMathDll.h
dll (4).png


Click "Add".

Add the following to the headers:

#ifdef MYMATHDLL_EXPORTS
#define MYMATHDLL_API __declspec(dllexport)
#else
#define MYMATHDLL_API __declspec(dllimport)
#endif

#define PI 3.1415

MYMATHDLL_API double PowerOf2 (double UserNumber);
MYMATHDLL_API double PowerOf3 (double UserNumber);
MYMATHDLL_API double CircleArea (double UserRadius);
MYMATHDLL_API double CircleCircum (double UserRadius);

The dllexport and dllimport attributes are extensions to the C and C++. You can use them to export and import functions to or from a DLL. When the MYMATHDLL_EXPORTS symbol is defined, the MYMATHDLL_API symbol will set the __declspec(dllexport) modifier in the member function declarations. This enables the function to be exported by the DLL so that it can be used by other applications. When MYMATHDLL_EXPORTS is undefined, MYMATHDLL_API defines the __declspec(dllimport) modifier in the member function declarations. This enables the compiler to optimize the importing of the function from the DLL for use in other applications. By default, MYMATHDLL_EXPORTS is defined when the MyMathDll project is built.

You can also define the header file this way.

#define PI 3.1415

__declspec(dllexport) double PowerOf2 (double UserNumber);
__declspec(dllexport) PowerOf3 (double UserNumber);
__declspec(dllexport) CircleArea (double UserRadius);
__declspec(dllexport) double CircleCircum (double UserRadius);

For further information on dllexport and dllimport please refer to this article.

Step 3: Create the Implementation Program
Under Solution Explorer, right click Source Files >> Add >> New Item. Rename the program to MyMathDll.c.

dll (5).png


Enter the source code as follows

#include "MyMathDll.h"

double PowerOf2 (double UserNumber)
{
return UserNumber * UserNumber;
}

double PowerOf3 (double UserNumber)
{
return UserNumber * UserNumber * UserNumber;
}

double CircleArea (double UserRadius)
{
return UserRadius * UserRadius * PI;
}

double CircleCircum (double UserRadius)
{
return 2 * UserRadius * PI;
}

Step 4: Build solutions
Build solutions. You should have result as follows:
dll (6).png

Once the compilation is complete, close the project.


Create a C Application Program Using DLL
Step 1: Create a new project
Create a new project using the name MyApp3 with Console Application as options. Remember to clear all headers and checked Empty Project.

Step 2: Establish Link with the Static Library
Under Solution Explorer, right click and select Add >> Existing Projects
dll (7).png

Navigate to the project folders of MyMathDll and select the project file MyMathDll.vcxproj and click Open.

Your solution explorer should show two projects like below:
dll (8).png
dll (8).png (10.59 KiB) 查看 16573 次

Select MyApp3, right click and select properties. Under Common Properties, select Framework and References. Click "Add New Reference"
dll (9).png

You should see the following screen, there should be a project named "MyMathDll". Check the project as shown below and click "OK".
dll (10).png

On the properties page, under Configuration Properties >> C/C++ expand the list in C/C++ and select "General" as shown below.
dll (11).png

For first line "Additional Include Directories", click the arrow and select edit. The following dialog box shows:

dll (12).png
Click the "New Line" icon and click on the button "...". Now you need to navigate to the DLL folder. Do not select the folder "MyMathDll" under Projects, drill one level down and select the folder "MyMathDll". The purpose is to the select the folder that contain the header file. Highlight the folder and click Select Folder.
dll (13).png

Click OK. Then click Apply. You can close the property dialog box.

Step 3: Create the application program
Under Solution Explorer, right click Source Files >> Add >> New Item. Rename the program to MyApp3.c.

Enter the following program:

#include <stdio.h>
#include "MyMathDll.h"

int main ( )
{

double p2 = 10.0;
double p3 = 5.0;
double radius = 4.0;

printf ("The number %.2f to the power of 2 is %.2f. \n", p2, PowerOf2(p2));

printf ("The number %.2f to the power of 3 is %.2f. \n", p3, PowerOf3(p3));

printf ("A circle with a radius of %.2f, the area is %.2f. \n", radius, CircleArea(radius));

printf ("A circle with a radius of %.2f, the circumference is %.2f. \n", radius, CircleCircum(radius));

return 0;

}

Step 4: Build the solution.
After you have built the solutions, you should received a message similar to the one below. Please note that two projects are being built.

dll (14).png
Step 5: Run the program
You can test the project from the command prompt as shown below:

dll (15).png

Additional Note:
Please note that for the successful execution of the program. MyApp3.exe and MyMathDll.dll should be in the same folder. Alternatively, the MyMathDll.dll should be located where the Windows system could find. The search path the DLL files for Windows are as follows:

The directory where the exe file is located.
The Windows system directory.
The Windows directory.
The directories listed in the PATH environment variable.


This completes the procedure for creating a DLL in C using Visual Studio Express 2012. Please note that the procedure for creating similar DLL using command line is different from using the IDE.



#pragma once是一个比较常用的C/C++杂注,只要在头文件的最开始加入这条杂注,就能够保证头文件只被编译一次。
如果编译失败那么把所有cpp文件改成c后缀的文件
changto c.png
243750496
帖子: 1038
注册时间: 2012-06-09 15:40

Re: Ubuntu&Fedora装机&Mac装机(Mac装机将会持续更新)

#427

帖子 243750496 » 2018-04-08 0:09

Code Block OpenGL开发设置(Glew Glfw)
I was having similar problems earlier with importing GLFW into codeblocks, and I recently found something that works for me.
I can see that you have already done the header installation correctly, but I will include that in this response so that you can double-check that everything is in tip-top condition.
I also recommend that you use the sample code within the 'Documentation' tab of glfw.org. It works really well for me, so I think it might for you as well.
Since you are using GLFW, I will assume that you want to use OpenGL in your application, so I will include the installation of OpenGL in the tutorial

A. Creating relevant folders
The first thing you will need to do is set up a location for library files and header files on your system. You can either creates these folders within a specified location on your drive, or you can create these folders within your code::blocks project.
In my case, I created a 'lib' and 'head' folder in my code::blocks project folder.

B. Downloading & Installing necessary media
GLFW:
Head over to GLFW.org, and hit 'Downloads'.
Click '32-bit Windows binaries', and open the 'glfw-version.bin.WIN32' within zip file that was downloaded.
Open the 'include' folder and copy the enclosed GLFW folder to the 'head' folder you created in part A.
Open up 'glfw-version.bin.WIN32' again, and pick the 'lib' folder that corresponds to your compiler. Because I am using the MinGW GCC compiler, I picked 'lib-mingw'. To find your compiler, go to code::blocks, click settings, and then click 'compiler...'. Your compiler is found in the 'selected compiler' section of the window that appears.
Once you've found the 'lib' folder that you will use, open it, and copy all of the files within into the 'lib' folder that you created during part A.
GLEW (OpenGL):
Go to this link
Open the folder that is within the downloaded zip.
Go to 'lib', then release, then Win32, and copy all of the files located there into the 'lib' folder you created in step A.
Go back to the folder within the downloaded zip.
Enter the 'include' directory, and copy the 'GL' folder into the 'head' folder created in part a.
At this point, your 'head' folder should contain 'GLFW' and 'GL' folders, and your 'lib' folder should contain 'glew32', 'glew32s', and all of the library files from GLFW for your compiler.

C. Configuring your code::blocks project
Once you've opened your project, right click on the name of your project in your workspace, and hit 'build options...
On the left of the window that has appeared, make sure 'Debug' is selected.
Next click the 'linker settings' tab, and add the following libraries: 'glfw.3', 'gdi32', and 'opengl32'.
Next, in the 'Search Directories' tab, select the 'Compiler' tab.
Add the path to your 'head' folder. If the head folder was created within your project folder, you can just type 'head'
Also in the 'Search Directories' tab, select the 'Linker' tab.
Add the path to your 'lib' folder. Again, if the lib folder was created withing your project folder, you can just type 'lib'.
Hit 'OK' at the bottom of the window.

D. Build and Run your code :)! Hope this helps!

注意以下几点:
1、Build Options在Project下
2、GUN GCC在Settings->Compiler->Cygwin GCC的滚动条上方
3、先改为GUN GCC然后再改Toolchain executables->Compiler's installation directory为C:\Program Files (x86)\CodeBlocks\MinGW\bin
4、使用GUN GCC编译,如果使用LLVM Clang则会爆出LINK : fatal error LNK1181: cannot open input file 'glfw3.lib'(解决办法见cmake)

报错解决办法:
main.o: file not recognized: File format not recognized codeblocks
删除obj->DEBUG目录下的main.o文件

winapifamily.h : No such file or directory
build options -> search directories -> compiler添加如下路径:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\shared

glfw官方测试代码:
#include <GLFW/glfw3.h>

int main(void)
{
GLFWwindow* window;

/* Initialize the library */
if (!glfwInit())
return -1;

/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}

/* Make the window's context current */
glfwMakeContextCurrent(window);

/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);

/* Swap front and back buffers */
glfwSwapBuffers(window);

/* Poll for and process events */
glfwPollEvents();
}

glfwTerminate();
return 0;
}

如果用CodeBlocks创建DLL的话前面Visual Stuido一样然后再参考配置dll和lib(把这两个文件用VS编译后拷贝并配置好)
最后也就是最重要的一步就是Build Options->Linker Settings->添加MyMathDll(没有lib后缀)然后就可以了


cmake是一个构建C++代码的跨平台工具,他能够干什么呢?他能够搜索你的平台环境,然后生成平台上用于Build的文件。在Windows上安装了Visual Studio, 他能够帮你生成.sln然后在VS中Build Project), .vcxproj文件。如果在Linux上,能够帮你生成makefile。在MAC OS上,帮你生成xcode的项目文件。利用这些文件你就可以在本地编译,链接文件。生成这些项目,solution文件的输入信息,就是一套自己编写的和平台无关的配置文件。一般使用CMakeLists.txt文件。


使用GUN GCC编译,如果使用LLVM Clang则会爆出LINK : fatal error LNK1181: cannot open input file 'glfw3.lib'
解决办法:下载Cmake然后使用cmake-gui生成VS 工程文件并在VS中编译

如果不小心设置为X86编译器则需删除掉原glfw文件夹然后重新解压载入就行了
记得勾选上BUIDL_SHARED_LIBS(否则clang将无法使用)
Build_Shared_Libs.png
然后把生成的libs和dll文件拷贝载入并链接上(注意是glfw3dll,不是glfw3!)

如果使用CodeBlocks生成lib文件只需要在Project->Properties->Build Targets中去掉勾选:Auto-generate filename prefix 和 Auto-generate filename extension
lib extension.png

#include <iostream>

// GLEW
#define GLEW_STATIC
#include <GL/glew.h>

// GLFW
#include <GLFW/glfw3.h>


// Window dimensions
const GLuint WIDTH = 800, HEIGHT = 600;

// The MAIN function, from here we start the application and run the game loop
int main()
{
std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl;
// Init GLFW
glfwInit();
// Set all the required options for GLFW
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

// Create a GLFWwindow object that we can use for GLFW's functions
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", nullptr, nullptr);
if (window == nullptr)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
// Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions
glewExperimental = GL_TRUE;
// Initialize GLEW to setup the OpenGL Function pointers
if (glewInit() != GLEW_OK)
{
std::cout << "Failed to initialize GLEW" << std::endl;
return -1;
}

// Define the viewport dimensions
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);

// Game loop
while (!glfwWindowShouldClose(window))
{
// Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions
glfwPollEvents();
// Swap the screen buffers
glfwSwapBuffers(window);
}

// Terminate GLFW, clearing any resources allocated by GLFW.
glfwTerminate();
return 0;
}
再次提醒使用glfw3dll.lib库做链接的的时候输入的是glfw3dll,不是glfw3!)

只用到glew和glfw库的opengl测试源代码:
#include <GL/glew.h>
#include <GLFW/glfw3.h>

int main(int argc, char *argv[])
{
glfwInit();
GLFWwindow* window = glfwCreateWindow(640, 480, "Sample code does not display two triangles", NULL, NULL);
glfwMakeContextCurrent(window);

glewInit();

GLfloat vertices[] =
{
+0.0f, +0.0f, //0
+1.0f, +1.0f, //1
-1.0f, +1.0f, //2
-1.0f, -1.0f, //3
+1.0f, -1.0f, //4
};

GLuint vertexBufferID;
glGenBuffers(1, &vertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 2, GL_FLOAT, 0, 0 );

GLuint indexBufferID;
GLushort indices[] = { 0,1,2, 0,3,4 };
glGenBuffers(1, &indexBufferID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

while (!glfwWindowShouldClose(window))
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
glfwSwapBuffers(window);
glfwPollEvents();
}

glfwTerminate();
return 0;
}
243750496
帖子: 1038
注册时间: 2012-06-09 15:40

Re: Ubuntu&Fedora装机&Mac装机(Mac装机将会持续更新)

#428

帖子 243750496 » 2018-04-10 22:08

config.h

/*
Copyright 2012 Jun Wako <wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in