Automatically reference header files in different directories - c

I am attempting to run a tool known as crest on existing applications. My first target application is Apache. The output (as shown below) indicates that some header files are not being found. These are located in other directories in the source folder. One of these being \httpd-2.2.14\srclib\apr\include. I'd rather not change the source code of apache since I will want to run this command against numerous files in Apache and then apply the same technique to several other applications.
My question is:
1) How can I make it so whenever these referenced include files are being looked for, it locates the proper directory they are located in and will use that. I can define the directories. A friend mentioned something about altering the command line input, or building environment variables?
Other thoughts/suggestions would be appreciated.
Thanks all.
The command to run crest is:
../bin/crestc ../../httpd-2.2.14/server/request.c -dfs
I get the following output:
[root#localhost src]# ../bin/crestc ../../httpd-2.2.14/server/request.c -dfs
cp libcrest/libcrest.a ../lib
cp run_crest/run_crest ../bin
cp process_cfg/process_cfg ../bin
cp tools/print_execution ../bin
cp libcrest/crest.h ../include
cp libcrest/libcrest.a ../lib
cp run_crest/run_crest ../bin
cp process_cfg/process_cfg ../bin
cp tools/print_execution ../bin
cp libcrest/crest.h ../include
gcc -D_GNUCC -E -I../bin/../include -DCIL=1 ../../httpd-2.2.14/server/request.c -o ./request.i
../../httpd-2.2.14/server/request.c:28:25: error: apr_strings.h: No such file or directory
../../httpd-2.2.14/server/request.c:29:25: error: apr_file_io.h: No such file or directory
../../httpd-2.2.14/server/request.c:30:25: error: apr_fnmatch.h: No such file or directory
../../httpd-2.2.14/server/request.c:33:22: error: apr_want.h: No such file or directory
../../httpd-2.2.14/server/request.c:36:23: error: ap_config.h: No such file or directory
../../httpd-2.2.14/server/request.c:37:19: error: httpd.h: No such file or directory
../../httpd-2.2.14/server/request.c:38:25: error: http_config.h: No such file or directory
../../httpd-2.2.14/server/request.c:39:26: error: http_request.h: No such file or directory
../../httpd-2.2.14/server/request.c:40:23: error: http_core.h: No such file or directory
../../httpd-2.2.14/server/request.c:41:27: error: http_protocol.h: No such file or directory
../../httpd-2.2.14/server/request.c:42:22: error: http_log.h: No such file or directory
../../httpd-2.2.14/server/request.c:43:23: error: http_main.h: No such file or directory
../../httpd-2.2.14/server/request.c:44:25: error: util_filter.h: No such file or directory
../../httpd-2.2.14/server/request.c:45:26: error: util_charset.h: No such file or directory
../../httpd-2.2.14/server/request.c:46:25: error: util_script.h: No such file or directory
../../httpd-2.2.14/server/request.c:48:22: error: mod_core.h: No such file or directory
BRead 0 branches.
Read 0 nodes.
Wrote 0 branch edges.
[root#localhost src]#

You can set the C_INCLUDE_PATH environment variable (use a : to separate multiple paths):
export C_INCLUDE_PATH=/path/to/include/files:/path/to/more/include/files

Related

Mingw32 make command: Unrecognized option -z

I'm trying to make this project using Mingw32:
GitHub PNG2POS
For that, I'm doing the following command using git bash:
git clone --recursive https://github.com/petrkutalek/png2pos.git
It creates a folder called png2pos containing the project sources, and an important file called Makefile.
From there, I cd into the newly create folder, and try to execute the command
make
The expected result was the sources being built into an executable file, but I'm getting some errors that don't allow me to to that:
(...)/x86_64-pc-cygwin-bin/ld: unrecognized option '-z'
use the --help option for usage information
collect2: error: ld returned 1 exit status
Makefile:36: recipe for target 'png2pos' failed
mingw32-make: *** [png2pos] Error 1
What am I supposed to do for this to work and create my desired executable file?

GCC compiler errors with “No such file or directory”

My Ubuntu version is 14.04 LTS. I have a C program copied on the desktop by the name sendRawEth.c. When I write:
gcc sendRawEth.c -o sendRawEth
The compiler complains:
gcc: error: sendRawEth.c: No such file or directory
gcc: fatal error: no input files
I have no idea how to solve this error.
please do the following.
On terminal check the present directory by 'pwd' command and then check the directory in which your programme is there and see if they are same or not. And while writing gcc yourfile it's case sensitive. Hope this helps
There are 2 reasons for such errors.
You said you copied your C programs in your desktop folder.
This means you may have only copied sendRawEth.c. file format not the executable file.
You should ensure you copy the .exe files as well.
You need to change the directory to the same folder that you copied your programs into.
First, check your current folder by typing pwd.
Then change it to your required folder with:
cd /outerfolder/your program folder
Then compile it with:
gcc -o programname programname.c
And finally execute it with:
./programname

Libtool prefixes objects but gcov requires them without prefix

I need to perform some test coverage with gcov on a shared library I am working on.
The problem is libtool renames the object files from my-name.c to libmylib_la-my-name.lo and gcov is unable to handle that conversion. Everytime I run it, the error cannot open notes file is generated.
If I manually rename my-name.c to libmylib_la-my-name.c after the build gcov works fine, so there is no other problem apart the filename mangling.
Addendum
Trying to provide a minimal working example I discovered the filename mangling happens only when lib..._la_CFLAGS is set (and also when it is set to an empty value).
cat <<EOT > configure.ac
AC_INIT(sample,0.0.1)
AC_CONFIG_SRCDIR(configure.ac)
AM_INIT_AUTOMAKE(foreign)
LT_INIT
AC_PROG_CC
AC_CONFIG_FILES(Makefile)
AC_OUTPUT
EOT
cat <<EOT > Makefile.am
lib_LTLIBRARIES=libsample.la
libsample_la_SOURCES=sample.c
# The following line triggers the filename mangling (libsample_la-sample.lo instead of sample.lo)
libsample_la_CFLAGS=
EOT
touch sample.c && autoreconf -if && ./configure && make
Is there a way to avoid the filename mangling operated by libtool or to let gcov understand the filename mangling scheme?
Gcov gcda and gcno files are named after object files. You can run gcov from source directory directly on object file or you can use -o option of gcov to specify the object file and corresponding gcov files.
For example I have a small project that builds a shared library. I pass gcov flags to make command:
make CFLAGS="-O0 --coverage" LDFLAGS=--coverage
Object files and corresponding gcno files are created in src/.libs folder:
$ ls -la src/.libs
libtest_la-test.o
libtest_la-test.gcno
The source file is in src folder
$ ls src/
test.c
Next I run my test suite and gcda files are created:
$ ls -la src/.libs
libtest_la-test.o
libtest_la-test.gcno
libtest_la-test.gcda
Now I can enter src directory and run gcov, specifiying object file name:
$ gcov -o .libs/libtest_la-test.o test.c
File ‘test.c’
Lines executed:27.08% of 96
Creating ‘test.c.gcov'
It is also possible to just run gcov on object file:
$ gcov .libs/libtest_la-test.o
File ’test.c’
Lines executed:27.08% of 96
Creating ’test.c.gcov'
Or even just specifying base name of object file and gcov files:
$ gcov .libs/libtest_la-test
File ’test.c’
Lines executed:27.08% of 96
Creating ’test.c.gcov'
But I would suggest another automated approach that works very well for me, using lcov. I invoke it from top directory specifying paths to source files and object files:
$ lcov --base-directory src --directory src/.libs/ --capture --output-file gcov.info
Capturing coverage data from src/.libs/
Found gcov version: 4.8.2
Scanning src/.libs/ for .gcda files ...
Found 10 data files in src/.libs/
Processing .libs/test_la-test.gcda
[…]
Finished .info-file creation
$ genhtml -o html/coverage gcov.info
Reading data file gcov.info
Found 10 entries.
Found common filename prefix "/usr/src/libtest”
Writing .css and .png files.
Generating output.
Processing file src/test.c
[…]
Writing directory view page.
Overall coverage rate:
lines......: 56.1% (2098 of 3737 lines)
functions..: 68.8% (139 of 202 functions)
Now html/coverage directory contains html files that can be easily analyzed in a web browser.
Libtool shouldn't change .c file names. However, it does change .o file names; this is because it needs to compile libraries twice on some platforms (once to create position-independent code (PIC) for .so (shared) libraries, once to create code which is not PIC for .a (static) libraries).
What you may be seeing is the fact that gcov has issues with shared libraries. See "can gcov deal with shared object?" for details.
If that doesn't fix it, I'll have to agree with Brett that you ned to supply more info.

CROSS COMPILE:arm-eabi-gcc -static -o hello hello.c

while cross compiling (application)"arm-eabi-gcc -static -o hello hello.c" following error occurring
hello.c:1:18: error: stdio.h: No such file or directory
hello.c:2:19: error: stdlib.h: No such file or directory
hello.c:3:19: error: string.h: No such file or directory
hello.c:4:19: error: fcntl.h: No such file or directory
hello.c:5:20: error: unistd.h: No such file or directory
hello.c:6:23: error: sys/types.h: No such file or directory
hello.c:7:22: error: sys/stat.h: No such file or directory
hello.c:8:23: error: sys/ioctl.h: No such file or directory
`
I am able to cross compile kernel modules.
if you try to cross-compile user program in linux machine, you shoud use not arm-eabi-gcc but arm-linux-gnueabi-gcc.
you have a broken crosscompiler. Get a better toolchain, you have a lot of options:
OpenEmbedded
Yocto
Buildroot
Scratchbox

Makefile - include library

I'm trying to write a module that uses the function nanosleep().
when my make file runs it changes the build libary by doing:
make -C /lib/modules/2.6.18-128.4.1.el5/build M=/workspace/lcd-winstar-0.0.1 modules
nanosleep is declare in /usr/include so my makefile cant find it.
what lines should I add to my makefile to include this location as well?????
thanks
-I dir
Add the directory dir to the list of directories to be searched for
header files. Directories named by -I
are searched before the standard
system include directories. If the
directory dir is a standard system
include directory, the option is
ignored to ensure that the default
search order for system directories
and the special treatment of system
headers are not defeated .
&&
-Ldir
Add directory dir to the list of directories to be searched for -l

Resources