无法在 Linux Mint 15 中编译简单的 c 程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19500018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to compile simple c program in Linux Mint 15
提问by namco
I am a Linux Mint 15 User.
i wanted to write simple program in C.
Below is my code.(hw.c)
我是 Linux Mint 15 用户。
我想用 C 写一个简单的程序。
下面是我的代码。(hw.c)
#include<stdio.h>
#include<conio.h>
int main()
{
printf("Hello World");
}
But, when i try to compile it with gcc
但是,当我尝试用 gcc 编译它时
gcc -o hw hw.c
it gives me an error
它给了我一个错误
hw.c:1:18: fatal error: stdio.h: No such file or directory
compilation terminated.
I googled and found some solutions which say to install build-essential
and tried to install it
我用谷歌搜索并找到了一些说要安装build-essential
并尝试安装它的 解决方案
sudo apt-get install build-essintial
but it gives an error again. The error is
但它再次出错。错误是
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
build-essential : Depends: libc6-dev but it is not going to be installed or
libc-dev
Depends: g++ (>= 4:4.4.3) but it is not going to be installed
Depends: dpkg-dev (>= 1.13.5) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
So what is wrong? What is the problem?
How to solve it?
那么有什么问题呢?问题是什么?
如何解决?
PS.
The result of locate stdio.h
is
附注。结果locate stdio.h
是
/usr/lib/perl/5.14.2/CORE/nostdio.h
/usr/lib/syslinux/com32/include/stdio.h
回答by david
I was having the same problem, and simply installed the g++ package and that fixed the missing include file.
我遇到了同样的问题,只是安装了 g++ 包并修复了丢失的包含文件。
sudo apt-get install g++
sudo apt-get install g++
回答by догонят
I had this situation before:
我之前有过这样的情况:
rleclerc@fvrwbp01:~# gcc -o tokens tokens.c
tokens.c:1:19: fatal error: stdio.h: No such file or directory
compilation terminated.
You wrote:
你写了:
sudo apt-get install build-essintial
There's a typo. Try this instead (I guess you already did something similar):
有一个错字。试试这个(我猜你已经做了类似的事情):
sudo apt-get install --no-install-recommends gcc
and:
和:
sudo apt-get install --no-install-recommends build-essential
Sometimes, proof-reading makes some difference:
有时,校对会产生一些影响:
The following NEW packages will be installed:
build-essential dpkg-dev g++ g++-4.7 libc-dev-bin libc6-dev libdpkg-perl libstdc++6-4.7-dev libtimedate-perl linux-libc-dev make
(...)
This fixed the error.
这修复了错误。
回答by Mike Gleason
FWIW, Mint 17 just needs build-essential to compile C programs:
FWIW,Mint 17 只需要 build-essential 来编译 C 程序:
# apt-get install build-essential
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
dpkg-dev g++ g++-4.8 libc-dev-bin libc6-dev libstdc++-4.8-dev
Suggested packages:
debian-keyring g++-multilib g++-4.8-multilib gcc-4.8-doc libstdc++6-4.8-dbg
glibc-doc libstdc++-4.8-doc
Recommended packages:
libalgorithm-merge-perl
The following NEW packages will be installed:
build-essential dpkg-dev g++ g++-4.8 libc-dev-bin libc6-dev
libstdc++-4.8-dev
0 upgraded, 7 newly installed, 0 to remove and 1 not upgraded.
回答by user2229691
The package name for the C standard library is libc6
. Its header files are in the development package: libc6-dev
. Some Linux distributions do not have the development package installed. You need to install it yourself:
C 标准库的包名是libc6
. 它的头文件在开发包中:libc6-dev
. 某些 Linux 发行版没有安装开发包。你需要自己安装:
sudo apt-get install libc6-dev
Why the installation of build-essentials
does not resolve the dependencies I don't know. But I think the question wasn't about the installation of build-essentials
and maybe it isn't needed at all.
为什么安装build-essentials
不能解决我不知道的依赖项。但我认为问题不在于安装,build-essentials
也许根本不需要它。
References:
参考:
回答by Krishna Chalise
This problem may come when you are trying from wrong directory...
当您从错误的目录尝试时可能会出现此问题...
I suggest you to check for directory.
Update the OS by: sudo apt-get update.
The final option is to remove the exixting gcc compiler and install the new one.
我建议你检查目录。
通过以下方式更新操作系统:sudo apt-get update。
最后一个选项是删除现有的 gcc 编译器并安装新的。
You can also try this:
你也可以试试这个:
g++ -o [fileName] [executable name]
g++ -o [文件名] [可执行文件名]