PDA

View Full Version : Programming in c and c++ in the CLI



nir2000
November 30th, 2010, 01:24 PM
Hi everybody!
How can I compile programs written in c in the CLI?
Second question. How can I compile programs written in c++ in the CLI?
Answers will be greatly appreciated.
Thank you in advance.
Nir

fct
November 30th, 2010, 01:27 PM
Install the build-essentials package.

Then you can compile C programs with the gcc command and C++ with the g++ command.

Tutorial:
http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html

PaulM1985
November 30th, 2010, 01:58 PM
I don't think you need to compile your C code in CLI. You should just be able to interop onto it from you .NET code by defining the method you want to call and making sure that the method is exported from your C library.
To use your C++ code, I would consider writing an object oriented wrapper for it, but I don't know how to compile it.

Maybe this link will help.

http://www.mono-project.com/Interop_with_Native_Libraries

Paul

fct
November 30th, 2010, 02:02 PM
Ouch, I thought he meant the Command Line Interface, not the Common Language Infrastructure.
*facepalms*

PaulM1985
November 30th, 2010, 02:06 PM
It looks like compiling for C++ may not be supported yet.

http://www.mono-project.com/CPlusPlus

Maybe you could make some sort of system where you have a static map of objects in C++ with an integer key and an object. In the interop you pass in the key to specify which object you want to perform the action on.

Paul

PaulM1985
November 30th, 2010, 02:08 PM
Ouch, I thought he meant the Command Line Interface, not the Common Language Infrastructure.
*facepalms*

Oh, maybe I mis-interpreted it...
:oops:

(I have been doing quite a bit of work using CLI recently)

I guess we will find out when the original poster responds.

Paul

muteXe
November 30th, 2010, 04:06 PM
I was thinking command line interface as well. Not sure at all now.
Incidentally, you can use gcc to compile c++ programs, you just need to add -lstdc++ at the end of the compile line to pull in the c++ runtime libs.