Cannot compile a simple C program on Elementary distro - c

I'm using elementary OS 5.1.7 Hera (based on Ubuntu 18.04.4 LT) I created a very simple c program:
#include <stdio.h>
int main()
{
printf( "Hello World!\n" );
return 0;
}
and executing the following :
gcc -o simple simple.c
I get this error:
/usr/lib/gcc/x86_64-linux-gnu/7/cc1: error while loading shared libraries: libisl.so.19: cannot open shared object file: No such file or directory
Any suggestions?

I solved with these:
sudo apt-get remove libisl19
sudo apt update
sudo apt install build-essential

Related

How to fix the error "Python.h: No such file or directory"

I have a C file that I am trying to integrate Python into, but it returns this error "Python.h: No such file or directory". This is my file:
#define PY_SSIZE_T_CLEAN
#include <Python.h>
int main(int argl, char **argv)
{
return 0;
}
I also tried to use cmake, but it gives me the same error, this is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.18)
project(Test)
add_executable(main main.c)
find_package(PythonLibs REQUIRED)
include_directories(${Python_INCLUDE_DIRS})
target_link_libraries(main ${Python_LIBRARIES})
Output picture from the exec
You didn't tell us what operating system you are using. Debian (and Ubuntu) ships that header file in:
$ apt-file search /Python.h|grep h$
libpython2.7-dbg: /usr/include/python2.7_d/Python.h
libpython2.7-dev: /usr/include/python2.7/Python.h
libpython3.9-dbg: /usr/include/python3.9d/Python.h
libpython3.9-dev: /usr/include/python3.9/Python.h
...
and you would install that with:
$ sudo apt install libpython3.9-dev
You tagged this with c and not cmake, so the answer that you now need to include that directory with -I/usr/include/python3.9. On the Debian the best way to do that is using so you would include that as an argument to when compiling the file:
$ pkg-config -cflags python-3.9
-I/usr/include/python3.9 -I/usr/include/x86_64-linux-gnu/python3.9

How compile c code with python header file

I downloaded python source code using the command
git clone https://github.com/python/cpython
Now I created a main.c like so
#include <stdio.h>
#include <python.h>
int main(void)
{
return 0;
}
when I try to compile using this command
gcc main.c -L /f/<redacted>/cpython/Lib -I /f/<redacted>/cpython/Include -lpython
I get this error
$ gcc main.c -L /f/<redacted>/cpython/Lib -I /f/<redacted>/cpython/Include -lpython
In file included from main.c:2:
F:/<redacted>/cpython/Include/python.h:12:10: fatal error: pyconfig.h: No such file or directory
12 | #include "pyconfig.h"
| ^~~~~~~~~~~~
compilation terminated.
I know that pyconfig.h can be obtained using sudo apt install python-dev on Linux, so I tried pacman -S python-devel but this does not seem to fix the issue
I also tried to use locate pyconfig.h to link it using the -I but it is nowhere to be found
My machine is a windows 10 and I am using MSYS2withMINGW64 to compile this code

Go 1.8 plugins, fatal error: stddef.h: No such file

Observe:
$ cat /tmp/plugin.go
package main
import "fmt"
var V int
func F() { fmt.Printf("Hello, number %d\n", V) }
$ go build -buildmode=plugin -o /tmp/plugin.so /tmp/plugin.go
# runtime/cgo
cgo-builtin-prolog:1:57: fatal error: stddef.h: No such file or directory
compilation terminated.
Why is that?
This is under Ubuntu 17.04, and I have build-essentials installed:
$ go version
go version go1.9 linux/amd64
$ uname -r
4.10.0-37-generic
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 17.04
Release: 17.04
Codename: zesty
$ apt-cache policy build-essential
build-essential:
Installed: 12.1ubuntu2
Candidate: 12.1ubuntu2
please not the "Compilation error: "stddef.h: No such file or directory"" is NOT the answer as my gcc-core package and gcc-g++ are of the same version -- here are my gcc related packages:
gcc_4:6.3.0-2ubuntu1
gcc-6_6.3.0-12ubuntu2
gcc-6-base:amd64_6.3.0-12ubuntu2
libgcc-6-dev:amd64_6.3.0-12ubuntu2
libgcc1:amd64_1:6.3.0-12ubuntu2
UPDATE:
thanks #peterSO, seems to be my gcc's own problem:
$ cat /tmp/foo.c
#include <stdio.h>
$ gcc /tmp/foo.c
In file included from /tmp/foo.c:1:0:
/usr/include/stdio.h:33:21: fatal error: stddef.h: No such file or directory
# include <stddef.h>
While searching for solution for it, I found someone suggested to reinstall gcc, so I did, together with libc6-dev:
apt-get --reinstall install libgcc-6-dev gcc-6 gcc-6-base:amd64 libc6-dev:amd64
Now my simple .c file compiles OK now, but I'm bumped into a new problem with cgo:
$ go build -buildmode=plugin -o /tmp/plugin.so /tmp/plugin.go
# runtime/cgo
In file included from /usr/include/errno.h:35:0,
from cgo-gcc-prolog:21:
/usr/include/x86_64-linux-gnu/bits/errno.h:24:26: fatal error: linux/errno.h: No such file or directory
# include <linux/errno.h>
^
compilation terminated.
I know this might be a Ubuntu/gcc specific problem (Ref: Why is stddef.h not in /usr/include? and my stddef.h is under /usr/src/linux-headers-4.10.0-37/include/linux/stddef.h), but anybody here knows Go and gcc good enough to know how to fix it, so that Go plugins can be compiled properly?
Thx!

Cross-compiled library not found by toolchain

I'm new to developing for embedded systems, but I have installed arm-linux-gnueabi-gcc via the Linux Mint package manager and managed to build a few programs successfully.
I'm currently struggling with getting a program to compile using libusb. I've done the following:
Downloaded and unpacked the libusb 1.0.20 sources from https://sourceforge.net/projects/libusb/.
Compiled and installed them using the following commands:
~/Downloads/libusb-1.0.20 $ ./configure --host=arm-linux-gnueabi --prefix=/opt/ --disable-udev
~/Downloads/libusb-1.0.20 $ sudo make
~/Downloads/libusb-1.0.20 $ sudo make install
(The reason for sudo-ing the make commands was because I encountered permission problems related to removing old files.)
Copied a small sample file from somewhere on the internet:
#include <libusb-1.0/libusb.h>
#include <stdio.h>
int main()
{
int i=0;
libusb_context **c = NULL;
i = libusb_init(c);
printf("\nusing libusb.h\n");
return 0;
}
Tried to build it and run it with gcc:
~/Desktop/libtest $ gcc libtest1.c -o libtest1 -lusb-1.0
~/Desktop/libtest $ ./libtest1
using libusb.h
However, when I try to do the same with arm-linux-gnueabi-gcc, it can't find the library:
~/Desktop/libtest $ arm-linux-gnueabi-gcc libtest1.c -o libtest1 -lusb-1.0
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find -lusb-1.0
collect2: error: ld returned 1 exit status
Where did I go wrong? Is there something else I need to do in order to use the library? Did I fail at compiling the library for the arm compiler? I didn't include the compiler output here since it's quite long, but there are no obvious errors. This might be a very stupid question, but I'm completely clueless.

C code won't compile in mac Terminal.

Whenever I run $ /developer/usr/bin/gcc -v main.c -o main in Terminal, I get the following error: stdio.h: No such file or directory.
Here is the main.c file
#include <stdio.h>
int main(void){
int i;
for(i = 0; i<10;i++){
puts("Hello World!\n");
}
return 0;
}
I am pretty good with C, however I usually use xcode to compile any C command line programs. The same code runs fine in Xcode, what am I doing wrong?
I had the same problem and fixed it. Just install xCode's command line tools and it'll all work just fine!
Hope it helps! :)
You can install xcode tools with the command -
xcode-select --install
A fresh install of xcode command line tools will require 130MB of space and does require sudo access.

Resources