I'm trying to create a lib_mysqludf_sys.so for mariadb database but everytime when I run it there is an error. Does anyone know how to fix it?
enter image description here
┌──(kali㉿kali)-[~/OSCP/sandbox/lib_mysqludf_sys]
└─$ make
gcc -Wall -I/usr/include/mariadb/server -I/usr/include/mariadb/ -I/usr/include/mariadb/server/private -I. -shared lib_mysqludf_sys.c -o lib_mysqludf_sys.so
In file included from lib_mysqludf_sys.c:40:
/usr/include/mariadb/my_global.h:3:2: warning: #warning This file should not be included by clients, include only <mysql.h> [-Wcpp]
3 | #warning This file should not be included by clients, include only <mysql.h>
| ^~~~~~~
In file included from lib_mysqludf_sys.c:41:
/usr/include/mariadb/my_sys.h:3:2: warning: #warning This file should not be included by clients, include only <mysql.h> [-Wcpp]
3 | #warning This file should not be included by clients, include only <mysql.h>
| ^~~~~~~
lib_mysqludf_sys.c:44:10: fatal error: m_ctype.h: No such file or directory
44 | #include <m_ctype.h>
| ^~~~~~~~~~~
compilation terminated.
make: *** [Makefile:4: install] Error 1
This udf project is nowadays more than a decade of years old. Files were renamed or removed, so now wonder why the build fails. And it was initially written for MySQL, not for MariaDB.
I would recommend to check the udf_example.c code in MariaDB server and to fix the include files. I would also recommend to define STANDARD when building the shared object (-DSTANDARD).
Related
I need to check 2 million C source files for a research project for simple syntax errors like missing (semicolons, parenthesis, ...). Each file is a function without main() and header files.
With the help of GCC, I have used the following command:
gcc -c -fsyntax-only -w file.c
My script is doing the job, but the only problem is that almost more than 95% of errors are related to missing header files. I tried to add some of these header files to each function, but the number of these header files seems endless.
Is there any way to suppress errors about missing header files?
Does GCC have a special Flag that I can use for my purpose?
A sample of errors that are related to header files:
error: unknown type name ‘ioreq_t’
error: unknown type name ‘SH7750State’
error: unknown type name ‘int64_t’
error: unknown type name ‘AVCodecContext’
error: unknown type name ‘BlockDriverState’
error: unknown type name ‘PXA2xxLCDState’
Also, I appreciate any other solution besides using GCC.
As workaround, you might create one header which includes all the missing #include and use -include to force that inclusion on top of examined files.
So you don't edit all files:
gcc -include "workaround.h" -c -fsyntax-only -w file.c
I generated toolchain with Yocto for qemuarm, by running the following command: 'bitbake -c populate_sdk core-image-minimal' and installed on my build machine, Following are the commands i am executing for busybox to compile.
. /opt/poky/3.1.14/environment-setup-armv7vet2hf-neon-poky-linux-gnueabi
wget https://busybox.net/downloads/busybox-1.30.0.tar.bz2
tar xvf busybox-1.30.0.tar.bz2
make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi-gcc defconfig
make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- defconfig
make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- menuconfig
make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- install
The compilation is failing with the below error:
CC applets/applets.o
In file included from /opt/poky/3.1.14/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/include-fixed/syslimits.h:7,
from /opt/poky/3.1.14/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/include-fixed/limits.h:34,
from include/platform.h:153,
from include/libbb.h:13,
from include/busybox.h:8,
from applets/applets.c:9:
/opt/poky/3.1.14/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/include-fixed/limits.h:194:61: error: no include path in which to search for limits.h
194 | #include_next <limits.h> /* recurse down to the real one */
| ^
In file included from include/libbb.h:13,
from include/busybox.h:8,
from applets/applets.c:9:
include/platform.h:164:11: fatal error: byteswap.h: No such file or directory
164 | # include <byteswap.h>
| ^~~~~~~~~~~~
compilation terminated.
make[1]: *** [scripts/Makefile.build:198: applets/applets.o] Error 1
make: *** [Makefile:372: applets_dir] Error 2
Can you please help me on this
I'm having issues compiling some c code.
I have a code structure like the following
main.c
src
line
line.h
line.c
Available here: https://github.com/Vafilor/c_includes
main.c includes #include "src/line/line.h"
src/line/line.c includes #include "src/line/line.h"
When I try to compile this with gcc main.c src/line/line.c on ubuntu 20.4
I get this error
src/line/line.c:1:10: fatal error: src/line/line.h: No such file or directory
1 | #include "src/line/line.h"
| ^~~~~~~~~~~~~~~~~
compilation terminated.
How can I get this to compile?
Additional info:
I've been looking at the bluez code at https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/
and they have something similar with
client/main.c - includes shell.h
src/shared/shell.c - includes shell.h
src/shared/shell.h
so I'm trying to figure out how it works for their code base.
I have been struggling with having my make file properly compile all of my source files due to an include error at compile time. I have looked at some questions online but the solutions do not seem to fix mine.
I can get this program to compile if I have all of the source files in the same directory but once I tried splitting up the files into separate directories it no longer worked.
Here is is the error:
~/Documents/GitHub/testing$ make build
gcc -I/. -Wall main.c inplementation/inplementation.c -o program.exe
In file included from main.c:3:
./inplementation/inplementation.h:4:10: fatal error: 'module/module.h' file not found
\#include "module/module.h"
1 error generated.
In file included from inplementation/inplementation.c:1:
inplementation/inplementation.h:4:10: fatal error: 'module/module.h' file not found
\#include "module/module.h"
1 error generated.
make: *** [build] Error 1
Here is a screenshot of my file directory:
Here is a screenshot of my include paths of this project:
Here is a screenshot of my make file (specifically build):
You use #include "module/module.h" while the include flag is -I/$(TESTING_DIR)/module.
First of all I think you probably meant -I$(TESTING_DIR)/module, otherwise you are adding an extra slash before the path stored in TESTING_DIR.
But the main problem is that module/module.h doesn't exist under that module folder. So you need to do one of these combinations:
-I$(TESTING_DIR)/module and #include "module.h"
-I$(TESTING_DIR) and #include "module/module.h"
Why does gcc ignore these header guards in this simple test program?
The header file is:
#ifndef MYHEADER_H
#define MYHEADER_H
#warning "header declared"
int some_int=0;
#endif
And the two .c files are:
main.c:
#include "header.h"
int main ()
{
return some_int;
}
source.c:
#include "header.h"
int get_int()
{
return some_int;
}
When compiling with:
gcc -o out main.c source.c
I get the following output:
In file included from main.c:1:
header.h:4:2: warning: #warning "header declared" [-Wcpp]
4 | #warning "header declared"
| ^~~~~~~
In file included from source.c:1:
header.h:4:2: warning: #warning "header declared" [-Wcpp]
4 | #warning "header declared"
| ^~~~~~~
/usr/bin/ld: /tmp/ccmAbN1J.o:(.bss+0x0): multiple definition of `some_int'; /tmp/ccEd5PwN.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
As expected, the warning shows up, when the compiler includes the header file for the first time. But why wont the header guards stop the second inclusion?
The gcc version is:
gcc version 9.2.1 20200130 (Arch Linux 9.2.1+20200130-2)
Header guards guard against multiple inclusion in a single translation unit (usually a .c file and everything it includes, directly or indirectly).
You have two translation units, main.c and source.c, and they're compiled independently (even if you use a single command line line gcc main.c source.c). That's why you're getting an error message from the linker, not from the compiler.
If you want to define an object, you should do it in a .c file and declare it as extern in the corresponding .h file. The .c file defining the object is compiled just once, and multiple other .c files can see the declaration in the .h file.
It's not ignoring them. You have two separate compilation units there and each one needs header.h. Header guards are intended to prevent a single compilation unit from including the same header twice. For example. If main.c included header.h' directly, but also includedfoo.hwhich also includedheader.h, when all the includes are expanded the header guard ensures thatheader.h`'s contents only appear once.
There are 2 compilation units : 1 for main.c and 1 for source.c. These are compiled separately (and completely independently) by the compiler, resulting in 2 object files (eg. main.o resp. source.o). Each of these prints the warning :
In file included from main.c:1:
header.h:4:2: warning: #warning "header declared" [-Wcpp]
4 | #warning "header declared"
| ^~~~~~~
These object files are then linked into an executable out by the linker.
But the linker discovers that both object files define the same symbol some_int, and thus fails to generate the executable, resulting in :
/usr/bin/ld: /tmp/ccmAbN1J.o:(.bss+0x0): multiple definition of `some_int'; /tmp/ccEd5PwN.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status