Skip to content

Does not compile with GCC 10+ #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
GitMensch opened this issue Sep 5, 2023 · 0 comments
Open

Does not compile with GCC 10+ #105

GitMensch opened this issue Sep 5, 2023 · 0 comments

Comments

@GitMensch
Copy link
Contributor

#/tmp/ocesql-1.2b/build/ocesql> make
/bin/sh ../libtool  --tag=CC   --mode=link gcc  -g -O2   -o ocesql errorfile.o ocesql.o ocesqlutil.o parser.o ppout.o scanner.o
libtool: link: gcc -g -O2 -o ocesql errorfile.o ocesql.o ocesqlutil.o parser.o ppout.o scanner.o
/usr/bin/ld: scanner.o:/tmp/ocesql-1.2b/build/ocesql/scanner.l:49: multiple definition of `dbname'; ocesql.o:/tmp/ocesql-1.2b/ocesql/ocesql.c:40: first defined here
/usr/bin/ld: scanner.o:/tmp/ocesql-1.2b/build/ocesql/scanner.l:50: multiple definition of `prepname'; ocesql.o:/tmp/ocesql-1.2b/ocesql/ocesql.c:41: first defined here
/usr/bin/ld: scanner.o:/tmp/ocesql-1.2b/build/ocesql/scanner.l:45: multiple definition of `host_reference_list'; ocesql.o:/tmp/ocesql-1.2b/ocesql/ocesql.c:36: first defined here
/usr/bin/ld: scanner.o:/tmp/ocesql-1.2b/build/ocesql/scanner.l:46: multiple definition of `res_host_reference_list'; ocesql.o:/tmp/ocesql-1.2b/ocesql/ocesql.c:37: first defined here
/usr/bin/ld: scanner.o:/tmp/ocesql-1.2b/build/ocesql/scanner.l:52: multiple definition of `cursorname'; ocesql.o:/tmp/ocesql-1.2b/ocesql/ocesql.c:42: first defined here
/usr/bin/ld: scanner.o:/tmp/ocesql-1.2b/build/ocesql/scanner.l:47: multiple definition of `sql_list'; ocesql.o:/tmp/ocesql-1.2b/ocesql/ocesql.c:38: first defined here
/usr/bin/ld: scanner.o:/tmp/ocesql-1.2b/build/ocesql/scanner.l:40: multiple definition of `hostlineno'; ocesql.o:/tmp/ocesql-1.2b/ocesql/ocesql.c:32: first defined here
/usr/bin/ld: scanner.o:/tmp/ocesql-1.2b/build/ocesql/scanner.l:44: multiple definition of `exec_list'; ocesql.o:/tmp/ocesql-1.2b/ocesql/ocesql.c:39: first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:425: ocesql] Error 1

The reason is documented in https://gcc.gnu.org/gcc-10/porting_to.html

A common mistake in C is omitting extern when declaring a global variable in a header file. If the header is included by several files it results in multiple definitions of the same variable. In previous GCC versions this error is ignored. GCC 10 defaults to -fno-common, which means a linker error will now be reported. To fix this, use extern in header files when declaring global variables, and ensure each global is defined in exactly one C file. If tentative definitions of particular variables need to be placed in a common block, __attribute__((__common__)) can be used to force that behavior even in code compiled without -fcommon. As a workaround, legacy C code where all tentative definitions should be placed into a common block can be compiled with -fcommon.

Both ocesql.c (which has this as external definition) and scanner.l (which includes the external one via ocesql.h) share those definitions with the same name. scanner.l has both "local" and "external" names that match to this.

So as a temporary workaround add CFLAGS=-fcommon if you need to compile a not-yet-fixed version of ocesql with a recent GCC; to reproduce the failure on the current CI: just add CFLAGS=-fno-common, to actually fix this: check if those should be shared or not, then adjust the code accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant