- Compile C Code In Visual Studio 2008
- C Programming With Visual Studio
- Compiling C Program In Visual Studio 2008 Download
In my copious amount of free time I've been messing around with network analysis and security. I've always been generally interested in networking technology, but have never really had much practical exposure to it. Sometimes, however, it is nice to be able to analyze a network and see what kind of information is actually coming across the wire. In my last article I mentioned a tool called WireShark which is a free, open source network analyzer aka packet sniffer.
WireShark is a great tool and has its own set of extension points, but I wanted lower level access to the packets being captured. My understanding of the politics and genesis is lacking, but it seems like the WinPCap library is the Windows version of the libpcap packet capture library from the *NIX world. Naturally, WinPCap is coded in C and even though I have some background in it, the tool I am looking to develop requires a lot of UI work. Instead of stepping back into the land of MFC/Win32, I tried to locate a Managed version of WinPCap. The closest thing I could find was this Ancient Project on CodeProject.com. It hasn't been updated since 2003 and isn't a 'fully' managed wrapper (also, the source code in the download is just to the example, not the wrapper).
I figured, 'If this guy can do PInvoke, so can I'. Thus, I downloaded the WinPCap developer pack and attempted to open the example solution in Visual Studio 2008. Visual Studio 2008 alerted me to the fact that I had to upgrade the project (which was actually a VS 6.0 .dsw file) and I happily agreed. The upgrade went smooth so I attempted to compile the solution, but received the following error:
C programming in Visual Studio 2008. As long as your source file has the.c extension, Microsoft C++ compiler will compile in C-mode. In addition, the /Tc switch can be used to force compilation of a specific file in C mode, and the /TC switch can be used to force C mode for all files. For C++, it's /Tp and /TP respectively. Install Visual Studio 2008. If you do not have Visual Studio 2008, you can download Visual Express 2008 for free from Microsoft. This download comes with SP1 so you do not need the information below in that case. Upgrade to Service Pack 1. If you installed VS2008 before August 2008 it will probably need updating to SP1.
'error C3163: '_vsnprintf': attributes inconsistent with previous declaration c:program filesMicrosoft visual studio 9.0vcincludestdio.h 358 savedump'
Crap. Apparently this is a common problem when compiling older C++ code with the Visual Studio 2008 C++ compiler. Now, I didn't find a solution for this on the net specific to WinPCap, but several forum posts across other projects lead me to the following solution.
Ok so i have some code that works perfectly with visual studio 2003, but when i move it into my project which is using visual studio 2008, the compiler spits out 9 errors. Visual Studio comes with its own C compiler, which is actually the C++ compiler. Just use the.c file extension to save your source code. You don't have to be using the IDE to compile C. 4) when i tried to include in program,it gave an error,while i looked up in directory,iostraem.h is present in the VC directory in C drive.why so? I am reproducing the code below // FIRST.cpp: Defines the entry point for the console application.
First, find the pcap-stdinc.h file on your system. It should be located in: '..WpdPack_4_0_2WpdPackInclude'
Next, locate the following code near the bottom of your header:
The problem, as we can tell from the compiler error, is that the '#define vsnprintf _vsnprintf' causes some incompatibilities with what is already in stdio.h. Modify your code to the following and save the header:
You should now be able to compile all the examples in the solution!
All that we've done is check the version of the compiler at compile time. If the version is prior to MSC++ 9.0 then we go ahead and do the #define. Otherwise, we don't do the #define and rely on what is in stdio.h.
This solution is general in nature, i.e. anything that defines _vsnprintf may exhibit this issue, but specific in the sense that the exact location of the code to modify will vary by project. In the case of WinPCap, everything is groovy at this point. Now I just need to learn everything I can about PInvoke : )
Posted on Wednesday, January 30, 2008 10:52 AM General .NET | Back to topActive10 years, 1 month ago
I have visual studio 2008. I have a written a small C program. I want to compile that C file in command prompt. How do i do that ? please point me to a place where i can learn more about working with projects without visual studio.
avakar27.4k55 gold badges5555 silver badges9595 bronze badges
AnandAnand5,2412323 gold badges8282 silver badges131131 bronze badges
6 Answers
If you have Visual Studio, you also have the command line C compiler, which Visual Studio invokes when it builds your project. So you just have to invoke it from the command line.
You can also download a C compiler for free, there are a lot of options available, such as http://gcc.gnu.org/releases.html, or see http://www.thefreecountry.com/compilers/cpp.shtml
If we assume you are using the Microsoft C/C++ Compiler (cl.exe which will be in the VC subdirectory of your Visual Studio installation), open the Visual Studio command prompt (it will have appropiate paths set). In order to compile a file called 'helloworld.c', type: Installer via hd audio deck for windows 8.1 download.
For more information, see the MSDN docs.
driisdriis127k4141 gold badges246246 silver badges325325 bronze badges
run above code in command prompt (visual studio 2010, editor: notepad.exe recommend)
c:temp> cl.exe hello.c
plan9assemblerplan9assembler
If you're talking about not using the IDE GUI, an alternative is to set up a project for your C file as you normall would and call devenv.com to compile that project. It will then pass all the required paths and settings to the compiler and linker. We use that to compile some projects on our build servers. To learn more, type 'devenv.com /?'.
Regards,
Sebastiaan
Sebastiaan MSebastiaan M4,57511 gold badge2323 silver badges2828 bronze badges
Read more about that here:http://msdn.microsoft.com/en-us/library/ms235639(VS.80).aspx
MSDN is a great source for more information.
ZyphraxZyphrax13.9k99 gold badges5757 silver badges8080 bronze badges
Lots of options out there. As mentioned by driis, there are lots of free c compilers available to download.
If you just want to compile code on a machine that has visual studio on it, microsoft offers several tools that allow command line use and project management:
- Invoke the ide from the command line. You can use devenv.exe.
- Use cl.exe directly (this is the c/c++ compiler and linker.
- Microsoft offer a make tool (similar to the unix one) called NMake. Use this with makefiles for project management, in conjunction with cl.exe.
Microsoft have reference documents for command line building.
Another options is MonoDevelop - an open source ide that understand visual studio project files.
OdedCompile C Code In Visual Studio 2008
Oded423k7878 gold badges776776 silver badges932932 bronze badges
Compiling the 'c' file from command line is easy and you have many answers to start with. However working with projects is a different thing and you will need to have a tool that will do it. Microsoft nmake was mentioned before, but i will suggest using gnu make utility that used for managing build. It is compiler independent, old (meaning proven) and very flexible tools that will allow you to create very robust build environment.
IlyaIlyaC Programming With Visual Studio
2,65822 gold badges1919 silver badges2727 bronze badges