简体   繁体   English

如何在 Visual Studio (Mac) 中运行 C 程序

[英]How to run C program in Visual Studio (Mac)

so I am trying to run a C program for the first time using VS and Mac OS Catalina however I get the following error messages when trying to run:所以我第一次尝试使用 VS 和 Mac OS Catalina 运行 C 程序,但是在尝试运行时我收到以下错误消息:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/Users/xxx/Documents/EECS2031/scanf2.c).C/C++(1696)


cannot open source file "stdio.h"C/C++(1696)

I'm using the 'Code Runner' extension in VS to run the C code and I have also installed the following things using homebrew:我在 VS 中使用“Code Runner”扩展来运行 C 代码,我还使用自制软件安装了以下内容:

xcode-select --install
brew install gcc

I'm not sure what else to do as I am completely new to C, and haven't found any other solutions after searching so I need some help.我不知道还能做什么,因为我是 C 的新手,搜索后还没有找到任何其他解决方案,所以我需要一些帮助。 The c filename has a .c extension as well if that helps.如果有帮助,c 文件名也有一个 .c 扩展名。

Here is the C code:这是C代码:

#include <stdio.h>
/*The error is here when I am trying to include this library*/


int sum (int i, int j)
{
  return i+j;           
}


main()
{
  int a, b;
  printf("Please enter two integers separated by a blank: " );

  scanf( "%d %d",  &a, &b);     /* assign value to a b  */

  printf("Entered %d and %d. Sum is %d\n", a, b, sum(a,b));

  return 0;
}

Before trying to compile, the C environment (all the include headers, libraries, etc) has to be installed.在尝试编译之前,必须安装 C 环境(所有包含头文件、库等)。

this web page should be of great help to you:这个网页应该对你有很大帮助:

https://www.tutorialspoint.com/cprogramming/c_environment_setup.htm

especially the paragraph:尤其是这一段:

Installation on Mac OS

If you use Mac OS X, the easiest way to obtain GCC is to download the Xcode development environment from Apple's web site and follow the simple installation instructions. 
Once you have Xcode setup, you will be able to use GNU compiler for C/C++.

Xcode is currently available at 

developer.apple.com/technologies/tools/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM