How can I create a basic C app in Visual Studio, be it 2010 Ultimate or 2008 Professional? I have searched through the project templates, and can find plenty for C++, but none for C.
(I'm hoping that the compiler and debugger will be built in.)
New project/Win32 Console Application/Empty project.
Add a file called "hello.c" (important that it's .c)
Type out a basic hello-world:
#include <stdio.h>
int main()
{
printf("Hello world\n");
return 0;
}
Compile, execute... PROFIT!
Visual Studio doesn't have a separate compiler for C, it uses the C++ compiler for C code. You can tell it to restrict itself to legal C syntax by using a compiler switch or by renaming the .cpp file to .c
Edit: I'm still using 2005 on this machine, so it might not be in the same place, but try this
Right click on the main.cpp in the solution explorer pane (on the right).
Choose Properties (bottom of the menu)
Open up the C/C++ group of properties
choose Advanced page
Change "Compile As" property to "Compile as C Code (/TC)"
In addition to changing the file extension, you may need to change the compiler settings:
Settintgs of Application->C/C++->addition->compiler such...
You must take /TC for basic C and /TP for C++.
https://msdn.microsoft.com/ru-ru/library/032xwy55.aspx
Good Luck.
Related
I am getting this results in the terminal.
gcc.exe: error in visual studio code.
How to fix this?
I was working well until now, don't know what happened.
If you want to add spaces to the name of your C/C++ files, you will then need to let the compiler know that this is a single file, this can be achived by using quotation marks around the file name:
gcc "If condition.c"
That said, it's not the best idea to have C/C++ files with spaces, you shouldn't do it.
Suggestion: rename If condition.c as If-condition.c or If_condition.c
I tried to compile on windows c program with tenserflow c api and tenserflow.dll from https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0.zip founded on https://www.tensorflow.org/install/lang_c.
This example:
#include <stdio.h>
#include <tensorflow/c/c_api.h>
int main() {
printf("Hello from TensorFlow C library version %s\n", TF_Version());
return 0;
}
Compiling is success, but when i have run it, i recieved a mistake that libtenserflow.so not found. Its look like that tensorfow,dll from https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0.zip was builded with some mistakes for windows sistem, becaurse libtensorflow.so is a target for Linux.
Can you explain or fix this?
I guess it looks for tensorflow.so because you were using GCC tools on VS Code's WSL mode (or other IDEs). But in order to load DLL you need to have Visual Studio.
Here's a simple process to run the Tensorflow for C demo:
Create a new project in Visual Studio;
Configure the project properties(assume the Tensorflow path is C:\tensorflow\; replace it with yours):
C/C++ > General > Additional Include Directories, add "C:\tensorflow\include\"
Debugging > Environment, add "PATH=C:\tensorflow\lib\;%PATH%"
Don't forget the "PATH=" before your tensorflow.dll path.
Compile and run.
You may also add the Tensorflow path to system environment (replace C:\tensorflow\ with your path):
SET PATH=%PATH%;C:\tensorflow\lib\
P.S. If you don't like the Visual Studio IDE and prefer to use Tensorflow with command line mode, try Bazel for Windows instead.
What is the best way to do this? The templates seem to allow only for C++ (which is basically compatible with C, but not the same.) What is the proper way to do this? (A particular #define or whatever.) Any help would be appreciated.
The solution is simple and easy
You create a new win32 console project
Remove the default .cpp file
Add new .c file as you wish
In Properties, under C/C++ --> All Options, find "Compile as", then select "Compile as C code"
Simple sanity check. This code doesn't work with C++ since "new" is a reserved word for C++.
int new = 10;
i have simple C source file created and compiled nicely on GNU gcc/cc. However when I wanted to compile in Visual Studio on Windows it gives me lots of errors. Is there any particular settings to set for VS compiler in order to compile nicely C source code.thanks
C source (standard style ?)
#include <..>
//function prototype
int main(){
// my code here
}
/* all my other functions below this */
Just found out I can use cl.exe . would try this first.
Do you know if it's possible to programm c (not c++) in Visual Studio 2008? If yes then how? I haven't found any component for that.
Regards.
Just save the file with .c extension instead of .cpp and it will compile as C instead of C++. To be extra cautious, you can go to the project settings, under "Project -> Properties -> Configuration Properties -> C/C++ -> Advanced", make sure that "Compile As" says "Compile as C code (/TC)".
As long as your source file has the .c extension, Microsoft C++ compiler will compile in C-mode.
In addition, the /Tc<source filename> 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.
You can specify any compiler you'd like in VisualStudio; therefore, if there's a specific C compiler you'd like to use, it will handle it.
If you want to make a .c program in Visual Studio 2008:
Goto>>File>>New>>Project
Choose "Visual C++" in the left column, then in the right column, select "Win 32 Console Application".
Write file name as:
"Any_Name.c"
Here you can now create a C program:
Create source file
To compile, press ctrl+shift+B
To run, press F5
It does not work because C++ precompiled headers, so the solution is select project-properties-c/c++-precompiled headers
Then select Not Using Precompiled Headers