How compile c code with python header file - c

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

Related

PBC libraries implementation

I am trying to implement a cryptography code and for that I need to include the pbc libraries into my code the basic code is as follows
#include "pbc.h"
int main(void)
{
/* call PBC functions */
return 0;
printf("it's there");
}
and I am working in ubuntu environment and after installing the pbc and gmu I am using this command
gcc -o foo foo.c -I home/Mtech/Desktop/Alok/pbc-0.5.14/include/pbc/ -L home/Mtech/Desktop/Alok/pbc-0.5.14/include/ -l pbc
but the system shows me the following error
:~/Desktop/Alok$ gcc -o foo foo.c -I home/Mtech/Desktop/Alok/pbc-0.5.14/include/pbc/ -L home/Mtech/Desktop/Alok/pbc-0.5.14/include/ -l pbc
foo.c:1:17: fatal error: pbc.h: No such file or directory
`enter code here`compilation terminated.
install gmp library first
sudo apt-get install libgmp3-dev
install pbc library,pbc uses gmp library
[download]: https://crypto.stanford.edu/pbc/download.html "follow guide for installation"
for compiling
gcc <program_name>.c -lgmp -lpbc
for c++
g++ <program_name>.cpp -lgmp -lgmpxx -lpbc
run
./a.out

How fix Error of error of crt1.o,crti.o in Build TinyCCompiler(TCC) from Source?

How fix Error of crt1.o,crti.o in Build TinyCCompiler(TCC) from Source?
https://github.com/LuaDist/tcc
i'm test this at my Desktop system(ubuntu) and also test on server(centos).
at both OS , show error.
Error :
tcc: file '/usr/lib/crt1.o' not found
tcc: file '/usr/lib/crti.o' not found
Details :
guest#Base:~/Gits/tcc-compiler$ ./configure --prefix=build
Binary directory build/bin
TinyCC directory build/lib/tcc
Library directory build/lib
Include directory build/include
Manual directory build/man
Doc directory build/share/doc/tcc
Target root prefix
Source path /home/guest/Gits/tcc-compiler
C compiler gcc
CPU x86-64
Big Endian no
gprof enabled no
cross compilers no
use libgcc no
Creating config.mak and config.h
config.h is unchanged
guest#Base:~/Gits/tcc-compiler$ sudo make
....
....
guest#Base:~/Gits/tcc-compiler$ sudo make install
mkdir -p "build/bin"
install -s -m755 tcc "build/bin"
mkdir -p "build/man/man1"
install tcc.1 "build/man/man1"
mkdir -p "build/lib/tcc"
mkdir -p "build/lib/tcc/include"
install -m644 libtcc1.a "build/lib/tcc"
install -m644 include/stdarg.h include/stddef.h include/stdbool.h include/float.h include/varargs.h include/tcclib.h "build/lib/tcc/include"
mkdir -p "build/share/doc/tcc"
install -m644 tcc-doc.html "build/share/doc/tcc"
mkdir -p "build/lib"
install -m644 libtcc.a "build/lib"
mkdir -p "build/include"
install -m644 libtcc.h "build/include"
guest#Base:~/Gits/tcc-compiler$ cat test2.c
#include <tcclib.h>
int main()
{
printf("Hello World\n");
return 0;
}
Error :
guest#Base:~/Gits/tcc-compiler$ build/bin/tcc test2.c
tcc: file '/usr/lib/crt1.o' not found
tcc: file '/usr/lib/crti.o' not found
$ find /usr/ -name crti*
/usr/mipsel-linux-gnu/lib/crti.o
/usr/lib32/crti.o
/usr/libx32/crti.o
/usr/lib/i386-linux-gnu/crti.o
/usr/lib/x86_64-linux-gnu/crti.o
$ find /usr/ -name crt1*
/usr/mipsel-linux-gnu/lib/crt1.o
/usr/lib32/crt1.o
/usr/libx32/crt1.o
/usr/x86_64-w64-mingw32/lib/crt1.o
/usr/x86_64-w64-mingw32/lib/crt1u.o
/usr/i686-w64-mingw32/lib/crt1.o
/usr/i686-w64-mingw32/lib/crt1u.o
/usr/lib/i386-linux-gnu/crt1.o
/usr/lib/x86_64-linux-gnu/crt1.o
(Full Commands available at https://pastebin.ubuntu.com/26211506/)
how can fix error?
i'm can install tcc using sudo apt install tcc.(without bug and error)
but i want install tcc from source.(this have error)
New Update
in tcc.h file :
#define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr/lib"
i'm change /usr/lib to /usr/lib/x86_64-linux-gnu.
$ build/bin/tcc test.c -run
Hello World
$ /build/bin/tcc test.c
tcc: undefined symbol '__libc_csu_fini'
tcc: undefined symbol '__libc_csu_init'
tcc: undefined symbol '__libc_start_main'
tcc: undefined symbol 'printf'
New Update
#include <tcclib.h>
int main()
{
printf("Hello World\n");
return 0;
}
guest#Base:~/Gits/tcc-try/_build/_install/bin$ ./tcc test.c
test.c:1: include file 'tcclib.h' not found
How fix error of include files not found?!
Related Question : How fix Error of error of include files in TinyCCompiler(TCC)?
The LuaDist project aims to build a complete Lua ecosystem using CMake. So you should use the CMake build system instead of the original makefiles. Typically you would do the following CMake invocation.
$ mkdir _build && cd _build
$ cmake .. -DCMAKE_INSTALL_PREFIX=_install
$ cmake --build . --target install
After this you should have working tcc in _install/bin
Sorry this is not exactly an answer to a question, but initially I had the same problem and this is my solution (Ubuntu 18.04):
git clone https://github.com/TinyCC/tinycc
cd tinycc
./configure
make
make test
cd ..
echo '#include <stdio.h>
int main() {
printf("Hi!\n");
}' > a.c
tinycc/tcc -Btinycc a.c -o a.o
./a.o

MOTIF compiling error / X11/intrinsic.h missing

i have MOTIF installed X11
a easy program is saved as hello.c
there is the following message
where can i get the X11/intrinsic.h , file ???
need help to compile
my system : MX-16 Linux Debian Jessie / i386
Code:
hans#mx1:~/Documents
$ cc push.c -o push -lXm -lXt -lX11
In file included from push.c:2:0:
/usr/include/Xm/Xm.h:59:27: fatal error: X11/Intrinsic.h: No such file or directory
#include <X11/Intrinsic.h>
^
compilation terminated.
hans#mx1:~/Documents
I installed the libxt-dev package on my Debian box:
apt-get install libxt-dev
Then the proper header will be installed:
# find /usr -name "Intrinsic.h" -print
/usr/include/X11/Intrinsic.h
Been using xv for several decades now -- I always find myself trying to rebuild it.
The copy on my system came from libxt-dev
$ locate Intrinsic
/usr/include/X11/Intrinsic.h
/usr/include/X11/IntrinsicI.h
/usr/include/X11/IntrinsicP.h
$ dpkg-query -S /usr/include/X11/Intrinsic.h
libxt-dev:amd64: /usr/include/X11/Intrinsic.h
You may want to install and use apt-file - you can ask it for a filename and it will tell you which packages (that you don't even have to have installed - just from the repos in your sources.lists) contain a file with that name

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.

Why do I keep getting "Killed: 9" when I run this very basic SQLite3 based C file?

I have this super basic C file:
#include <sqlite3.h>
#include <stdio.h>
int main(void) {
printf("%s\n", sqlite3_libversion());
return 0;
}
And in the same directory I have sqlite3.h, sqlite3.c and sqlite3ext.h downloaded from the downloads page on sqlite.org.
I then run gcc -c main.c. Then chmod +x main.o. Then ./main.o. And every time I get:
Killed: 9
What am I doing wrong?
You cannot execute a relocatable object file directly like that. Try this:
gcc main.c -o main -lsqlite3
This works on Ubuntu with libsqlite3-dev package installed. Running main results in:
3.8.2
The -o flag specifies the name of the executable file. If you ommit -o main, you'll get a file called a.out with gcc on most platforms (maybe a.exe on windows+cygwin?). Either way, this file will already be executable, so you can skip the chmod +x.
The -lsqlite3 flag tells the compiler to link in the sqlite3 library too.
If you've built sqlite3 from scratch, you may also need -I and -L flags to tell the compiler where to look for libraries and headers.
In your command, the "-c" flag skips the linking stage and produces a relocatable object, where otherwise, gcc will produce an executable file.
You can use readelf -h main.o using output of your original command and readelf -h main using output of my suggested command, or alternatively just file main.o and file main to see differences in file types.

Resources