|
|
9/26/2007 从为找工作学 Java 直到现在,我都一直用 NetBeans 进行 Java 开发。NetBeans C/C++ 开发包出现后,我把用了多年还是一知半解的 Microsoft Visual C++ 也抛弃了。我从来没用过 Eclipse,因为我相信 NetBeans 足够好,迟早会超过它(可能现在已经超过了)。 为了和更多朋友一起学习、分享、探讨、进步,我趁公司午休的时间新开了这个“网豆”类别,主要写关于 NetBeans 的文章,也会包括一些其他的开发话题,例如 OpenGL、Qt 等等。 我一会儿把网址发送给 NetBeans 星球,希望不久后安装 NetBeans 中文版并且能上网的朋友都可以在“欢迎”窗口中看到我的文章。
NetBeans Special Topic Open Sine my learning Java for finding a job, I keep using NetBeans for Java development. And since the appearence of NetBEans C/C++ Development Pack, I threw away Microsoft Visual C++ which I had used for so many years used but still half-knew. I never tried Eclipse, because I believe NetBeans is good enough and will exceed it sooner or later (perhaps already exceeded it). For the sake of learning, sharing, discussing and progressing with more friends, I create this new "NetBeans" catalog in our company's noon break. Articles in it will mainly concentrate on NetBeans, and also some other development topics, such as OpenGL, Qt, etc. Later, I'll send the URL to PlanetNetBeans, with a hope that every friend that installs NetBeans CHS edition could read my articles in the "Welcome" window. 9/24/2007 目前的 NetBeans IDE 5.5.1 开发和管理 Qt 项目不太方便也就罢了,最头痛的是 MSYS 里面的 UNIX 风格的 make 不适用于 Qt,经常因为不能识别“\”而报错。可是 NetBeans 偏爱 UNIX 风格,不安装 MSYS 就不能在 Makefile 里面用 cp 等等(Windows 的 copy 是不能用的)。今天折腾了好一阵,总算找到了一个比较折中的办法,连同创建 Qt 项目的步骤一并如下。 - 下载 GNU Make(mingw32-make),解压缩到 MinGW 目录下,也可以用昨天提到的 自动 MinGW 安装程序。
- 编辑源代码并用 qmake 生成 Makefile。
- 新建“基于现有代码的 C/C++ 项目”,这是为了避免修改 NetBeans 生成的“重要文件”和杂乱的项目结构。
- 第二步中,把“使用现有的 makefile”设为“Makefile.Release”。如果想用其他两个 Makefile 的话就必须先从源代码生成 Qt 的调试库(开始→所有程序→Qt by Trolltech v4.x.y (OpenSource)→Qt 4.3.1 (Build Debug Libraries)),下载安装的文件不包括这些库,我是懒得弄了。
- 第三步中,把“生成命令”和“清理命令”里面的“make”替换为“mingw32-make”。如果不打算手工编辑 qmake 生成的 PRO 文件和 Makefile,还可以在前面加上生成这些文件的命令。例如:qmake -project; qmake -makefile; mingw32-make -f Makefile.Release。
- 按向导完成“新建项目”,现在已经可以在项目中使用 IDE 的“生成项目”等命令了。
NetBeans C/C++ 开发包还不成熟,无法完全管理 Qt 项目,常常要结合命令提示符的 qmake 来使用。另外就是编辑代码不方便,不仅要预先写好代码,而且没有代码完成(我没弄出来)。 顺便提一下分发的问题,用 Dependency Walker 查找出 Qt 程序要调用的 Qt 库,一起分发这些库就可以了。一般会有 kernel32.dll、msvcrt.dll、QtCore4.dll 以及 QtGui4.dll,前两个是 Windows 标准库可以不管,其他的就必须随程序一起分发。 Creating Qt Projects in NetBeans I wouldn't mind the inconvenience using current NetBeans 5.5.1 to develop and manage Qt projects, but the biggest headache is the UNIX styled make in MSYS doesn't apply to Qt, and it often reports errors for unrecognized "\". However, NetBeans prefers UNIX styles, so without MSYS installation cp and so on can't be used in Makefiles (Windows' copy doesn't work). I tried over and over again and found a compromise way. Here are the steps together with how to create a Qt project. - Download GNU Make (mingw32-make) and unpack it to MinGW directory, or you can used Automated MinGW Installer mentioned yesterday.
- Edit source code and generate Makefiles with qmake.
- Create a new "C/C++ Project From Existing Source", in order to avoid modifying "Important Files" generated by NetBeans and messy project structure.
- In Step 2, set "Using A Existing Makefile" to "Makefile.Release". If you want to use two other Makefiles, you must first build Qt's debug library, which is not included in the downloaded installer, from source (Start→All Programs→Qt by Trolltech v4.x.y (OpenSource)→Qt 4.3.1 (Build Debug Libraries)), but I don't feel like doing so.
- In Step 3, replace "make" in "Build Command" and "Clean Command" with "mingw32-make". If there's no plan to manually edit qmake generated PRO file and Makefiles, you can add commands that generate these files at the beginning (qmake -project; qmake -makefile; mingw32-make -f Makefile.Release). For instance: qmake -project; qmake -makefile; mingw32-make -f Makefile.Release.
- Follow the wizard to complete creating "New Project", and now IDE's "Build Project" command can be used in the project.
NetBeans C/C++ Development Pack is not yet mature and can't manage Qt overall, so it's usual working with qmake from command line. In addition, it's inconvenient to edit source code, that code must be prewritten and there is no code completion (I haven't dug it out). By the way, a few words about distribution. Use Dependency Walker to find out Qt libraries invoked by Qt applications and distribute these libraries together. Usually there are kernel32.dll, msvcrt.dll, QtCore4.dll and QtGui4.dll, the first two of them are Windows standard libraries and can be ignored, while others must be distributed along with applications. 9/23/2007 前面的文章《搭建基于 NetBeans 的 OpenGL 开发环境》提到了 NetBeans 和 MinGW 的配置,当时记得好像以前写过步骤,就随手略过了。今天收到网友的提醒才发现是我记错了,在这里补上,同时谢谢你! 步骤如下: - 下载自动 MinGW 安装程序,这对初学者来说是比较方便的方式,缺点就是下载速度慢得不如蜗牛。
- 运行下载的 MinGW-x.y.z.exe,一直点“Next”,接着选择“Current”,直到出现组件选择。
- 至少要选择“MinGW base tools”和“g++ compiler”。其他组件还不受 NetBeans 支持。
- 然后就是下载、安装,运气不好的话用的时间都可以看一部电影了。
- 下载 GNU 源级别调试器(也就是 GDB),安装到 MinGW 目录下。
- 下载并安装 MSYS:最小系统,安装后有些简单的配置向导。
- 安装 NetBeans 5.5.1 和 NetBeans 5.5.1 C/C++ 开发包。
现在已经能正常编译和运行标准的 C/C++ 程序了。只要对 Makefile、GCC 这些工具有所了解,NetBeans 足以应付大多数开发,虽然有时还是不太方便。目前 NetBeans 6.0 Beta 出来了,不知道 C/C++ 开发组件有什么改进。 Configuring Development Environment of NetBeans + MinGW My former article "Building OpenGL Development Environment Based on NetBeans" noticed the configeration of NetBeans and MinGW, and at that time I just skipped it since I remembered the steps had been written before. Today I received a notice from a net friend and realized my memery was wrong, so I supply the missing and meanwhile thank you! Below are the steps: - Download Automated MinGW Installer, which is a good method to primers, and the shortcoming is the downloading speed is slower than a snail.
- Run the downloaded MinGW-x.y.z.exe, click "Next" straight forward, select "Current", until the components selection.
- Choose at least "MinGW base tools" and "g++ compiler". The other components are not supported by NetBeans yet.
- Then is download and installation, and if you're unluck, the consumed time is enough for watching a film.
- Download GNU Source-Level Debugger (aka GDB), and install it to MinGW directory.
- Download and install MSYS: Minimal System, and after that there is a simple configuration wizard.
- Install NetBeans 5.5.1 and NetBeans 5.5.1 C/C++ development pack.
Now standard C/C++ applications can be compiled and run correctly. If you have a basic knowledge of these tools like Mafile and GCC, NetBeans can handle most developments, though not very convenient sometimes. NetBeans 6.0 Beta has been out, but I don't know the improvements of C/C++ development components. 真是的,等了三年才终于推出 4.0 正式版。从安装的程序来看,已经有某人翻译了简体中文,但管理员 Flo 说已经很久失去联系了,所以就由我来接手工作。我已经全部重新翻译并上传到官方网站,并且在我的鼓动下,Flo 让我把网页也翻译了(Flo 好像还搞不清楚简体中文和繁体中文的区别,开始还觉得只要“一种中文”就够了)。后面的工作就是翻译帮助文档和更新网页翻译了。 下载地址:http://www.cdburnerxp.se/download(还没有包含我的翻译)。 CD Burner XP 4.0 Official Simplified Chinese Edition Well, after three years' waiting, the final reelease of version 4.0 comes at last. From the installed program, it can be seen somebody has done a CHS translation, but Flo, the administrator, said it was so long since his last contact, so I took over the furthur jobs. I've finished the translation from the scratch and submitted it to the official Web site, and under my promotion, Flo let me translate the Web pages (Seems Flo is so confusing about the differences between CHS and CHT that he felt "a single Chinese" is enough at the beginning). The further jobs are translating help documentations and updating the translation of Web pages. Download address: http://www.cdburnerxp.se/download (Not includes my translation yet). 9/22/2007 老板要我做嵌入式系统的操作界面。我问同事,了解到操作系统是嵌入式 Linux,要用 C++ 语言配合一个叫 Qt 的开发工具来做(生活总是带有讽刺)。 接着就上网踩 Qt 的当家奇趣科技的地盘。Qt 本来也有 Java 版本 Qt Jambi,不过据说使用的 Linux 没有安装 Java(至少不确定),用不了。然后了解到 Qt 也是像 Java 一样跨平台的,在 PC 和嵌入式开发里面都用得比较多,有点兴趣了,就下载来用,感觉还真是不错,至少不像微软那样炮制一大堆稀奇古怪宏。 Qt 分商业版和开源版两种,我当然用后者。Windows 版本的 Qt 有个问题,就是如果生成的 Makefile(共三个)里面有用到 moc.exe 的地方,要手动把反斜杠“\”改成正斜杠“/”,否则就会出现一堆编译错误,目前还没找到更好的解决方法(就因为这个搞得都不好用 NetBeans 来管理 Qt 项目)。 Qt The boss wanted me to make a operation GUI in a embedded system. I aksed my colleague and was told that the operation system is embedded Linux, and must be programmed in C++ language together with a development tool called Qt (Life is always of irony). Then I pay a visition to Trolltech, the owner of Qt. Qt actually has a Java version Qt Jambi, but it's said the Linux we are using has no Java installed (at least not surely), so I can't use it. Then I get to know Qt is cross-platform like Java, and is widely used in PC and embedded development. I'm interested, downloaded and had a taste. It's really good, at least not like Microsoft who cooks up a pile of most strange macros. Qt is divided into two editions, the commercial one and the open source one, and of course I take the latter. There is a problem using Qt's Windows edition, that is, if the generated Makefiles (3 in total) have the usage of moc.exe, the counter slash "\" must be manually changed to slash "/", otherwise there will be many compiling errors, and I haven't yet found a good solution (Because of this NetBeans is not handy to manage Qt projects). 9/11/2007 NetBeans 6.0 有一个 OpenGL 开发包,但那是基于 OpenGL 的 Java 包装 JOGL 的,况且 NetBeans 6.0 要到年底才发布正式版,目前的开发版都不太稳定。我这里说的是搭建 Windows 本地的 OpenGL 开发环境。按照以下步骤: - 下载必备的工具:NetBeans IDE 5.5.1、NetBeans C/C++ 开发包、MinGW、GLUT。前三个安装,GLUT 解压缩到一个目录下。
- 配置 NetBeans C/C++ 开发包和 MinGW,在我前面的文章中有,不重复了。
- 把 GLUT 目录加入到系统的环境变量中,确保 glut32.dll 可见。
- 把 glut.h 复制到 MinGW 安装目录下的 include\GL 中。
这样环境就算搭建好了。在编译的时候还有点注意事项。在 C/C++ 项目的属性里面,把 glut32.lib 文件加入到库中(用绝对路径),并设置库选项 -lopengl32 和 -lglu32。glut32.dll 不是标准 Windows 库,所以不能用 -lglut32。现在已经可以顺利生成项目了。在分发的时候,最好复制一份开发时用的 glut32.dll 到生成的程序所在的目录中,以防用户没有安装 glut32.dll 或版本冲突。 There is an OpenGL development pack for NetBeans 6.0, but that is based on JOGL, the Java wrapper of OpenGL, and, besides, the final version of NetBeans 6.0 is scheduled to be released in the end of this year, and the current development versions are not very stable. My meaning here is to build a Windows native OpenGL development environment. Follow the steps below: - Download necessary tools: NetBeans IDE 5.5.1, NetBeans C/C++ development pack, MinGW, GLUT. Install the first three and unpack GLUT to a directory.
- Configure NetBeans C/C++ development pack and MinGW, which has been detailed in my previous article and will not be repeated here.
- Add GLUT directory to the system's environment variables to make sure glut32.dll is visible.
- Copy glut.h to include\GL under MinGW installation directory.
Like this the environment is set up. There are still some points to be noticed while compiling. In the properties of a C/C++ project, add glut32.lib into libraries (using absolute path), and set libraries options to -lopengl32 and -lglu32. glut32.dll is not a standard Windows library, so -lglut32 is useless. Now the project can be built successfully. When distributing, it it best to install glut32.dll used during development into the same directory as the built application, for avoiding the situation that the user doesn't install glut32.dll or version conflict. 一开始我是倒向微软的。在大学我加入过微软技术俱乐部,吃力不讨好地学习过 C、C++、Windows API、MFC、VC++ .NET、VC# .NET、DirectX、SQL Server,也许还不止这些,但没有一个真正搞懂过,也可以说是知难而退。我曾经嘲笑 Java 又慢又丑,OpenGL 迟早要败给 DirectX,甚至嘲笑 Java 技术俱乐部没钱了。谁又曾想到,现在 Java 是我的第一武器,OpenGL 帮助我学习计算机图形学;而微软的 MFC、.NET 什么的成了我厌恶的对象。今天我也随着 Linux 的创始人李纳斯·托沃兹把 C++ 也鄙视了。以后我可能就只用 Java 和 C 了。 这个转折是从找工作开始的。当时我那点皮毛的微软技术,谁也不会要,于是想找个捷径。正好流行 J2ME,据说上手也容易,于是开始学 Java,然后我才知道 Java 是简洁而优美的语言,且速度并不亚于 C++ 之流。就这么一直到现在。因为对市场持怀疑态度,Java ME(J2ME 改名了)没有继续了,Java SE 一直在学,Java EE 始终不太喜欢,因为我感兴趣的是眼睛能看到效果的。学了好一阵 Swing 和 Java2D 后,想研究一下更底层的学问,也就是正在学习的计算机图形学。 In the beginning I was on the side of Microsoft. I had joined Microsoft Technical Club in university, learn C, C++, Windows API, MFC, VC++ .NET, VC# .NET, DirectX, SQL Server and maybe more very hard but got little. I had never got to really understand even one of them, or I just retreated before the impossible. I used to laugh at Java's slowness and ugly, at OpenGL's defeated by DirectX sooner or later, and even at Java Technical Club's lack of money. Who had thought that Java is now my first-place weapon, OpenGL helps me study computer graphics, but Microsoft's MFC, .NET or so becomes what I am sick of. And today I look down on C++ together with Linus Torvalds, founder of Linux. I will probably only use Java and C in the future. This turn started from when I was looking for a job. At that time, my superficial knowledge of Microsoft technology appealed to nobody, and I wanted to find out a shortcut. J2ME was popular and said to be easy to get start with, so I began to learning Java, and realized Java is a terse and beautiful language and its speed is no slower that C++ and its like. That lasts to today. Java ME was given up (J2ME has changed its name) because of my suspicion of its market, Java SE is always leared, and Java EE is never liked because I am interested in that whose effects can be seen. After a long time of learning Swing and Java2D, I want to study more lower level staffs which turns out to be Computer Graphics I am currently learning. 9/9/2007 我用 C 写了一个程序读取 32768 字节大小的文件,每次读 16 个字节,应该是 2048 次读完。但结果读了 2049 次,并且最后两次的数据相同,似乎重复读取了最后 16 个字节。源代码如下: int loop = 0; while (!feof(file)) { loop++; fread(buffer, 16, 1, file); // 以下省略处理读取的 buffer。 } printf("%d\n", loop); // 打印结果是 2049。 | 我想了一阵,发现导致这个错误的原因是 feof(FILE*) 判断文件末尾的机制:它必须要在文件末尾之后再读取一次才能判断出末尾。文件指针在文件末尾的时候,除非再读一次导致发生 I/O 错误(因为这是在文件末尾之后读取),feof(FILE*) 依然返回 0。因此用 feof(FILE*) 作为判断条件的 while 循环始终会多读一次,而最后一次的读取是失败的,buffer 也就没有改变,看起来就像是重复读了一次。 用下面的代码就没问题了: int loop = 0; while (fread(buffer, 16, 1, file) == 1) { loop++; // 以下省略处理读取的 buffer。 } printf("%d\n", loop); // 打印结果是 2048。 | 9/2/2007 法国以自然事物命名一年的十二个月,这些名称来源于法国大革命中一度实行的历法。 1793 年 10 月 5 日国民公会决定废止基督教的格利高里儒略历(即公历),采用革命历法,即共和历。共和历以法兰西第一共和国建立之日(1792 年 9 月 22 日)为历元,每年分四季,12 个月,每月 30 天,每 10 天为一旬,每旬第 10 日为休息日。12 个月之外余下的 5 天(闰年为 6 天,包括 1796、1800 和 1804)称为“无套裤汉日”。 根据 10 月 24 日法布尔·戴格朗丁的提议,共和历借用当时一本小册子里作者想象的富有诗意的名称来命名 12 个月。附在格利历日期上的圣徒名字则用种子、树木、花和水果的名字加以替换。法国大革命中发生的热月政变、芽月起义、牧月起义、葡月暴动、果月政变、花月政变、雾月政变等事件以及牧月法令、风月法令等等,就是按共和历的月份命名的。1806 年元旦开始,拿破仑一世政权恢复格里历法,正式废止了共和历,这些名字就进入历史了。 以下是共和历与公历对照: | 葡月 | Vendemaire (Vintage) | 9.22 ~ 10.21 | | 雾月 | Brumaire (Fog) | 10.22 ~ 11.20 | | 霜月 | Frimaire (Frost) | 11.21 ~ 12.20 | | 雪月 | Nivose (Snow) | 12.21 ~ 1.19 | | 雨月 | Pluviose (Rain) | 1.20 ~ 2.18 | | 风月 | Ventose (Wind) | 2.19 ~ 3.20 | | 芽月 | Germinal (Budding) | 3.21 ~ 4.19 | | 花月 | Floreal (Flowers) | 4.20 ~ 5.19 | | 牧月 | Prairial (Meadows) | 5.20 ~ 6.18 | | 获月 | Messidor (Harvest) | 6.19 ~ 7.18 | | 热月 | Thermidor (Heat) | 7.19 ~ 8.17 | | 果月 | Fructidor (Fruit) | 8.18 ~ 9.21 |
生物学 W.·布赖恩·斯文尼、布赖恩·牛皮纸雅各、杰弗里·W.·布立顿和韦恩·汉森,褒奖他们的突破性研究:《便秘的军人:遍布外派的美军上下》,特别褒奖他们对肠道运动频率的数字分析。[发表在《军事医学》,第 158 卷,1993 年 8 月,346~348 页。]
和平 马哈里西大学及科学、技术和公共政策研究所的约翰·哈格林,和平思想的散播者,褒奖他的实验结论:4000 名受训的沉思者在华盛顿造就了 18% 的暴力犯罪的减少。[参考:《临时报告:1993 年 6 月 7 日到 7 月 30 日在华盛顿减少暴力犯罪和增强政府效力的国家示范项目》,爱荷华州菲尔费德镇科学、技术和公共政策研究所。]
医学 该奖项分成两部分颁发。首先是 X 病人,前美国海军陆战队员,他的宠物响尾蛇毒咬下的英勇受害者,褒奖他果断使用电休克疗法——他自己坚称,汽车火花塞线搭在他的嘴唇上,发动机引擎以 3000 rpm 旋转了五分钟。其次是落基山脉毒药中心的理查德·C.·达特博士和亚利桑那州健康科学中心大学的理查德·A.·古丝塔森博士,褒奖他们基础牢固的医学报告:《响尾蛇毒电休克治疗的败笔》。[发表在《急诊医学年鉴》,第 20 卷,6 号,1991 年 6 月 6 日,659~661 页。]
昆虫学 纽约州威斯特伯特镇的罗伯特·A.·洛佩兹,英勇的兽医和所有大小生物的朋友,褒奖他的系列实验:从猫身上取出耳蚤,放进他自己的耳朵,然后仔细观察和分析结果。[发表为《跳蚤和人的》,《美国兽医医学协会月刊》,第 203 卷,5 号,1993 年 9 月 1 日,606~607 页。]
心理学 李光耀,前新加坡首相,消极强化心理学的实践者,褒奖他三十年来为吐痰、嚼口香糖或喂鸽子而惩罚三千万新加坡市民造成的效果的研究。
文学 L.·朗·哈伯德,科幻小说的热心作者和知觉教的创始人,褒奖他响当当的好书《心灵清新学》,那对全人类或其中一部分价值不菲。
化学 德克萨斯州参议员鲍勃·格拉斯哥,逻辑立法的聪明写手,褒奖他发起 1989 毒品控制法,使得未经允许购买烧杯、烧瓶、试管或其他实验室玻璃器皿是非法的。
经济学 智利的简·巴勃罗·达维拉,孜孜不倦的金融期货交易者和国营铜公司的前雇员,褒奖他教他的电脑“买”当他的意思是“卖”的时候,然后不断增加不赚钱的交易以图收回他的损失,最终损失了智利国家总产值的 0.5 个百分点。达维拉的不懈成就启发他的国人炮制出一个新的动词:“davilar”,意思是“庄严地搞砸”。
数学 阿拉巴马南浸礼教堂,伦理的数学测量者,褒奖他们一个挨一个镇地估算如果不忏悔,有多少阿拉巴马市民会下地狱。
|