CDT

From Informatics

Jump to: navigation, search

see also - JNI for information on setting up the Java Native Interface environment

Eclipse is most commonly used for Java development, but also has a powerful C development environment. This development environment can be installed as a regular eclipse plugin.

One thing you will notice when installing the C Development Environment (CDT) is that it does not come with a compiler. Both the compiler and make locations can be read from your environmental variables. If you are a cygwin user, you can configure eclipse CDT to use your cygwin installation. If not, see below for a description on configuring eclipse to use MinGW.

Contents

Eclipse CDT and Cygwin (Recommended)

To use gcc, g++, and make in cygwin:

  • Install cygwin. For information on installing Cygwin, see Cygwin. Make sure to install the packages make (make, not cmake), gcc (gcc-core), and g++ (gcc-g++). You can also get gcc-mingw-core and gcc-mingw-g++. These are all in the Devel package.
  • Create the environmental variable %CYGWIN_HOME% (from the Control Panel in Windows). Add %CYGWIN_HOME\bin% to the %Path% (if you have any other C compilers on the path, make sure this precedes those entries.
  • Follow the steps in the following article detailing how to install CDT via the eclipse software update manager. Alternatively, you can manually install CDT by downloading it from the website, extracting, and copying all folders from /Features and /Plugins to your eclipse/Featuress and eclipse/Plugins directories.
  • Restart eclipse.
  • See (and try) the following to both see how aracne was configured and test your environment - Aracne.

Eclipse CDT and MinGW

The following article describes how to configure eclipse to use the MinGW compiler: http://met.dnsalias.net:1111/howto/cdt/

  • If you plan on using MinGW, make sure you have put your MinGW and MYS installation directories before cywin on the Path. That is, under Windows in Environmental Variables, under Path you could have something like:
C:\MinGW\bin;C:\msys\1.0\bin;%CYGWIN_HOME%\bin
  • Also, make sure you set the make field in under Build Settings to mingw32-make -k (make sure you uncheck the box that reads "Use default command"

C Projects Built with CDT

Gotchas

NOTE: You do not have to do anything here as this is already done for you in the generated .h header file (from javah). This is just an FYI.

  • JNI uses C calling conventions. The C++ compiler will mangle your

function names if you don't wrap your C++ code in the following:

#ifdef __cplusplus
extern "C" {
#endif
/* JNI functions go here. */
#ifdef __cplusplus
}
#endif

An interesting article on name mangling can be found here: http://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_C.2B.2B

  • You dll may load, but the program will terminate. This could be due to a number of reasons, but a common issue is that the created exe or dll is dependent on cygwin1.dll. To use cygwin development tools to compile and link your project but at the same time avoid any dependencies in the created exe or dll on cygwin, you must set the -mno-cygwin flag. This can be set by right-clicking on the project, selecting Properties, selecting C/C++ Build, and then highlighting GCC C Compiler and adding the following to the Command text box: gcc -mno-cygwin. Do the same for GCC C Linker.

You can determine if your .exe or .dll is dependent on the cygwin1.dll, type the following:

objdump -p aracne.exe | grep "DLL Name"

A good article that details all this is here - http://www.delorie.com/howto/cygwin/mno-cygwin-howto.html

gcc -c -mno-cygwin hello.c gcc -o hello -mno-cygwin hello.o

Personal tools