Problems with Compiling C program on Ubuntu - c

I am using Ubuntu 10.10 as VM and am new to it. Until recently i could easily compile C programs from the terminal. However, as i try to compile them now it gives a message as:
/usr/bin/ld: cannot find -lc
collect2: ld returned 1 exit status
I have searched for it over the net but could not figure out what is going wrong. I know the answer to it must be simple but any help would be appreciated. Thanks!

Installing the necessary tools should solve your problem. Try:
sudo apt-get install build-essential

You probably -- most of us do -- installed Ubuntu desktop, but not Ubuntu server. A whole lot of tools don't come over with a default Ubuntu desktop installation.
So start by installing build-essential:
sudo apt-get install -y build-essential
Then try the compile again. build-essential contains a bunch of components that you need to perform a basic compile.
For my work, beyond build-essential, I have to install other libraries like curses. However, I first have to have build-essential installed before I can do anything else.

Related

How can I run GCC into WSL?

So, Windows System on Linux seems to be an inovative light-weight substitute for a virtual machine, especially when it comes to learning Linux. Nevertheless, for me WSL seems to have a little more complicated organization from a VM when it comes to file management. For example, in WSL the data are stored in
C:\Users\<username>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\rootfs\usr\
as shown here.
Of course my first try to install GCC was to type in:
sudo apt install gcc
,but after typing
gcc --version
the output was :
Command 'gcc' not found, but can be installed with:
sudo apt install gcc
After that, I tried installing GCC using the following commands as shown here :
$ sudo apt-get update && sudo apt-get upgrade -y
$ sudo apt autoremove -y
$ sudo apt-get install gcc -y
but I end up getting the same output.
On the other hand, I already had installed TDM GCC on Windows and used sudo in VM to install it also there (successfully:).
Like a lot of people, I want to substitute the use of my virtual machine with WSL in order to be able to develop in C without overloading my RAM my questions are :
Can you count out for me how many times have I downloaded GCC files?
Why the folder that I was supposed to be downloading the gcc files in is shown to be empty?
Where are the downloaded files being stored?
How can get gcc fired up?
Is there any way to use the gcc I had on Windows to compile C using the WSL terminal?
I think these questions come from the fact that I cannot understand how WSL file system interacts with Windows. They are a bit more generic on purpose because I want you to have a lot of "answering" freedom.
Please help me out of this one! I don't want to be forced to use a virtual machine and run out of RAM almost every time!

Install OpenMPI on Ubuntu 17.10

I am using the following command for OpenMPI installation on Ubuntu 17.10:
sudo apt-get install openmpi-bin openmpi-common openssh-client openssh-server libopenmpi1.3 libopenmpi-dbg libopenmpi-dev.
However, I get the following error:
E: Unable to locate package libopenmpi1.3
I wanted to know how to fix this. Alternatively,I am open to installing openmpi differently if anyone knows another way of doing it.
apt-get install libopenmpi1.10 would work.

Install arm-poky-linux-gnueabi toolchain on PC

There are 2 compilers used in IMX7(ARM Yocto Linux):
arm-poky-linux-gnueabi-gcc
arm-poky-linux-gnueabi-g++
When I build complete image by spending about 2 hours its already downloaded.
But I would like to know how to install this tool chain directly on PC(Ubuntu/CentOS) and use it as separate compiler in PC instead of with its Image as I mentioned above.
Use below command in your ubuntu pc
$ sudo apt-get install gcc-arm-linux-gnueabihf
$ sudo apt-get install g++-arm-linux-gnueabihf

How to install cjson properly in Ubuntu 14.0LTS?

I am new in json and I don't know how to use but I found compare to XML json is better so, I am learning json in C programming in Ubuntu 14.0LTS.
I followed https://linuxprograms.wordpress.com/2010/05/20/install-json-c-in-linux/.
In this link, I installed libjson0 with the help of first command but when I installed libjson – debug symbols package with the help of second command which is mentioned in link then showing "E: Unable to locate package libjson0-dbg".
Also I gone through https://github.com/json-c/json-c. After cloning moved to json-c directory, in json-c directory I did sh autogen.sh then showing "autogen.sh: 2: autogen.sh: autoreconf: not found".
Why autoreconf is not works ? When I installed CppUTest and other stuffs then it works.
I also install build-essential which found in google for above problems but it can't works for me.
How can I installed cjson in a proper manner and how to use with the C-programms.
Try below commands:
$ sudo apt-get install libjson-glib-1.0-0 libjson-glib-1.0-0-dev
If you want to debug your programs and see the various steps of serializing/deserializing you can also install the libjson-glib – debug symbols package
$ sudo apt-get install libjson-glib-1.0-0-dbg
For documentation related to json-glib, you must install the following package
$ sudo apt-get install libjson-glib-1.0-0-doc
This documentation will then be available in file:///usr/share/gtk-doc/html/json-glib/index.html
Maybe your problem is related with the path.
The library is installed correctlly but you have tot tell the system where. Here a post on how to do it in Ubuntu How to set the environmental variable LD_LIBRARY_PATH in linux

GCC fatal error: stdio.h: No such file or directory

I'm trying to compile a program in C on OS X 10.9 with GCC 4.9 (experimental). For some reason, I'm getting the following error at compile time:
gcc: fatal error: stdio.h: No such file or directory
I then tried a simple Hello World program:
#include <stdio.h>
int main(int argc, const char *argv[])
{
printf("Hello, world!");
return 0;
}
Again, upon running gcc -o ~/hello ~/hello.c, I got the same error. I'm using an experimental version of gcc, but it seems implausible that there would be a release which generated errors upon importing stdio. What could be causing this issue, and how can it be fixed?
macOS
I had this problem too (encountered through Macports compilers). Previous versions of Xcode would let you install command line tools through xcode/Preferences, but xcode5 doesn't give a command line tools option in the GUI, that so I assumed it was automatically included now. Try running this command:
xcode-select --install
If you see an error message that developer tools are already installed (and still header files can't be found), wipe out any existing one to do a fresh installation:
sudo rm -rf /Library/Developer/CommandLineTools
Ubuntu
(as per this answer)
sudo apt-get install libc6-dev
Alpine Linux
(as per this comment)
apk add libc-dev
Mac OS Mojave
The accepted answer no longer works. When running the command xcode-select --install it tells you to use "Software Update" to install updates.
In this link is the updated method:
Open a Terminal and then:
cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg
This will open an installation Wizard.
Update 12/2019
After updating to Mojave 10.15.1 it seems that using xcode-select --install works as intended.
ubuntu users:
sudo apt-get install libc6-dev
specially ruby developers that have problem installing gem install json -v '1.8.2' on their VMs
I know my case is rare, but I'll still add it here for someone who troubleshoots it later.
I had a Linux Kernel module target in my Makefile and I tried to compile my user space program together with the kernel module that doesn't have stdio.
Making it a separate target solved the problem.
I had the same problem. I installed "XCode: development tools" from the app store and it fixed the problem for me.
I think this link will help:
https://itunes.apple.com/us/app/xcode/id497799835?mt=12&ls=1
Credit to Yann Ramin for his advice. I think there is a better solution with links, but this was easy and fast.
Good luck!

Resources