Hiển thị các bài đăng có nhãn Eclipse. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Eclipse. Hiển thị tất cả bài đăng

20/4/13

Hướng dẫn sử dụng thư viện OpenCV Eclipse


Hướng dẫn sử dụng thư viện OpenCV

OpenCV là một thư viện mã nguỗn mở rất mạnh hỗ trợ cho việc xử lý ảnh cũng như các vấn đề liên quan đến thị giác máy tính (Computer Vision).
Tron bài này tôi sẽ hướng dẫn cách sử dụng thư viện OpenCV cho việc lập trình trên ngôn ngữ C/C++ trong môi trường Visual Studio và Eclipse.
Trước hết các bạn download thư viện OpenCV về. Hiện có nhiều phiên OpenCV khác nhau, các bạn nên download bản mới nhất về dùng, Ở đây tôi giả sử đang dùng bản 2.3.1. Tiếp theo các bạn cài đặt thư viện lên, việc cài đặt ở đây thực chất là giải nén thư viện OpenCV vào một thư mục nào đó, các bạn cài đặt như bình thường, ở đây tôi giả sử là cài vào thư mục C:\. Sau khi cài đặt ta sẽ có thư mục C:\opencv và bên trong có rất nhiều thư mục con.
Sử dụng OpenCV với Eclipse CDT và trình dich MinGW GCC.
Từ cửa sổ Eclipse chọn New -> C++ Project , hộp thoại C++ Project xuất hiện, trong hộp thoại ta chọn Project name là opencv, Project type là Hello World C++ Project, Toolchains là MinGW GCC.



Chọn Finish và ta có một Project mới. OK, bây giờ configure cho project này hoạt động được với OpenCV
Trong cửa sổ của Eclipse chọn Project ->Properties, cửa sổ Properties hiện ra. Tron cửa sổ Properties chọn C/C++ Build->Settings. Trong tab Tool Settings. Ở phần GCC C++ Compiller chọn Include rồi dẫn đường dẫn tới mục Include của OpenCV là C:\opencv\build\include. Trong phần MinGW C++ Linker chọn Library và chọn các mục như sau: click vào dấu cộng ở Library search path (-L) và dẫn tới thư mục lib: C:\opencv\build\x86\mingw\lib đối với Windows 32 bit hoặcC:\opencv\build\x64\mingw\lib đối với Windows 64 bit. Tiếp đó click vào dấu "cộng" để thêm Library(-I) vào, các library cần thêm lần lượt là: opencv_core231, opencv_highgui231, opencv_imgproc231 ... nói chung là tùy vào nhu cầu sử dụng có thể thêm một hoặc nhiều lib vào.


Nhấn OK để hoàn thành, như vậy là configure xong, bây giờ là viết một chương trình đơn giản là load và hiển thị một ảnh từ máy tính.
Trong file opencv.cpp thêm vào header : #include <opencv2/opencv.hpp> . Việc thêm header này vào sẽ tự động thêm tất cả các thư viện của opencv vào trong project. Tuy nhiên các bạn cũng có thể thêm thủ công vào project của mình bằng cách thêm các thư viện #include <opencv2/core/core.hpp>#include <opencv2/imgproc/imgproc.hpp> ...
Toàn bộ chương trình đơn giản như sau : 

#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;

int main() {
    cout << "The first program in opencv" << endl;
    IplImage *img = cvLoadImage("D:\\Test\\test.jpg", CV_LOAD_IMAGE_COLOR);
    cvNamedWindow("Test", CV_WINDOW_NORMAL);
    cvShowImage("Test", img);
    cvReleaseImage(&img);
    return 0;
}


Chương trình đã hoàn tất, tuy nhiên lúc này để chạy được ta cần copy các file DLL trong thư mục C:\opencv\build\x86\mingw\bin vào thư mục chứa file chạy (opencv.exe) hoặc vào trong thư mục C:\WINDOWS\system32. 
Giờ thị build và chạy chương trình, ta sẽ thấy một cửa sổ ảnh Test hiện ra. Ok, xong phần với eclipse. 

Sử dụng OpenCV với Visual Studio

Phiên bản Visual studio sử dụng ở đây là phiên bản Visual studio 2010, các version trước các bạn có thể cấu hình một cách tương tự.
Tạo một project mới: New > Project, trong cửa sổ New Project chọn Visual C++, Win32 console application. Đặt tên project là opencv


Nhấn OK, Next, Finish và ta có một project mới. Bây giờ vào Project > Properties hoặc nhấn Alt + F7 để mở hộp thoại property. Hộp thoại opencv property page hiện ra, Trong mục Visual C++ Directories, chọn Include Directories, dẫn tới đường dẫn chứa thư mục include của opencv, ở đây là C:\opencv\build\include

Tương tự như vậy, trong mục Lybrary Directories chọn đường dẫn tớiC:\opencv\build\x86\vc9\lib
Trong mục Liker > Input > Additional Dependence ta thêm vào các lib:opencv_core231.lib,
opencv_imgproc231.lib, opencv_highgui231.lib
 ... Tùy vào mục đích chương trình mà ta có thể thêm nhiều hoặc tất cả các lib vào.

Để máy tính có thể chạy được chương trình ta cần phải chỉnh phần PATHenvironment variable, tuy nhiên để đơn giản tôi thường copy hêt các file *.dll trong thư mục C:\opencv\build\x86\vc9\bin vào thư mục C:\Windows\System32 hoặc vào thư mục chứa file chạy (opencv.exe) trong project để có thể chạy được trên máy khác khi copy thư mục bin của project từ máy mình sang máy khác.
Cài đặt xong, bây giở viết chương trình đơn giản load ảnh và hiển thị ảnh:

#include "stdafx.h"
#include <opencv2/opencv.hpp>

int _tmain(int argc, _TCHAR* argv[])
{
    IplImage *src = cvLoadImage("D:\\Temp_work\\opencvgiude2.jpg", CV_LOAD_IMAGE_COLOR);
    cvNamedWindow("a", 1);
    cvShowImage("a", src);
    cvWaitKey(10);
    return 0;
}
OK, giờ thì build và chạy chương trình, ...

12/2/13

Tạo và chạy ứng dụng Android đầu tiên với Eclipse


Tạo và chạy ứng dụng Android đầu tiên với Eclipse

Ở bài số 1 chúng ta đã học cách cài đặt và cấu hình môi trường lập trình Android trên IDE Eclipse. Các bạn có thể tham khảo bài trước ở đây
Bước 1: Chọn New Android App Project , xuất hiện hộp thoại sau:
Build SDK: mặc định là bản latest SDK bạn đã cái trên máy
MinimumRequired SDK: bản thấp nhất của Android hỗ trợ cho app của bạn

Bước 2: Tạo icon cho ứng dụng
Tham khảo http://developer.android.com/design/style/iconography.html
Bước 3: Chọn template cho project, với VD này là Blank Activity
Bước 4: Chọn next ở màn hình tiếp theo, nếu gặp màn hình này chọn Install/Upgrade
Chọn “Accept” và “Install”
Sau khi upgrade xong , ấn “Finish” và khởi động lại Eclipse
Một vài chú ý trước khi chạy project:
AndroidManifest.xml mô tả những đặc tính cơ bản và xác định các thành phần của ứng dụng. Bạn sẽ được học rõ hơn trong những bài tiếp theo.
Src: folder chính để lưu giữ các fie mã nguồn. Mặc định nó bao gồm lớp Activity sẽ được gọi khi khởi chạy ứng dụng
Res: chứa những thư mục con để lưu trữ hình ảnh âm thanh của ứng dụng
drawable-hdpi/
Thư mục cho các đối tượng drawable( chẳng hạn như ảnh bitmap) được thiết kế mật độ cao (hdpi). Các thư mục drawable khác chứa tài sản được thiết kế cho các mật độ màn hình khác.
layout/
Thư mục định nghĩa giao diện người dùng cho ứng dụng của bạn
values/
Thư mục cho các tập tin XML để định nghĩa màu sắc và chuỗi ký tự.
Trước khi chạy chúng ta phải thiết lập máy ảo như sau:
Chọn biểu tượng ở thanh toolbar, hộp thoại hiện lên chọn New, sau đó nhập một vài thông số:
Name: Tùy ý
Targert:  Chọn phiên bản hệ điều hành bạn muốn
SD Card: gõ size của SD Card ( mình để là 256 MiB)
Skin: Có thể để default (HVGA) hoặc chọn kích cỡ bạn muốn
Sau khi khởi tạo máy ảo chọn máy ảo và nhấn nút Start ở thanh công cụ bên phải. Giao diện sau khi chạy thành công

Quay lại với project MyFirstApp đã tạo ở bước trên, chọn và click Run từ thanh toolbar
Một số chức năng quan trọng cần biết khi lập trình Android
Android có một hệ thống debug hoàn hảo được hỗ trợ bởi logcat. Logcat sẽ thông báo toàn bộ về hệ điều hành, giúp chúng ta biết được  hệ điều hành đang làm gì, gọi đến cái gì, khởi chạy những gì, chiếm dụng bộ nhớ ra sao … (các bạn sẽ được nói rõ hơn trong những bài sau)

File Explorer của Android là tính năng hữu ích của Google đưa vào giúp chúng ta quản lý file trong sd card  và cả file system data. File Explorer giúp bạn dễ dàng đưa file vào/ lấy file ra trong sdcard ảo của simulator, xóa cơ sở dữ liệu để khởi tạo lại (only emulator)
Mở File Explorer bằng cách: Window->ShowView->Other->Android->File Explorer

7/1/12

Installing and configuring OpenCV 1.1 + Eclipse on ubuntu 10.04 and higher

 
During our computer vision course this semester we were strictly required to use OpenCV version 1.1 in our programming assignments. Since this is a very outdated version, there are some problems with it especially with the newer ubuntu versions. Newer OpenCV versions such as 2.x can be easily installed from the repositories without any problems. I have no clue about the exact differences between OpenCV2.X and OpenCV1.1 and whether or not it is that necessary to use the latter outdated version in order to mach the university setups or not. That's why I didn't go with OpenCV2.x which is the current mainstream version.

After some Googling and intense hacking around. I managed to hack my way through all difficulties and error messages and finally install OpenCV 1.1 on my 10.10 Ubuntu maverick.

Therefore, in this tutorial I will guide you in details through compiling OpenCV 1.1 from source and getting it to work on Ubuntu 10.04 and higher as well as configuring it to work with eclipse.

Note: If you have any version of OpenCV previously installed, make sure you completely purge it along with it's configuration files and libraries before you proceed with this tutorial. Two OpenCVs at once = Doom's day. You have been warned.

Part 1: Installing OpenCV 1.1

1. OpenCV depends on some packages as well as dev libraries, so let's install these (Make sure you have the 'universe' and 'multiuniverse' repositories enabled in your ubuntu software sources):
?
1
2
# OpenCV dependencies
sudo apt-get install gcc g++ pkg-config libgtk2.0-dev libjpeg62-dev libtiff4-dev libjasper-dev libpng12-dev zlib1g-dev build-essential
There are some other optional dependencies you might wanna install depending on what u r going to be doing using OpenCV such as (openexr for HDR images, ffmpeg and libgstreamer for videos, libv4l for webcam support, ... etc). Note: Some of these might cause some bugs if u follow the same instructions in this tutorial as u would need to pass extra parameters to the ./configure script to generate the make file.

2. Download the OpenCV 1.1 source tarball from here somewhere you know. Say in /home/user_name/Downloads. Where 'user_name' is your ubuntu user name.

3. Extract the content of the downloaded file.
?
1
2
3
4
# Navigate to where you downloaded it.
cd ~/Downloads
# Extract in Current dir.
tar -zxvf opencv-1.1pre1.tar.gz
4. There is a certain C header file that will cause a problem if you try to './configure' due to a declaration error in the code. Let's fix that:
?
1
gedit ~/Downloads/opencv-1.1.0/cxcore/include/cxmisc.h
At line 133, change "#elif" to "#else" then save like the screenshot below:
5. Now, lets configure and generate the make file that we are going to build:
?
1
2
3
4
5
6
# Gain root privilege.
sudo -s
# Navigate to OpenCV extracted dir
cd ~/Downloads/opencv-1.1.0/
# Configure
./configure --disable-apps --without-v4l --with-gtk
Basically the parameters we are passing to the ./configure disables adding the sample apps path in the generated make file (so they do not take time in building), --without-v4l to disable 'video4linux' support which is basically web-cam support in opencv as there is some buggy code in that part of the configure script and finally --with-gtk to force using gtk window management library. (necessary by functions such as cvNamedWindow(..) and such)

6. After the configure script (step 5) finishes, we need to build the source package using the generated make file:
?
1
2
# Make sure you are still root and inside the opencv dir!
make
The last line of the output of that command should be something like:
Leaving directory `/home/user_name/Downloads/opencv-1.1.0' where user_name is your ubuntu user name. Otherwise, know that the make command did not succeed and failed somewhere in the process.

7. Next, we need to install:
?
1
2
# Make sure you are still root and inside the opencv dir!
make install
Also, The last line of the output of that command should be something like:
Leaving directory `/home/user_name/Downloads/opencv-1.1.0' where user_name is your ubuntu user name. Otherwise, know that the installation did not succeed and failed somewhere in the process.

8. After that, we need to configure opencv with ld such that it "feels" the new libraries:
?
1
2
# create/edit opencv.conf
sudo nano /etc/ld.so.conf.d/opencv.conf
Add "/usr/local/lib" without the quotes in a new line then press CTRL+o in order to save your changes and create the file if it's not there.

9. Then, we need to poke ldconfig =D. So:
?
1
2
# wake that lazy bitch up!
sudo ldconfig
10. Finally, we need to add the pkgconfig system path:
?
1
sudo gedit /etc/bash.bashrc
Then append the following lines to the end of it and save:
?
1
2
3
# Added during OpenCV installation
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
11. Logout the log back in.

12. Now, we need to make sure  that the libraries and and paths are in-place and we are set to go:
?
1
2
3
4
# Verify includes
pkg-config --cflags opencv
# Verify libraries
pkg-config --libs opencv
The output of these two command should be:

-I/usr/local/include/opencv

and

-L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux -lml

Respectively.

13. Now if it all went okay then, it's time to test some code and see some output. So, download the following file into say your /home/user_name/Downloads directory. where user_name is ur ubuntu user name.

hello.cpp
Download File


Then compile and run it by typing the following commands:
?
1
2
3
4
5
6
# Navigate to Download dir
cd ~/Downloads
# Build binary
g++ -I/usr/local/include/opencv -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux -lml hello.cpp
# Run it
./a.out /path/to/an/image.jpg
Where /path/to/an/image.jpg is a jpg image which you know it's location.

If it all goes well, you should see "Hello" printed in the terminal and a window containing your image poping-up and showing the gray-scale version of it like the screenshot below.

Part 2: Configuring Eclipse with OpenCV

a. Download the linux version of Eclipse for C/C++ developers from here. Extract the downloaded file and run the file named "Eclipse" from inside the extracted folder in order to launch eclipse.

b. File -> New -> C++ Project -> Enter a name -> Finish.

c. Right click on created project folder -> new -> Source File -> hello.cpp -> finish. Then, copy and paste the code that you downloaded in step 13.

d. Right click on project folder -> properties -> C/C++ build -> settings -> G++ compiler -> includes. Then in the include paths section (-I) click the tiny add button which has a green + sign on it and add the following path: /usr/local/include/opencv Like the screenshot below:
e. From the same window as in (d), navigate to G++ Linker -> Libraries and add libraries (-l) and library search paths (-L) as in the following screenshot:
f. Modify the 1st two lines of code as follows:
#include <cv.h> -->  #include <opencv/cv.h>
#include <highgui.h> --> #include <opencv/highgui.h>

g. Right click -> refresh your project. There shouldn't be any warnings or errors.

h. Build then Run using the eclipse toolbar. You will see this output displayed in console:
Hello
Enter filename
File not found



Congratulations! Now you are done =D. If you faced any problems or have any remarks please post them in the comments blow ;)

Setting up OpenCV 2.3 and Eclipse on Ubuntu 11.10

Setting up OpenCV 2.3 and Eclipse on Ubuntu 11.10

This post seeks to help you in installing OpenCV and Eclipse and setting them up on Ubuntu 11.10 Oneiric so that you can begin development straight away.

What is OpenCV? OpenCV is a library of programming functions (in C and some C++ classes) mainly aimed at real time computer vision and image processing. It is a cross platform library, first developed by Intel and now supported by Willow Garage, and is free for use under the open source BSD license.

What is Eclipse? Eclipse is a multi-language software development platform comprising an IDE and lots of plug ins to help you develop applications in several widely used programming languages.

This walk through is aimed at helping you to set up OpenCV 2.3 (the latest version as of January 2012), and Eclipse CDT (Eclipse with the C Development Toolkit) on Ubuntu 11.10.

Ubuntu 11.10 does come with OpenCV 2.1 in the repositories, but we want OpenCV 2.3 ... so we first begin with adding a PPA for OpenCV 2.3.

Head over to the terminal and type

$ sudo add-apt-repository ppa:gijzelaar/cuda
$ sudo add-apt-repository ppa:gijzelaar/opencv2.3
$ sudo apt-get update

Now, do the usual apt-get to get OpenCV. Note that the usual Ubuntu repos have a package called libcv-dev, however with the new PPA we are looking for a package called libopencv-dev.


$ sudo apt-get install libopencv-dev

This installs OpenCV on your computer. You will find the package files in /usr/include/opencv/

Now for Eclipse. You can do the usual apt-get (sudo apt-get install eclipse) to get Eclipse or you can download from the official website. I recommend the former. At the end you should have the following packages installed on your machine. ( I further recommend you install Synaptic Package Manager (sudo apt-get install synaptic) and then check for the individual packages.)


eclipse
eclipse-platform
eclipse-rcp
eclipse-platform-data
eclipse-pde
pdebuild
eclipse-cdt


Now you should be able to launch Eclipse. So do that and then create a new C or C++ project.


We shall write an introductory OpenCV program in C++ in this project, so we name the project ImageDisplay. (Note that I have created a C++ project and not a C project. While Ubuntu comes with the default gcc compiler for C, it does not have the GNU C++ compiler, g++ by default. In case you also wish to use C++ instead of C, do a sudo apt-get install g++ to install the g++ compiler on your computer).




We now have a C++ project called ImageDisplay. To enable us to use the OpenCV libraries in this project we need to include these libraries. To do that, right click on the ImageDisplay project in the Project Explorer on the left and select Properties. Go to C/C++ build in the left menu and then Settings, in the dialog box that appears.

The Configuration bar should be set to Debug [ Active ]. In the Tool Setting tab, select Directories in the GCC C++ Compiler menu and add the path

/usr/include/opencv





Now go to Libraries under GCC C++ Linker and add the libraries that you would need. Typically you would definitely need opencv_core and opencv_highgui. The other libraries that you can add are


opencv_imgproc
opencv_ml
opencv_video
opencv_features2d
opencv_calib3d
opencv_objdetect
opencv_contrib
opencv_legacy
opencv_flann


Lastly, in the Library search path, add /usr/lib.


Make sure that you add these paths and directories for the Release build as well (in the Configuration bar).


Now we are all set to write our first OpenCV program.


Before that let us once run through what all we've done.

  • Installed OpenCV.
  • Installed Eclipse.
  • Installed G++.
  • Created a project called ImageDisplay.
  • Configured the libraries and paths with our project.
Now for the program.


Create a file within your ImageDisplay project called main.cpp. Also, copy an image (.jpg format) to your project workspace folder. (You had set your workspace folder when you had started Eclipse. If you do not remember, then it mostly is in your home folder, and it's called workspace. There'll be a folder within the folder corresponding to you current project called ImageDisplay. So copy the image there. Call it image.jpg)


Double click main.cpp in the Project Explorer and write the following piece of code. If all goes well, when you compile and run this program, you should see a window and your image.jpg should be displayed in it.
Just replace the quotes in the include statements with angular brackets.


#include "cstdlib"
#include "cmath"
#include "cv.h"
#include "highgui.h"



int main(int argc, char *argv[])

{

cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
IplImage* img = 0;
img=cvLoadImage("image.jpg");
cvShowImage("Example1", img );
cvWaitKey(0);
cvReleaseImage(&img );
return 0;
}
-
Now save this file (Ctrl+S) and compile the code (ie "build" the project with Ctrl+B). Now click on the green arrow in the Eclipse toolbar to run the code.


You should see a window pop up called Example1 and your image.jpg should be in it.

You might face an error during compile time / run time that looks something like this :
Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",
This is because you do not have a package in your system. To install it, just head over to the terminal and type
sudo apt-get install gtk2-engines-pixbuf
That should be it. If you face any problem reread this post again and follow it carefully. Else of course, you can drop me a mail.


--


Also a very Happy New Year. Why I don't get all gaga on New Year's can be summed up nicely in the words of Mark Twain.
New Year's is a harmless annual institution, of no particular use to anybody save as a scapegoat for promiscuous drunks, and friendly calls, and humbug resolutions, and we wish you to enjoy it with a looseness suited to the greatness of the occasion
So there.

Eclipse – C/C++ (CDT), Python (PyDev), and Qt (Qt4) Plugins Installation Tutorial for Ubuntu 10.04

Eclipse – C/C++ (CDT), Python (PyDev), and Qt (Qt4) Plugins Installation Tutorial for Ubuntu 10.04

This walk-through will take you from a fresh install of Eclipse to a fully-functional IDE ready for development of Java, Python, C/C++, and Qt GUI applications. Every step is tailored to Ubuntu but might possibly be useful to Windows/Mac users as well. Enjoy!

First step, Install Java

By default, Ubuntu comes with the OpenJDK Runtime Environment. Honestly, I haven’t had any problems running Java applications with OpenJDK. However, I’ve read in a couple of places that Eclipse and/or some of its plugins cannot use OpenJDK. If you want to see what JRE version you have enabled, do this:
~$ java -version
Getting Sun Java in Ubuntu is easy. Just do this to get everything you need (the JRE, browser plugin, development kit, and fonts):
~$ sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-jdk sun-java6-fonts
Update 28APR11 – you have to make sure you’ve enabled partner repositories before the above command will work. From the Synaptic Package Manager, click on Settings → Repositores, go to the Other Software tab, and make sure Canonical Partners is checked. Thanks to HelloWorld321 for this update.
Now, while we’re at it, let’s make sure your browser actually uses this new browser plugin for Java applets instead of the default IcedTea plugin that’s based on OpenJDK. I have had many problems with the IcedTea browser plugin.
~$ sudo apt-get remove icedtea6-plugin
To ensure your browser is using the Sun Java plugin, you can look at Tools → Addons or simply go to JavaTester.org to get a display of the version and vender from the JRE your browser is using.
Anyway, back to the task at hand. Just because we have Sun Java is installed doesn’t mean Ubuntu is going to use it. If you do java -version again, you’ll note that Ubuntu still uses OpenJDK. You could uninstall OpenJDK, but that’s not necessary. We can switch which version of Java runs by default. First, though, let’s see which version of Java we just installed:
~$ /usr/lib/jvm/java-6-sun/bin/java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode)
At the time of this writing, the most recent stable version of Java is Version 6 Update 21. According to my terminal output above, I just installed Version 6 Update 20. One update behind isn’t too bad, so I didn’t see any reason to download Java directly from Sun.
Ok, how do we switch which version of Java runs by default? Do this:
~$ sudo update-java-alternatives -l
This should show you the available versions of Java. Now, to switch the default to Sun Java, do this:
~$ sudo update-java-alternatives -s java-6-sun
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
java-6-sun 63 /usr/lib/jvm/java-6-sun
Great! Now we have a recent version of Sun Java installed and ready to use. The next step is to get Eclipse.

Install Eclipse

Don’t download eclipse from the Ubuntu repository. If you already have, uninstall it. Instead, get the most up-to-date version of eclipse at the Eclipse download page. I chose to download Eclipse Classic 3.6.1 as opposed to the tailored versions. From my understanding, the only differences are which plugins come with the download. Here’s how to extract the download and create a startup script for it that’s inside the system path:
$ cd /opt
$ sudo tar xzf /home/greeenguru/Downloads/eclipse-SDK-3.6.1-linux-gtk.tar.gz
$ sudo touch /usr/bin/eclipse
$ sudo chmod +x /usr/bin/eclipse
$ sudo gedit /usr/bin/eclipse
Now edit the executable file you just created to contain the following BASH startup script:
#!/bin/sh

export ECLIPSE_HOME="/opt/eclipse"

# Now run eclipse with the argument list $*
$ECLIPSE_HOME/eclipse $*
Create a GNOME menu item for Eclipse:
Just use the GUI to do this. It’s easier and more reliable. Right-click on your applications menu, choose Edit Menu, go to your Programming menu, and hit the New Item button. This way, your icon set might even have a default icon for you automatically, and you don’t have to worry about if the method below will work or not.
~$sudo gedit /usr/share/applications/eclipse.desktop
Here’s what to enter to create the menu item correctly:
[Desktop Entry]
Encoding=UTF-8
Name=Eclipse
Comment=Program Some Stuff
GenericName=Interactive Development Environment
Exec=eclipse
Terminal=false
Type=Application
Icon=/opt/eclipse/icon.xpm
Categories=GNOME;Application;Development;
StartupNotify=true 
Now go to your Applications Menu, click on Eclipse, and make sure it works.

Install the C/C++ Development Toolkit (CDT) Eclipse Plugin

Now that you have Eclipse up and running, let’s add C/C++ support via the CDT plugin. We can do this entirely from within Eclipse. Just go to Help → Install New Software…:
Install New Software Then click on the Add to add a software site to install from:
Add Software Site The CDT repository is located at http://download.eclipse.org/tools/cdt/releases/helios:
CDT Repository At first, I tried to just install all the available CDT options:
CDT Packages But after I received an error, I went back and deselected the Remote Launch package. I’m sure I don’t need all of these options, but I don’t know which ones I do need, so I just installed all of the rest as you can see below:
CDT Packages Final Selection After making your choices, click Next. You will see an Install Details dialog containing all the software you selected to install (assuming you didn’t get an error). Just click Next. Finally, you’ll see a Review Licenses window. Just agree to the license agreement and your installation will begin:
CDT Installing Since Ubuntu already has g++, make, gcc, and gdb, installed and in the system path, you shouldn’t have any problem building C++ programs once CDT is finished installing. Just be sure to restart when prompted, then try it out. Go to Help → Cheat Sheets and find the Hello World application for C++. This will walk you through building a simple C++ executable.
Note: If you have problems after restarting Eclipse, exit and restart from the run dialog or terminal with the command eclipse -clean. This will clean the Eclipse cache and hopefully resolve some problems.

Install the PyDev Eclipse Plugin for Python Support

You can install PyDev for Python support completely from within Eclipse just as you did the CDT. Just follow the same steps as before (Help → Install New Software… and click Add), then add the PyDev repository, which is located at http://pydev.org/updates
PyDev Repository I don’t use Django, so I just need the main package:
PyDev Packages Finish the Install Wizard as you did with CDT and restart Eclipse when prompted. You now have support for Java, C/C++, and Python!
Note: If you have problems after restarting Eclipse, exit and restart from the run dialog or terminal with the command eclipse -clean. This will clean the Eclipse cache and hopefully resolve some problems.

Install The Qt Eclipse Integration Plugin

Qt Eclipse Integration is pretty cool if you’re going to be doing any C++ GUI development. You have to make sure you have CDT installed first, then download the package from the Qt Eclipse Integration Download Page. The rest of my instructions are basically taken from Qt’s Installation Instructions for Linux Systems.
According to Qt’s website, the preferred method for installing their plugin is from outside Eclipse, so go ahead and close it first. Next, make sure you have the Qt4 Development Library installed:
$ sudo apt-get install libqt4-dev qt4-doc-html
Notice that I also installed the documentation. I usually create a launcher for the documentation I think I’ll use:
Qt4 Documentation Launcher Go to the location of your eclipse installation directory and extract the Qt plugin. For some reason the plugin has been archived to extract as eclipse → plugins → important stuff, so you need to be in the parent folder of your eclipse installation directory when you extract the plugin in order for everything to extract to the right place:
$ cd /opt
$ sudo tar xzf /home/greeenguru/Downloads/qt-eclipse-integration-linux.x86-1.6.1.tar.gz
That’s it. Just launch Eclipse from the run dialog or terminal with the command eclipse -clean to start with a clean configuration. However, you’re not quite done because it still needs some configuring. You’ll need to know the version of Qt that you’re using, so do this to find out:
~$ qmake -version
QMake version 2.01a
Using Qt version 4.6.2 in /usr/lib
qmake came with the libqt4-dev package you just installed, and it is using Qt version 4.6.2 (on my system anyway). Now in Eclipse go to Window → Preferences and you should see the dialog below. Go to the Qt section as shown and Click the Add… button to add a new Qt version. This will tell Eclipse where to find the Qt version you plan to use.
Add Qt Version When you’ve finished with the dialog above, click Finish. Then click on the version you just added and click Default to make that the default Qt version:
Set Default Qt Version Finally, click Apply and you should get the following dialog:
Rebuilt Qt Projects Click Yes to this dialog and then exit Preferences by clicking Ok. Now, you’re finished configuring Qt. To get started using it, go to Help → Cheat Sheets and select Qt Development. There should be an address book application walkthrough you can learn from. Here’s what my screen looked like halfway through the walkthrough. It works just like Qt Designer, but it’s running inside Eclipse.
Qt Designer Well that’s really it. Now you should be able to program in Java, Python, C/C++, and design Qt-based C++ GUI applications all from inside the same cross-platform IDE. Enjoy!

Bài đăng phổ biến