Qemu can't boot custom operating system [duplicate] - c

I followed this article on how to make a very simple kernel which prints "Hello, World". The files to my project are available on Github.
I built my cross compiler from this project. I use these command to cross compile, assemble, and build my ISO (CD-ROM image):
i686-elf-as boot.s -o boot.o
i686-elf-gcc -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
i686-elf-gcc -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc
mkdir -p isodir/boot/grub
cp myos.bin isodir/boot/myos.bin
cp grub.cfg isodir/boot/grub/grub.cfg
grub-mkrescue -o myos.iso isodir
When I tried to execute it on VirtualBox, it gives the following message:
FATAL: No bootable medium found! System halted.
Why am I getting this error, and how can I fix it?
P.S. I use Ubuntu subsystem for Windows 10

Likely there is a GRUB component missing or an incorrect version of Xorriso. In the Bare Bones article you linked to it says this:
You can easily create a bootable CD-ROM image containing the GRUB bootloader and your kernel using the program grub-mkrescue. You may need to install the GRUB utility programs and the program xorriso (version 0.5.6 or higher).
When using grub-mkrescue to make ISO images, more often than not unbootable ISOs is a result of Xorisso installation missing. If grub-mkrescue runs but doesn't produce ISOs at all then likely a GRUB component is missing. To ensure that you have all the GRUB and Xorriso components installed install the components on modern Ubuntu releases with:
sudo apt-get install grub2-common grub-pc xorriso
Then attempt to rebuild and rerun your ISO image in VirtualBox.

Related

Emscripten compilation error: "'openssl/sha.h' file not found"

I have a file called "speed.c" which I wish to use for a web program
This works:
gcc speed.c -lcrypto -lssl
But this doesn't:
emcc speed.c -v -lcrypto -lssl -s EXPORTED_FUNCTIONS=_speed,_main -o speed.wasm
The function within speed.c is called "speed".
On the website for Emscripten, it says that the compiler is just like any other so this one confuses me.
Any help? Thanks!
Emscripten can't use you system's libraries. This is because they are binaries compiled for your own machine (probably 64-bit linux), while emcc compiles to WebAssembly/JavaScript. You can generally see what architecture a binary is targeting with file:
$ file `realpath /usr/lib/libssl.so`
Thus, you will need to first compile OpenSSL with emcc. I haven't done this myself, but I believe it's possible. You could check out this github issue.
Once you've done that you should have two files name libssl.a and libcrypto.a. Then you can compile your own project like this:
$ SSL=/path/to/openssl
$ emcc speed.c $SSL/libssl.a $SSL/libcrypto.a -I $SSL/include/ # etc.
Take a look at the project building page if you haven't yet.

Dynamic linking libgit2 .so in gcc

I'm running a Debian (Buster) container and my goal is to compile a small program I wrote which relies on libgit2. First, I was installing libgit2 via the libgit2-dev package and my Makefile had the following:
gcc -O2 -fpic -shared -I /usr/local/include -lgit2 -o output.so my_app.c
However, I'd rather have a "cleaner" environment and install libgit2 via the libgit-27 which, AFAIK, only installs the shared object binary instead of also including the development files like libgit2-dev does.
Using find I can find where the .so file is installed into:
$ find / -name "*git2*" -print 2>/dev/null
/usr/lib/x86_64-linux-gnu/libgit2.so.0.27.7
/usr/lib/x86_64-linux-gnu/libgit2.so.27
/usr/share/doc/libgit2-27
/var/lib/dpkg/info/libgit2-27:amd64.list
/var/lib/dpkg/info/libgit2-27:amd64.symbols
/var/lib/dpkg/info/libgit2-27:amd64.md5sums
/var/lib/dpkg/info/libgit2-27:amd64.shlibs
/var/lib/dpkg/info/libgit2-27:amd64.triggers
and I've been trying several combinations of linking this .so with gcc like:
gcc -O2 -fpic -shared -L /usr/lib/x86_64-linux-gnu/ -libgit2.so.27 -o output.so my_app.c
but so far I always get the following error:
my_app.c:1:10: fatal error: git2.h: No such file or directory
#include <git2.h>
^~~~~~~~
compilation terminated.
I understand this is a glaring lack of knowledge on how C compilation works. My two questions are:
Is it possible to compile my program by just relying on the libgit2-27 Debian Buster package instead of libgit2-dev? If not, why?
If yes, an example and explanation would be appreciated!

How to make the php extension(.so) file portable with dependent libraries?

I need to make an php extension(.so) file which can be made portable. The created library works fine on one of my machines, but, when I send it to other machine, it does not load properly as a dependency of cJSON is missing on the target machine. I do not have accessibility to install the cJSON library on the machine, though I can copy all the required files.
My current libtool command is :
/bin/bash /home/ubuntu/php-extension/libtool --mode=link cc -DPHP_ATOM_INC -I/home/ubuntu/php-extension/include
-I/home/ubuntu/php-extension/main -I/home/ubuntu/php-extension -static -I/usr/include/php/20170718
-I/usr/include/php/20170718/main
-I/usr/include/php/20170718/TSRM
-I/usr/include/php/20170718/Zend
-I/usr/include/php/20170718/ext
-I/usr/include/php/20170718/ext/date/lib
-I/usr/local/include
-L/usr/local/lib -lcjson
-DHAVE_CONFIG_H -g -O2
-o myextension.la -export-dynamic -avoid-version -prefer-pic -module -rpath /home/ubuntu/php-extension/modules
myextension.lo
How should I build the extension so it contains all the dependent libraries and there is no need to install library on target machine?

compiling keepalived from source not working

i have been trying to compile and install keepalived like in the following link http://www.keepalived.org/doc/installing_keepalived.html
i'm building it on ubuntu/trusty64 vagrant machine
i have installed all the requirement specified in the document
sudo apt-get install curl gcc libssl-dev libnl-3-dev libnl-genl-3-dev libsnmp-dev
when i made 'make' command
it showed me the following error
gcc -g -O2 -I/usr/src/linux/include -I/usr/src/linux/include -
DLIBIPVS_USE_NL -Wall -Wunused -c -o libipvs.o libipvs.c
In file included from libipvs.h:13:0,
from libipvs.c:23:
ip_vs.h:15:29: fatal error: netlink/netlink.h: No such file or directory
#include <netlink/netlink.h> <-(the terminal saying that the error)
i tried that answer
libnl-3 includes broken?
i entered
sudo make -I /usr/include/libnl3
or
make -I /usr/include/libnl3
but both failed i'm kind new c compiling and building in linux so i would aperciate any help

sscanf + c99 not working on some platforms?

When I compile a simple Hello World! program that uses the sscanf function on my local Debian lenny x64, it works. But when I upload the same program to the server running CentOS x86, it will not work. If I do not use sscanf, then the program works on both computers.
gcc -std=c99 -O2 -pipe -m32
If I compile it with sscanf but without -std=c99, then it works on both computers.
gcc -O2 -pipe -m32
What is the problem with sscanf and c99 on CentOS x86 ? I thought that compiling with the -m32 flag would work on all Linuxes ? (I have limited access to the CentOS server, so I do not have access to error messages.)
Probably the CentOS box is using an old version of glibc. Since the nonstandard GNU extensions to their scanf implementation ended up making glibc conflict with c99, they added a nasty hack of redirecting *scanf to __isoc99_*scanf when -std=c99 is in use; if your copy of glibc is missing the __isoc99_sscanf symbol, the program will then fail to run.
Static linking, or linking to a different libc without ugly backwardsness-compatibility hacks, would solve the problem.
Are you uploading the binary or the source and then recompiling? If you are uploading the binary, you are probably running into a library compatibility issue between Debian and CentOS.
If that is the case, upload the source only and recompile on CentOS.
If you do not have permission to compile # CentOS, then try compiling a static binary. You can use dietlibc which makes smaller binaries than glibc or try EGLIBC which is the default C library that Debian will use starting Debian "squeeze".
I came up with the similar problem, it works # Ubuntu 64-bit, but the compile fails # CenseOS 64-bit (REHL5 desktop):
the error message is:
undefined reference to `__isoc99_sscanf#GLIBC_2.7'
when i copied the executable file compiled #Ubuntu to REHL5, and run it another error appeared:
elf file os abi invalid
it is compiled without flag -std=c99, i'm a newbie at C, and looking forword some workarounds, ex. add some flag.
Makefile:
CC=gcc
CCFLAGS= -Wall -O2 -DLINUX -I../include
demos:linuxdemo.c
$(CC) $(CCFLAGS) -o demoA linuxdemo.c -L../lib -lsense4 -lusb
$(CC) $(CCFLAGS) -o demoSO linuxdemo.c -lusb -lsense4
clean:
rm -f demoA
rm -f demoSO
You need to update your glibc to 2.7
download the rpm package from here:
http://archive.fedoraproject.org/pub/archive/fedora/linux/releases/8/Everything/x86_64/os/Packages/
needs:
libc-common-2.7-2.x86_64.rpm
glibc-headers-2.7-2.x86_64.rpm
glibc-devel-2.7-2.x86_64.rpm
glibc-2.7-2.x86_64.rpm
command:
rpm -Uvh --aid --nodeps glibc-common-2.7-2.x86_64.rpm
rpm -Uvh --aid --nodeps glibc-headers-2.7-2.x86_64.rpm
rpm -Uvh --aid --nodeps glibc-devel-2.7-2.x86_64.rpm
rpm -Uvh --aid --nodeps glibc-2.7-2.x86_64.rpm

Resources