NVCC: warning: allowing all exceptions is incompatible with previous function - c

I'm trying to actually use -Wall and remove all warnings in my current program. I know this isn't required but it seems like it can't hurt and hasn't proven to be too time consuming.
I'm using sockets to communicate between two programs: one in C++11 (with c sections) and another in CUDA (so NVCC as the compiler). The socket creation is very similar, and in order to prevent warnings I have written lines such as:
#include<string.h>
extern char* strcpy(char*,const char*);
This forward declaration works great with gcc/g++ to prevent a warning like:
source.c:33:4: warning: implicit declaration of function ‘strcpy’ [-Wimplicit-function-declaration]
strcpy(saun.sun_path,CUDA_SOCKET_ADDR);
source.c:33:4: warning: incompatible implicit declaration of built-in function ‘strcpy’ [enabled by default]
However, the same code on the NVCC program yields another warning:
CUDAsource.cuh(26): warning: allowing all exceptions is incompatible with previous function "strcpy"
/usr/include/string.h(129): here
Is there another setting I need to set in my makefile? Currently the C side has the following flags:
-g -O0 -Wall -std=c99
and nvcc has:
-g -G
Any tips would be appreciated.
Thanks.

Removing the extern definitions and adding -D_GNU_SOURCE to the compiler flags resolved the issue.

Related

How to fix implicit declaration and consequential problems when trying to install a C program on Linux (randfold-2.0)?

I am trying to compile randfold-2.0 on an HPC cluster I am working from, but am encountering troubles.
When I try the compilation using make I got the following error message:
*user#loginnode*:~/mirdeep2/essentials/randfold-2.0> make
gcc -O3 -I. -I/***/mirdeep2/essentials/squid-1.9g -L/***/mirdeep2/essentials/squid-1.9g/ -o randfold params.o energy_par.o fold.o fold_vars.o utils.o randfold.c -lm -lsquid
randfold.c: In function ‘main’:
randfold.c:89:2: warning: implicit declaration of function ‘strcpy’ [-Wimplicit-function-declaration]
strcpy(seqfile,*argv);
^~~~~~
randfold.c:89:2: warning: incompatible implicit declaration of built-in function ‘strcpy’
randfold.c:89:2: note: include ‘<string.h>’ or provide a declaration of ‘strcpy’
The implicit declaration problems occurs multiple times, also referring to strlen for example.
I found a fix here http://seqanswers.com/forums/showthread.php?t=47751 that said to include #include <string.h> into the randfrold.c-file.
After that I got numerous other error messages which all read like this, referencing different "_intel***" files:
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: /dss/dsshome1/lxc09/ra57qey/mirdeep2/essentials/squid-1.9g//libsquid.a(shuffle.o): in function `StrShuffle':
shuffle.c:(.text+0x29): undefined reference to `__intel_sse2_strcpy'
I am no C developer and have no experience with it.
Has anybody encountered similar issues or has an idea how to fix this issue? Help would be greatly appreciated!

Can't get C Program to Build

I am trying to execute the c program found here. But when I try to build it in eclipse I get numerous errors about functions being implicitly declared and registers being accessed that don't exist. I was wondering if anybody can get this code to run and how they got it to work (program, OS, etc.) I am on a windows machine using an ubuntu virtual machine with eclipse and gcc to try and execute this code.
Here is a list of errors from Eclipse SDK (I have fixed a few bugs from the original code):
**** Build of configuration Debug for project nearpi ****
make all
Building file: ../src/nearpi.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/nearpi.d" -MT"src/nearpi.d" -o "src/nearpi.o" "../src/nearpi.c"
../src/nearpi.c:465:1: warning: return type defaults to ‘int’ [-Wreturn-type]
../src/nearpi.c: In function ‘main’:
../src/nearpi.c:501:5: warning: implicit declaration of function ‘input’ [-Wimplicit-function-declaration]
../src/nearpi.c:532:9: warning: implicit declaration of function ‘nearPiOver2’ [-Wimplicit-function-declaration]
../src/nearpi.c:540:9: warning: implicit declaration of function ‘dbleCF’ [-Wimplicit-function-declaration]
../src/nearpi.c: At top level:
../src/nearpi.c:590:1: warning: return type defaults to ‘int’ [-Wreturn-type]
../src/nearpi.c:694:1: warning: return type defaults to ‘int’ [-Wreturn-type]
../src/nearpi.c:756:1: warning: return type defaults to ‘int’ [-Wreturn-type]
../src/nearpi.c: In function ‘nearPiOver2’:
Finished building: ../src/nearpi.c
../src/nearpi.c:935:1: warning: control reaches end of non-void function [-Wreturn-type]
../src/nearpi.c: In function ‘input’:
../src/nearpi.c:748:1: warning: control reaches end of non-void function [-Wreturn-type]
Building target: nearpi
../src/nearpi.c: In function ‘main’:
Invoking: GCC C Linker
gcc -o "nearpi" ./src/nearpi.o -lm
../src/nearpi.c:564:1: warning: control reaches end of non-void function [-Wreturn-type]
Finished building target: nearpi
That code has bugs in it, when compiled on a modern compiler[*]. If I were you, I'd contact whomever licensed it, and ask for my money back.
Some of the bugs are:
Missing #include <stdio.h>, #include <math.h>
It uses the register keyword inccorrectly. Delete that keyword everywhere it appears.
It uses "%E" when it should have used "%lE".
It uses "%08x" when it should have used "%08lx".
It uses "1.0E" when it should have used "1.0".
If you fix all of those bugs, it runs. I don't know if it produces the correct answer, but it does run.
*That code was written in 1983, when the prevailing standard for C was the first edition of K&R. There have been three international standards for C published since then, and that code was never updated. Most of the bugs and warnings are a result of being very old.
You face only linking errors (in the current version of the question) like
undefined reference to `floor'
this indicates you need to add the math library by adding '-lm' to the compiler options.
Further explanations you find here

Ignore incompatible pointer types with gcc (char**→void**)

I am compiling some legacy C code with the purpose of migrating it to Java.
I don't want to fix the C code, I just want to run it, in order to compare numerical results.
I get this gcc 4.6.1 compilation error: expected void** but argument is of type char**
Written 20 years ago, this code did not care about pointer types, no big surprise.
QUESTION: How can I tell gcc to ignore these errors and compile anyway?
-fpermissive does not work.
What version of gcc are you trying to compile with? gcc 3 supported a -traditional flag which would tell it to behave like a K&R C compiler, but this option isn't included in gcc 4.
You probably need to run gcc 3 somehow, like installing an OS that included it in a VM. I've read that RHEL 4 used gcc 3, you could try old FreeBSD versions, or it might be available as a package on newer OSes.
By default, gcc only emits a warning. You must be having a -Werror or -pedantic-errors flag somewhere in your compilation flags that turns this warning into an error.
$ cat q.c
void foo(void **x) {}
void bar(void) { foo((char **)0); }
$ gcc -Wall -c q.c
q.c: In function ‘bar’:
q.c:2:1: warning: passing argument 1 of ‘foo’ from incompatible pointer type [enabled by default]
q.c:1:6: note: expected ‘void **’ but argument is of type ‘char **’
$ gcc -v
[...]
gcc version 4.6.2

How to avoid compiler warning when using PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP and -Wextra

I want to use GCC compiler option -Wextra in my project.
But it causes problems with PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP.
The following code:
static pthread_mutex_t g_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
Causes the following warning:
test.c:39: warning: missing initializer
test.c:39: warning: (near initialization for `g_mutex.__data.__nusers')
Is there any way to avoid that warning?
Gcc version is 3.4.5. and pthread version is 2.3.5.
With recent GCC versions (not the one you mention, I'm afraid) you can silence such warnings with the option -Wno-missing-field-initializers.

warning: incompatible implicit declaration of built-in function ‘xyz’

I'm getting a number of these warnings when compiling a few binaries:
warning: incompatible implicit declaration of built-in function ‘strcpy’
warning: incompatible implicit declaration of built-in function ‘strlen’
warning: incompatible implicit declaration of built-in function ‘exit’
To try to resolve this, I have added
#include <stdlib.h>
at the top of the C files associated with this warning, in addition to compiling with the following flags:
CFLAGS = -fno-builtin-exit -fno-builtin-strcat -fno-builtin-strncat -fno-builtin-strcpy -fno-builtin-strlen -fno-builtin-calloc
I am using GCC 4.1.2:
$ gcc --version
gcc (GCC) 4.1.2 20080704
What should I do to resolve these warnings?
In C, using a previously undeclared function constitutes an implicit declaration of the function. In an implicit declaration, the return type is int if I recall correctly. Now, GCC has built-in definitions for some standard functions. If an implicit declaration does not match the built-in definition, you get this warning.
To fix the problem, you have to declare the functions before using them; normally you do this by including the appropriate header. I recommend not to use the -fno-builtin-* flags if possible.
Instead of stdlib.h, you should try:
#include <string.h>
That's where strcpy and strncpy are defined, at least according to the strcpy(2) man page.
The exit function is defined in stdlib.h, though, so I don't know what's going on there.
In the case of some programs, these errors are normal and should not be fixed.
I get these error messages when compiling the program phrap (for example). This program happens to contain code that modifies or replaces some built in functions, and when I include the appropriate header files to fix the warnings, GCC instead generates a bunch of errors. So fixing the warnings effectively breaks the build.
If you got the source as part of a distribution that should compile normally, the errors might be normal. Consult the documentation to be sure.
Here is some C code that produces the above mentioned error:
int main(int argc, char **argv) {
exit(1);
}
Compiled like this on Fedora 17 Linux 64 bit with gcc:
el#defiant ~/foo2 $ gcc -o n n2.c
n2.c: In function ‘main’:
n2.c:2:3: warning: incompatible implicit declaration of built-in
function ‘exit’ [enabled by default]
el#defiant ~/foo2 $ ./n
el#defiant ~/foo2 $
To make the warning go away, add this declaration to the top of the file:
#include <stdlib.h>
I met these warnings on mempcpy function. Man page says this function is a GNU extension and synopsis shows:
#define _GNU_SOURCE
#include <string.h>
When #define is added to my source before the #include, declarations for the GNU extensions are made visible and warnings disappear.

Resources