compile c code in vs 2005 - c

Is there an easy way to compile c code in visual studio 2005? Its been a while(2-3 years) since I've done any coding in either c or c++, but I remember that you used to be able ti, in vs 2003, compile c code in visual studio. I thought it was just a matter of using an empty project(rather than, say a c++ project or a C# project) and giving your file s a *.c extension. However, doing that, I can't seem to figure out how to compile. I'm sure I'm just doing something stupid or missing something obvious.
Ah, really makes me appreciate eclipse's auto compile that much more, which is my normal IDE since I use java for work on the day to day basis.

You can start with a C++ project, and just delete the default .cpp files and make your own .c files.
The project defaults to compiling according to the file's extension.

If your original C code does not involve any GUI elements, you probably should create a console project. BTW, posting your error messages should make the problem clearer.

I thought it was just a matter of using an empty project ...
When you use the IDE to say you want to create a new project, you'll be asked to choose what kind of project: assuming that your software includes the main function (not WinMain) then you ought to say that you want to create a project for a "Console application".
After you've created this new project, add your existing *.c files (and *.h files) to the project, and delete the default *.c file which was created automatically with the project.

Related

LNK2005 and LNK1169 when trying to compile program in Visual Studio 2019

I have no experience with C/C++. I do not know how to even open files. I am working with SLN files in Visual Studio 2019 trying to compile a program I took off of GitHub (https://github.com/Marlowe97/Expected-Force).
I get these two errors (LNK2005, 'main already defined in TestExpectedForce.obj, and LNK1169 'one or more multiply defined symbols found') when trying to compile the Expected Force solution. The only changes I've made from the downloaded files are the ones directly stated in the instructions on the GitHub page of the program.
Is there someone who can tell me what to look for in as plain of a way as possible? I know basic Python and R so I understand some terms, but I know nothing about C so no other posted solutions to these errors make any sense to me. I'm already pretty concerned that I'm getting errors after following the step by step instructions from GitHub on what seemed to be a pretty basic task.
It's a strange package...
The functionality is provided as a library, to be compiled into your own project.
There are TWO test source files: TestExpectedForce.cpp and TestExpectedForce.cpp, each of them contains main().
They should be in their own projects (possibly, under the same solution).
To quickly move forward, just remove one of the test files from your solution.

How can I compile C files into an executable (.exe) file?

I am unsure about compiling C files into executables by using Cygwin under Windows 7.
Can anyone please tell me how to do this?
I've read some tutorials but still don't get it. I understand that I need a Makefile, but what shall I write into it to have an executable file after the compilation process?
For the beginning I would say it is enough to Install MinGW. If you have installed it you find in the bin folder a gcc.exe which is the Compiler. Either set the PATH Variable to the bin folder or go directly to this folder.
In terminal use:
gcc your_C_file.c
The output will be an exe.
There are several ways to compile c-files. Makefiles are just one possibility. But as you proposed it... Here are two tutorials for Makefiles:
http://makepp.sourceforge.net/1.19/makepp_tutorial.html
http://mrbook.org/tutorials/make/ (Content from 2012 accessable via waybackmachine)
But note, that you will also need a compiler (installed under cygwin).
Another possibility is to use Dev-C++, a IDE (Integrated Developement Environment) for C++. Once installed you can create a project and add your source code, and just compile the project. It also contains a c++ compiler (also supports C), which is named mingw. The makefile needed is automatically generated. So that's simpler for beginners.
You can download Dev-Cpp here: http://www.bloodshed.net/devcpp.html
Note: As you spoke about cygwin I assume you use Windows. Dev++ works only under windows, and you wont need cygwin.
Q: How can i compile c-files into an executable (.exe) file?
A: Get and use a C compiler.
GCC/Cygwin is one possibility. MS Visual Studio is another: you can download the free "MSVS Express" here: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express.
How you interact with the compiler is another question.
You can certainly use a command line.
You can use a command line with or without "Make": you can let "Makefiles" do the "heavy lifting" for you, you can use .bat files, or you can type everything by hand.
Using a graphical IDE is another possibility. "Eclipse" and "MS Visual Studio" are two popular alternatives for Windows.
Even easier solution is A86 Assembler. Its old school but works perfectly, in the right hands ;)

A .c file collection with their main() in NetBeans

I'm using NetBeans 7.0.1 to learn C.
I have done all the pre-requisites to start compiling in NetBeans so I'm ok with that.
I have done a "HelloWorld.c" with a main() in it and it runs fine. But then I made "Another.c" with its respective main(). I got an error which describes that I have already declared a main().
How can I have a .c files collection in the same project with their respective mains? I'm doing this because I require the learning of the language since I switched some roles at work.
Is there a way so NetBeans can handle all the .c without a project? Or should i try this in Visual Studio 2010?
The problem is that you can only have one main() per executable, but you're compiling the two files into on executable. When it links them it's spotting that the main() function exists in both of the files it's linking together and consequently reports this.
The solution is to make netbeans build you two, separate executables from each file. The easiest way to do this is to simply make two independent projects.
There is also a slightly messy way of making this work within a single netbeans project, but I wouldn't recommend it unless you have a compelling reason. The other workaround would be to write your own makefile to build two binaries, instead of using the netbeans managed one.

Keeping Visual Studio project files in sync with directory contents?

We have a large C project with development happening on Linux, Mac OS and Windows. Most of our Windows developers use MSVC -- for example, the free edition of Visual C. Oftentimes .c source files are added, renamed or deleted, and we find it very frustrating to keep the Visual C project in sync with these changes to directories.
Developer A might add newfile.c, check it in to Subversion and happily continue work.
Developers B, C, etc. update to the latest revision. Then when they compile in MSVC they get an error (buried somewhere in the huge compile output) saying the linker can't find such-and-such symbol. They then need to look to see what files have changed and manually add that to the project tree in MSVC.
(Developer A might be on Unix where build scripts tend to automatically find the right files to compile, and not realise how much work they've just created for B and C!)
My question is, is there a way to tell MSVC to consider every .c file in a directory as part of the project?
Update We have build scripts that can create initial MSVC project files. But there's a signicifant amount of customisation that gets done after this (pointing to libraries, etc.) which would be blown away each time the scripts were rerun merely to add a new file.
Given how many large projects there are out there, I'm kind of surprised Visual Studio requires such manual work by each developer just to pick up new files added by others.
I'm going to optimistically hold out for a better solution for now...
I don't think Visual Studio can do what you want (but would be glad if I'm proved wrong!).
What works for me is to use cross platform project files. Take a look at CMake, which allows you to define the structure of your project in a platform independent text based format. Then on each platform these project files are processed with a tool that then automatically generates the appropriate thing, which could be Makefiles, Visual Studio solution and project files, etc.
If this is really a serious problem, I would recommend writing a script which updates VS project file accordingly with directory contents.

Import C + Makefile into a linux IDE?

I have a project for Linux that i've been developing for some time. Basically it's a bunch of C and H files together with a directory structure and a Makefile.
Every time I need to debug something it's so painful, I need to manually search for var. definitions, structs, etc.
Is there any good IDE out there for Linux that will allow me to import those files into a "project" and that will provide code completion or at least an easy way to get my bearings in the source code?
thanks!
Eclipse with the CDT
CDT is pretty much Makefile based, just create an empty 'make' project then drop your files into it and refresh in eclipse then add your make targets.
Eclipse should pick stuff up from make output.
It depends on your definition of "good", but Emacs in connection with Cedet and AutocComplete does a good job in my opinion - but it's not too easy to get used to it.
Another IDE i've used (but not on Linux) is CodeBlocks.
There are several ways of going about this:
ctags: Most editors have ctags or etags support, which allows you to jump easily around in your source code. The tag file can be built by the makefile.
KDevelop: Version 4 is not bad, and is a more integrated IDE if standard text editors aren't your thing.
Eclipse with CDT: Eclipse is passable, and will work with C/C++ easily.
Emacs: Add CEDET (included in newer Emacs releases) for real code completion.

Resources