Ext.: http://blog.csdn.net/jacktan/article/details/9268535
It has always been felt that NetBeans lives in the shadow of Eclipse, and as a good Java-based development IDE, it is a completely different development path. It's probably because I've been using Java a lot before, so eclipse has always been my most used tool. Occasionally I would have a taste of netbeans, but I always feel a little uncomfortable with the habit. However, due to the need for work, start more contact with the Linux c,eclipse CDT will appear more and more pale. After all, Cygwin and real Linux are still very different, write a simple C program Cygwin can cope, but for a larger C program and need a very complex environment, Cygwin is obviously powerless. So I started looking for other solutions ....
In the online search for related technical articles, to tell the truth, 90% of the article content is similar, or copied to copy, or a taste to stop. Most of the content is from the official website manual, and the example used is "Hello world" type, no practical value. As a "cyclist" architect, it is the responsibility to write a systematic, illustrated summary of the article to provide a valuable reference for all students with similar needs.
To talk less, let's introduce our environment and the demo routine:
Environment:
The native environment is windows7,netbeans7.3.1,java1.6 (NetBeans runtime requires a Java environment).
The remote host is RHEL5.8 64-bit, the Ssh,oracle database 11.2.0,oracle the client 11.2.0,gcc4.1.2, all C + + development packages are installed, and the installation ocilib3.12.1 is compiled.
Demo Routines:
The example we demonstrate is to develop a C program that accesses an Oracle database, which requires access to a third-party library of functions (OCILIB) and relies on the Oracle client.
The use of this routine is mainly for the following purposes:
1. Learn about the other ways C accesses the Oracle database (we used to use pro*c in general);
2. Learn how to compile source code in remote mode;
3. Learn how to linked a third-party function library in remote mode;
4. Learn how to debug in remote mode;
The above-mentioned points of knowledge basically cover most of the skills required in daily development (I refer to the use of development tools only, and programming skills vary from person to person).
I. Configuring the NetBeans Remote development environment
This part is really boring, because the official website has a very detailed introduction (both English and Chinese version), and there are a group of people on the Internet to copy themselves as a copier, so I really do not need to copy again. Here I provide a link: https://netbeans.org/kb/docs/cnd/remotedev-tutorial_zh_CN.html, if you do not know how to configure the students can first to understand.
Finally, I will provide my own configuration results on this machine as a reference frame:
Here in a few words, the students may see that the icon is red, and the above "localhost" icon is not the same, this is because the remote host is not connected, you can connect to the remote host by right-clicking on the host and selecting the "Connect" command, if the connection success icon will turn green. There will also be a list of tools on my remote host, such as GCC, G++,make and GDB, with these tools for remote development and debugging.
NetBeans also provides the problem tracker (JIRA) and the Hudson Builder Service, which is a great help for our daily development, at least I didn't find these useful tools on eclipse (probably my ignorant).
Two. Preparing the remote host development environment
The Oracle database needs to be installed on the remote host. Of course there are Oracle database clients (need oci.h header files and libclntsh.so Dynamic Library and TNS configuration), these environment installation and configuration if you want to write again w word, estimate write you won't go to see, so if you do not know about this, then go to google it, related articles more is (To determine if an Oracle client is successfully installed, simply execute the sqlplus command and connect to the Oracle database and execute the SELECT statement).
I would like to introduce the compilation and installation of the Ocilib function library. This library is an encapsulation of the OCI and provides a very friendly API interface that you would find very gracious if you were familiar with JDBC. Download the latest version from Http://sourceforge.net/projects/orclib and unzip it to the remote host. Some articles on the internet have a bit of a problem, the compilation parameters are not the same, my compilation parameters are as follows:
[Plain]View PlainCopy
- ./configure--prefix=/usr/local/ocilib--with-oracle-lib-path=/u01/app/oracle/product/11.2.0/db_1/lib-- With-oracle-headers-path=/u01/app/oracle/product/11.2.0/db_1/rdbms/public
- Make && make install
I am installing it in the/usr/local/ocilib directory, and be sure to specify the directory where the Lib directory and header files of Oracle are located, otherwise the compilation will not pass.
When the compilation is complete, the Ocilib header file and the associated link library are generated, as follows:
Header file directory and header file.
Dynamic libraries and static library files.
At this point, our third-party library is compiled and installed, then the source code can be developed on this machine.
Three. Write the source code on this machine
The most exciting link has arrived, finally can write code. To create a new project in NetBeans, select the project category "C + + Application" and click Next, as shown in:
In the Second dialog box, enter the project name, project location, build host, and so on, as shown in:
Latest Click Finish, new project complete. As shown in the following:
We open the Main.c file and start writing the code as follows:
[CPP]View PlainCopy
- /*
- * FILE:MAIN.C
- * Author:administrator
- *
- * Created on July 5, 2013, 5:32
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <ocilib.h>
- /*
- *
- */
- int main (int argc, char** argv) {
- Oci_connection *CN;
- Oci_statement *st;
- Oci_resultset *rs;
- //init Instance
- if (! Oci_initialize (null, NULL, Oci_env_default | Oci_env_context)) {
- printf ("Oci_initialize failure!\n");
- return exit_failure;
- }
- cn = Oci_connectioncreate ("STOREVM", "username", "password" ,
- Oci_session_default);
- if (!CN) {
- printf ("Oci_connectioncreate failure!\n");
- return exit_failure;
- }
- st = Oci_statementcreate (CN);
- if (!st) {
- printf ("Oci_statementcreate failure!\n");
- return exit_failure;
- }
- Oci_executestmt (St, "select * from Test T");
- rs = Oci_getresultset (ST);
- While (Oci_fetchnext (RS))
- printf ("Table.name:%s, Pk.name%s\n", Oci_getstring (RS, 1),
- Oci_getstring (RS, 2));
- printf ("\n%d row (s) fetched\n", Oci_getrowcount (RS));
- Oci_cleanup ();
- return exit_success;
- }
The IDE may be prompted not to find the Ocilib.h file because the ocilib include path is not included. We can click on the "Tools" menu and select the "Options" menu item, and in the popup dialog box, select the "C + +" tab, as shown in:
In the Code Help tab, first select the remote host that we defined in the tool collection drop-down box, then click the Add button in the C compiler tab, the directory structure of the remote host is displayed, and then select the ocilib include path, for example, the path on my remote host is "/ Usr/local/ocilib/inculde ", click the OK button when you are done. You will no longer be prompted to find the Ocilib.h header file. We can also introduce the header files of other libraries by this method (this solves the problem of introducing the remote host files into the local IDE).
Four. Compiling and linking
The code is written, start compiling the code, click on the "Build Project" button on the toolbar, as shown in:
Tragedy! The compilation failed with a hint that the Ocilib.h file could not be found. As shown in the following:
Didn't we bring in the Ocilib.h header file before? So you didn't find it? In fact, this is the two concepts, the introduction of the code is just the help of the function, this feature provides us with the IDE to browse the contents of the header file, and now is the remote host to compile the source code, plainly, we have omitted the GCC compilation parameters. All right, let's go.
By right-clicking in the project and selecting "Properties" from the context menu, a Project Properties dialog box appears, as shown in:
Under construction We select the "C Compiler" and then, in the "Include directory" item on the right, fill in the Include path to the ocilib on the remote host (if multiple directories, each directory is separated by semicolons). Finally click the OK button. Of course, there are some other GCC compiler parameters to choose from, according to their own actual situation to choose. It is recommended that you replace the "warning level" with the "more warnings" or "replace warnings with errors" option.
OK, let's click on the "Build Project" button on the toolbar again. This compilation was finally over, but the error was made when connecting the Ocilib dynamic library, as shown in:
This is obviously an error that is not connected to the dynamic library, OK, continue to open the Project Properties dialog box as shown in:
Below the build we select "Linker" and then, in the right "other library directory", fill in the Ocilib's Lib directory path on the remote host (if there are multiple directories, each directory is separated by semicolons). Then we click on the right button in the "Library" and a library dialog box appears, as shown in:
Since we want to select the Remote function library, we can only select the "Add Options" button, in the Popup dialog box, select "Other Options" and fill in the parameters of the specified library as shown in. In this way, we can solve the problem of GCC compiling any function library on the remote host. We no longer need to install GCC's emulated Linux environment on this machine, for example: Cygwin, etc.
Click on a series of OK buttons and click on the "Build Project" button on the toolbar again, this time the compile link is completed successfully, as shown in:
From there, we can also find that the path of the executable file is generated on the remote host:/root/.netbeans/remote/www.storevm.org/zgc-20130102uwx-windows-x86/d/cpro/ocilib_test. You can go to the remote host to check to see if there is a file (as far as this is done by what mechanism, please refer to the official website, I will not repeat here).
Five. Code run and debug
Compile links are OK, you can execute the program, we first create a table, the table named Test, the table has 2 fields, are VARCHAR2 type, and finally insert some test data. Click the Run Project button on the toolbar to output the 3 rows of the table in the output console of the IDE, and the program executes successfully, as shown in:
The following are the records in our actual table (via PL/SQL):
The results of the program execution are exactly the same as the results of SQL execution.
At this point, all development is complete. Then we'll play. Remote host debugging, in fact NetBeans remote host debugging and local debugging procedures exactly the same. Hit the breakpoint, then click the "Debug Project" button, and then press the F6 key to step through the debugging. As shown in the following:
You can use the buttons on the Debug toolbar to step into, step out, and so on debug operations. It feels exactly the same as in the local debug program. One thing to note is that you do not include Chinese characters in the project path, or you cannot start the remote debugger.
I want to tell the content of this, wrote here, suddenly some feelings, remember more than 10 years ago, in the era of the lack of the IDE, basically rely on Notepad or vim and other tools to write C code, and then FTP to Linux under the compilation Run debugging. Sometimes, to debug a hard-to-find bug, you have to add a bunch of printf functions to your code. Perhaps until today you still can not see those who write code with the IDE, perhaps those who have just entered the company's 80, the people are looking at you in the eyes of worship of the rapid in the Notepad to type code and let you smug, or you may use 100 reasons on the forum to talk about the advantages of freehand code. Indeed, you are very good, I also sincerely admire your perseverance. But as a technician we should embrace change and accept change. Should always stand on the forefront of technology. Technical staff can only look forward, not in situ, but also can not look back, it will only restrict our development. Chinese stereotypes are thousands of years of habits, but technical people can not cling to, otherwise we will always only imitate, cottage! Those who still write code on the Notepad people, I hope this article may give you a little bit of revelation!
Turn: NetBeans's remote Linux C development practice