Creating a shared library by Eclipse CDT - c

I am getting this error each time and i do not not what is happening .. can anyone help please ?
#Mike Kinghan this is the new error
08:21:40 **** Incremental Build of configuration Debug for project 5exe ****
make all
Building file: ../5exe.c
Invoking: GCC C Compiler
gcc -I"C:\Users\Dylan Galea\workspace\5\source" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"5exe.d" -MT"5exe.o" -o "5exe.o" "../5exe.c"
../5exe.c: In function 'main':
../5exe.c:42:10: warning: variable 'temp' set but not used [-Wunused-but-set-variable]
char temp; //temporary storage to remove the extra ( character
^
Finished building: ../5exe.c
Building target: 5exe.exe
Invoking: MinGW C Linker
gcc -L"C:\Users\Dylan Galea\workspace\5\Debug -o "5exe.exe" ./5exe.o -l5
/usr/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/usr/bin/sh: -c: line 1: syntax error: unexpected end of file
makefile:29: recipe for target '5exe.exe' failed
make: *** [5exe.exe] Error 258
08:21:40 Build Finished (took 463ms)

Your source code (which you didn't post) has an unterminated string literal, something like
printf("example text %d with an integer , 4);
/* ^ missing `"' /*

The backslash ('\') is an escape-character for the shell (/usr/bin/sh). So in this line:
gcc -I"C:\Users\Dylan Galea\workspace\5\source\" -O0 -g3 -Wall -c -fmessage- length=0 -MMD -MP -MF"5exe.d" -MT"5exe.o" -o "5exe.o" "../5exe.c"
the backslash '\' that follows source escapes the following ", and the string
"C:\Users\Dylan Galea\workspace\5\source\" is parsed as having unbalanced quotes.
Do one of the following:
Escape the backslashes:-
-I"C:\\Users\\Dylan Galea\\workspace\\5\\source\\"
Replace them with forward slashes:
-I"C:/Users/Dylan Galea/workspace/5/source/"

Related

Macro wrongly defined in Makefile of Openwrt package

In the openwrt package that I'm working on, I defined a new config flag by adding following bloc to the Config.in file:
config VENDOR_PREFIX
string "Vendor Prefix"
default "X_Custom_SE_"
The flag is well added in the menuconfig:
I want that the value of this config flag is viewed in my C code as a macro. So I defined a macro CUSTOM_PREFIX in the Makefile of the package and assigned to it the value of the defined flag with this way:
TARGET_CFLAGS += -DCUSTOM_PREFIX=\"$(CONFIG_VENDOR_PREFIX)\"
and then I tried to use my macro in my C code by calling it in a structure variable initiation like that:
struct parameter_struct param1= {CUSTOM_PREFIX"param1", 4};
After that I tried to compile it. But I got this compilation error:
/home/user/openwrt//staging_dir/toolchain-mips_mips32_gcc-5.5.0_musl/usr/include -I/home/user/openwrt/staging_dir/toolchain-mips_mips32_gcc-5.5.0_musl/include/fortify -I/home/user/openwrt/staging_dir/toolchain-mips_mips32_gcc-5.5.0_musl/include -I/home/user/openwrt/staging_dir/target-mips_mips32_musl/usr/include -I/home/user/openwrt/staging_dir/target-mips_mips32_musl/usr/include -I/home/user/openwrt/staging_dir/target-mips_mips32_musl/usr/include -DCWMP_VERSION=\"3.0.0\" -I../inc/ -I../dm/ -I../dm/dmtree/ -I../dm/dmtree/common -I../dm/dmtree/tr098 -I../dm/dmtree/tr181 -I../dm/dmtree/upnp -Os -pipe -mips32 -mtune=mips32 -fno-caller-saves -DCONFIG_TARGET_iopsys_brcm63xx_mips -g3 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -iremap/home/user/openwrt/build_dir/target-mips_mips32_musl/icwmp-curl/icwmp-4.0-2018-03-21:icwmp-4.0-2018-03-21 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DCUSTOM_PREFIX=X_CUSTOM1_SE_ -D_GNU_SOURCE -D_AADJ -MT ../dm/dmtree/common/libdatamodel_la-deviceinfo.lo -MD -MP -MF ../dm/dmtree/common/.deps/libdatamodel_la-deviceinfo.Tpo -c ../dm/dmtree/common/deviceinfo.c -fPIC -DPIC -o ../dm/dmtree/common/.libs/libdatamodel_la-deviceinfo.o
^
../dm/dmtree/common/deviceinfo.c: At top level:
<command-line>:0:15: error: 'X_CUSTOM1_SE_' undeclared here (not in a function)
../dm/dmtree/common/deviceinfo.c:28:2: note: in expansion of macro 'CUSTOM_PREFIX'
{CUSTOM_PREFIX"param1", 4}
struct parameter_struct param1= {CUSTOM_PREFIX"param1", 4};
seems like that the c program doesn't accept it as a string.
Is there something wrong in my macro definition?
As I expected and I noted in the my post title the mistake is in the definition of the macro in the Makefile. In Openwrt Makefile the definition of the Macro should be like that:
TARGET_CFLAGS += -DCUSTOM_PREFIX=\\\"$(CONFIG_VENDOR_PREFIX)\\\"

No warnings for headers included by headers in non-current directories

How can I let gcc and clang generate warnings for header files included by header files in non-current directories?
I'm using gcc 4.9.2 and clang 3.6.0.
For example, assume that ./include_a.c includes ./dir/a.h, ./dir/a.h includes ./b.h, and ./b.h is expected to generate a warning for -Wconversion; then, gcc and clang with -Wconversion DO NOT generate the expected warning when they compile include_a.c. With -Wconversion -Wsystem-headers, the expected warning is generated, but it often comes with many useless warnings for system headers. When ./b.h is directly included from a source file in the current directory (such as ./include_b.c), the expected warning is generated without -Wsystem-headers.
The following shell script reproduces this example (the case of clang is omitted):
#!/bin/sh
mkdir dir
echo '#include "b.h"' >dir/a.h
echo 'void f() {int a = 0; char b = a;}' >b.h
echo '#include "dir/a.h"' >include_a.c
echo '#include "b.h"' >include_b.c
set -x
gcc -c include_a.c -Wconversion # DOES NOT generate a warning
gcc -c include_a.c -Wconversion -Wsystem-headers # generate a warning
gcc -c include_b.c -Wconversion # generate a warning
Output:
+ gcc -c include_a.c -Wconversion
+ gcc -c include_a.c -Wconversion -Wsystem-headers
In file included from dir/a.h:1:0,
from include_a.c:1:
./b.h: In function ‘f’:
./b.h:1:31: warning: conversion to ‘char’ from ‘int’ may alter its value [-Wconversion]
void f() {int a = 0; char b = a;}
^
+ gcc -c include_b.c -Wconversion
In file included from include_b.c:1:0:
b.h: In function ‘f’:
b.h:1:31: warning: conversion to ‘char’ from ‘int’ may alter its value [-Wconversion]
void f() {int a = 0; char b = a;}
^
This behavior seems not to be a bug because gcc and clang perform in the same way, but how can I obtain warnings from all the my source files?

compiler isn't issue error/warning in mismatch function parameter

I have the next code :
test.c
#include "a1.h"
int main() {
int a = 8;
foo(a);
return a;
}
a1.h
void foo (int a);
a1.c
int f = 0;
void foo (int a, int b){
f=5+a+b;
return;
}
Pay attention that in a1.c foo has 1 more parameter than the prototype defined in a1.h.
The compiler isn't issue a warning or an error and so as coverity :
make all
Building file: ../src/a1.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/a1.d" -MT"src/a1.d" -o "src/a1.o" "../src/a1.c"
Finished building: ../src/a1.c
Building file: ../src/test.c
Invoking: GCC C++ Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/test.d" -MT"src/test.d" -o "src/test.o" "../src/test.c"
Finished building: ../src/test.c
Building target: test
Invoking: GCC C++ Linker
gcc -o "test" ./src/a1.o ./src/test.o
Finished building target: test
How can I defend myself in those cases ? I know that if I will add #include "a1.h" in the a1.c file I will get an error but is there a way to get an error without the "include " ?
Compiler isn't issuing a warning because it does not know that foo(int) from a1.h header and foo(int,int) from a1.c file is the same function. C++ allows functions to be overloaded, so both functions could potentially coexist. That is why C++ compiler cannot detect this problem, so you need to wait until the linking stage.
If you were compiling using C, not C++, you could have the compiler detect this condition simply by including a1.h at the top of a1.c file.
You're overloading foo. The version with only one parameter is never defined, hence you should get a linker error when using it.
How can I defend myself in those cases ?
You can't defend yourself from function overloading. Just make sure that you've got the same signature in both the header as the source file.

ANSI-C pow function and type casting

This simple program below does not build for some reason. It says "undefined reference to pow" but the math module is included and I'm building it with -lm flag. It builds if I use the pow like pow(2.0, 4.0), so I suspect there is something wrong with my type casting.
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
int i;
for (i = 0; i < 10; i++) {
printf("2 to the power of %d = %f\n", i, pow(2.0, (double)i));
}
return EXIT_SUCCESS;
}
Here is the bulid log:
**** Build of configuration Debug for project hello ****
make all
Building file: ../src/hello.c
Invoking: GCC C Compiler
gcc -O0 -g -pedantic -Wall -c -lm -ansi -MMD -MP -MF"src/hello.d" -MT"src/hello.d" -o "src/hello.o" "../src/hello.c"
Finished building: ../src/hello.c
Building target: hello
Invoking: GCC C Linker
gcc -o "hello" ./src/hello.o
./src/hello.o: In function `main':
/home/my/workspace/hello/Debug/../src/hello.c:19: undefined reference to `pow'
collect2: ld returned 1 exit status
make: *** [hello] Error 1
**** Build Finished ****
You've told it to use the math library in the wrong place -- you're specifying the math library when you compile (where it won't help) but leaving it out when you link (where it's actually needed). You need to specify it when you link:
gcc -o "hello" ./src/hello.o -lm

Syntax error when using check unit testing framework with C99

I'm running into a weird syntax error when I try to compile tests using the check unit testing framework with the -std=c99 flag.
So, I'm trying to compile the example.c:
#include <check.h>
START_TEST(example) {
fail();
} END_TEST
int main(int argc, char** argv){ return 0; }
using autotools, with Makefile.am:
check_PROGRAMS = example
example_SOURCES = example.c
example_CFLAGS = #CHECK_CFLAGS# -Wall -pedantic -std=c99
example_LDADD = #CHECK_LIBS#
and configure.ac:
AC_PREREQ([2.61])
AC_INIT([example], [1.0.0], [noreply#here.com])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
AC_CONFIG_SRCDIR([example.c])
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_RANLIB
PKG_CHECK_MODULES([CHECK], [check >= 0.9.5])
AC_HEADER_STDC
AC_CHECK_HEADERS([stdlib.h string.h unistd.h])
AC_C_CONST
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_TYPE_UINT32_T
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_STAT
AC_CHECK_FUNCS([memset])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
However I get this weird error:
% make check
make example
gcc -DPACKAGE_NAME=\"example\" -DPACKAGE_TARNAME=\"example\" -DPACKAGE_VERSION=\"1.0.0\" -DPACKAGE_STRING=\"example\ 1.0.0\" -DPACKAGE_BUGREPORT=\"noreply#here.com\" -DPACKAGE=\"example\" -DVERSION=\"1.0.0\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_UNISTD_H=1 -DHAVE_FORK=1 -DHAVE_VFORK=1 -DHAVE_WORKING_VFORK=1 -DHAVE_WORKING_FORK=1 -DHAVE_STDLIB_H=1 -DHAVE_MALLOC=1 -DHAVE_STDLIB_H=1 -DHAVE_REALLOC=1 -DHAVE_MEMSET=1 -I. -I/opt/local/include -std=c99 -g -O2 -MT example-example.o -MD -MP -MF .deps/example-example.Tpo -c -o example-example.o `test -f 'example.c' || echo './'`example.c
example.c: In function 'example':
example.c:3: error: parse error before ',' token
make[1]: *** [example-example.o] Error 1
make: *** [check-am] Error 2
So it's finding a syntax error in fail() (which I suppose check implements as a macro). If I remove the -std=c99 flag, the syntax error goes away, and it works fine.
Is there a way I can fix this? I definitely want -std=c99 so that my use (and check.h's use) of variadic macros is ok'd by the compiler.
The basic tutorial on that site always shows the fail called between START_TEST and END_TEST macros. They most likely set some things up for these macros. Done.
Now all you need to get that to compile is give fail() an argument.
It's defined like this:
#define fail(...) _fail_unless(0, __FILE__, __LINE__, "Failed" , ## __VA_ARGS__, NULL)
Which will have a stray , if no argument is given.

Resources