Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to Use .NET to compile C++ code

Posted on 2004-09-18
15
Medium Priority
?
330 Views
Last Modified: 2010-04-24
Hi I'm new to .Net and C++
I am trying to use .Net to compile my C++ code.  Does anyone know how to do this?  I'm not sure where to begin.

Thanks
0
Comment
Question by:BBrian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
15 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12093496
If your C++ is standard, non managed C++. Then you can make it as usual. Create a new Project in File -> New -> Project -> Win32 console application (I guess your app is console based. If not, please advice)
0
 

Expert Comment

by:axsaxs
ID: 12094560

If you download the .NET Framework (for instance here: http://msdn.microsoft.com/netframework/downloads/framework1_1redist/), after installing you will have the Microsoft C/C++ compiler, which is called "cl" and can compile standard C++ source code.

You can find compiler options here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_compiler_reference.asp

Altough not 100% ANSI-ISO C++ compatible, this new version of the Microsoft C++ compiler is quite standard and offers, IMHO, some of the best optimizations in the "free" compilers market.

0
 

Author Comment

by:BBrian
ID: 12103646
Here's the probem....when I paste this code..

#include <iostream.h>
void main ( )
{
      cout <<"Hello World"<< endl;
}


I get errors.  It doesn't recognize the iostream.h file.  It says there is no such file directory exists.

0
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12103698
type with:

#include <iostream>

don't use .h extension.
0
 

Author Comment

by:BBrian
ID: 12104704
ok..i omitted the .h extention..but i still get..

There is no build command line to execute.
Performing Makefile project actions
GenTest2 : error PRJ0003 : Error spawning ''.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12104731
How have you created your project? which options?
0
 

Author Comment

by:BBrian
ID: 12105053
I chose...

1.  Visual C++ projects
2.  Under The General Tab...I selected...
     MakeProjectFile
3.  The wizard comes up..then I click finish
4.  Add a new item to the project
5.  I select a .cpp file


Then I paste this code into the .cpp file

#include <iostream>
void main ( )
{
      cout <<"Hello World"<< endl;
}


and i get the error..
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12105168
Yes, but which kind of project have selected in the Wizard? there are many. Mus be console application.
0
 

Author Comment

by:BBrian
ID: 12106037
There are five tabs..

1.  .NET
2.  ALT
3.  MFC
4.  WIN32
5.  GENERAL

I most recently tried selecting general and then clicking on MakeProjectFile
but I also tried clicking on Win32 then clicking on Win32Console Project

I got the same error either way.

am I doing something wrong?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12106088
for a win32Console, there is an option that says 'Simple hello world application", choose it, compile and run it. If succefull, replace main function internals with your code.
0
 

Author Comment

by:BBrian
ID: 12106669
I don't see that option.
0
 

Expert Comment

by:axsaxs
ID: 12109979
Ok. First of all correct the code:

#include <iostream>
void main ( )
{
     std::cout <<"Hello World"<< std::endl;

    char c;
    std::cin >> c; // just press any key
}

In fact you are using the std namespace. IMHO, forget the "Simple hello world"... it's better to learn to code from scratch!

Check out the steps:

1. New C++ project
2. New Win32 console project
3. Finish
4. Paste the code
5. Wipe out "precompiled headers" (Project/Properties then C/C++/Precompiled Headers choose: Not using precompiled headers)
6. Run/debug program.
7. Press any key + enter to exit



0
 

Author Comment

by:BBrian
ID: 12114484
Hey Axsaxs it worked....

I had to remove this code though..


#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
      return 0;
}

and replace it with my hello world code...


if I leave both in i get this error

Linking...
Win32ConsoleProject.obj : error LNK2005: _main already defined in HelloWorld.obj
Debug/Win32ConsoleProject.exe : fatal error LNK1169: one or more multiply defined symbols found
0
 

Accepted Solution

by:
axsaxs earned 200 total points
ID: 12120571

That's because the "stdafx.h" is the include for the pre-compiled headers. It's not a bad thing to have pre-compiled headers (it can speed up things if your project grows large), but it is Microsoft-specific. So, I'd rather prefer not to have them. But, there are some techniques to have precompiled headers without the "stdafx.h", but that should be the answer to another question... ;)



0
 

Author Comment

by:BBrian
ID: 12124972
Thanks alot
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question