Why does Cygwin's GCC display the first line of every file? - gcc

I'm not a regular Cygwin user. I installed Cygwin and Cygwin64 for testing proposed patches.
Here's the output of a typical make:
User#windows-7-x64 ~/cryptopp
$ make
g++ -DNDEBUG -g -O2 -fPIC -march=native -pipe -c shacal2.cpp
shacal2.cpp:1:0: warning: -fPIC ignored for target (all code is position independent)
// shacal2.cpp - by Kevin Springle, 2003
^
g++ -DNDEBUG -g -O2 -fPIC -march=native -pipe -c seed.cpp
seed.cpp:1:0: warning: -fPIC ignored for target (all code is position independent)
// seed.cpp - written and placed in the public domain by Wei Dai
^
g++ -DNDEBUG -g -O2 -fPIC -march=native -pipe -c shark.cpp
shark.cpp:1:0: warning: -fPIC ignored for target (all code is position independent)
// shark.cpp - written and placed in the public domain by Wei Dai
^
...
Cygwin's make displays the first line of every file it compiles.
Why does Cygwin's make display the first line of every file? How can I stop the behavior?

The output is due to the warning about the -fPIC command line option, just as it says. Remove the -fPIC option from your makefile's CXXFLAGS (or wherever) and it will go away.

Related

Problem with autoconf not making gcc with -Wall warnings

I have a simple project with a simple configure.ac script:
AC_INIT(...)
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES(...)
AC_OUTPUT
using GNU Autoconf version 2.69 (OpenSUSE Linux with gcc 9.2.1), but gcc is being called with no warning flags:
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT aprog.o -MD -MP -MF .deps/aprog.Tpo -c -o aprog.o aprog.c
mv ...
gcc -g -O2 -o aprog aprog.o -lgmp
In particular, I found -Wformat not working. Shouldn't -Wall include -Wformat? And shouldn't all warnings appear on the make line? If I run gcc line directly with -Wformat the warning shows in compile but it doesn't when I run autoconf, configure and make.
What I'm doing wrong?
The -Wall flag in the AM_INIT_AUTOMAKE(...) invocation refers to warnings from automake and related tools like aclocal, not to compiler warnings. You will see these warnings when you are running autoreconf.
Note that while you can also add -Werror to AM_INIT_AUTOMAKE(...) to make your autoreconf run fail on warnings, many common macros (like those shipped with gettext or libtool) will still use deprecated macros which generates a warning, so -Werror means you cannot use this standard set of tools, so -Werror is not very useful in many cases.
If you want to add compiler options, there are a third party macros (e.g. AX_CHECK_COMPILE_FLAG) which test whether the compiler recognizes a given compile option and you can then add them to some variable and use that in places. That is a different stackoverflow question, though.

does gfortran append underscores... error linking Fortran and C

I am trying to compile FormCalc 9.9 on a MacOS 10.10.5.
Compilation consists in running a bash script on terminal. I redirect both stdout and sterr to a log file, but this is all the output I get:
$ ./compile
Compiling for system type MacOSX-x86-64
cp -p ./bin/MacOSX-x86-64/* MacOSX-x86-64/
gcc -O3 -fomit-frame-pointer -ffast-math -Wall -Wextra -m64 -o MacOSX-x86-64/ToForm ./FormCalc/ToForm.c
./FormCalc/ToForm.c:72:9: warning: declaration does not declare anything [-Wmissing-declarations]
__attribute__ ((fallthrough));
^
>
1 warning generated.
strip MacOSX-x86-64/ToForm
gcc -O3 -fomit-frame-pointer -ffast-math -Wall -Wextra -m64 -o MacOSX-x86-64/ToFortran ./FormCalc/ToFortran.c
strip MacOSX-x86-64/ToFortran
gcc -O3 -fomit-frame-pointer -ffast-math -Wall -Wextra -m64 -o MacOSX-x86-64/ToC ./FormCalc/ToC.c
strip MacOSX-x86-64/ToC
gcc -O3 -fomit-frame-pointer -ffast-math -Wall -Wextra -m64 -o MacOSX-x86-64/reorder ./tools/reorder.c
strip MacOSX-x86-64/reorder
looking for gcc... /usr/bin/clang
looking for g++... /usr/bin/clang++
looking for fortran... /usr/local/bin/gfortran
extracting the Fortran libraries... ok
does gfortran append underscores... error linking Fortran and C
How can I get more information about the linking error?

Negate previous -D[efine] flag for GCC

Under GNUStep on Arch Linux, I'm running into an interesting error on a fresh install.
Using my build system I run
gcc `gnustep-config --debug-flags` [other command line args]
in order to build up the command line per the operating system's necessary flags.
This works fine under Ubuntu, but on Arch Linux I'm getting a rather random error:
/usr/include/features.h:328:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
Well, gnustep-config --debug-flags spits out the following:
-MMD -MP -D_FORTIFY_SOURCE=2 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -fno-strict-aliasing -pthread -fPIC -g -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -march=x86-64 -mtune=generic -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -fgnu-runtime -fconstant-string-class=NSConstantString -fexec-charset=UTF-8 -I. -I/home/qix/GNUstep/Library/Headers -I/usr/include -D_FORTIFY_SOURCE=2 -I/usr/include -I/usr/include -I/usr/include -I/usr/lib/libffi-3.1/include/ -I/usr/lib/libffi-3.1/include -I/usr/include/libxml2 -I/usr/include/p11-kit-1
As well, I wish not to have optimizations on my debug builds (and later on I even override GNUStep's -g parameter to -g2).
Is there a way to explicitly undefine -D_FORTIFY_SOURCE later on in the command line, after the call to gnustep-config?
For example, something like
gcc `gnustep-config --debug-flags` -U_FORTIFY_SOURCE ...
where the -U undefines the previously defined macro?
Something to mention; I have -Werror enabled on purpose, and I'd like to keep it.
For now, using sed to work around this works. It appears this is a known issue with _FORTIFY_SOURCE causing issues, and there isn't a straightforward fix.
`gnustep-config --debug-flags | sed 's/-D_FORTIFY_SOURCE=2//g'`

gcc and linking files with CFLAGS

I am trying to run program from the Learn C Hard Way book
I need to pass the library filename 'build/liblcthw.a' as the last parameter.
For eg :
Doesnt Work on Ubuntu :
gcc -g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG build/liblcthw.a tests/list_tests.c -o tests/list_tests
Works on Ubuntu :
gcc -g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG tests/list_tests.c -o tests/list_tests build/liblcthw.a
How do I handle this in Makefile ? CFLAGS will only add it before the source filename and it doesnt work. How do I force CFALGS to add the library filename at the end of the command ?
CFLAGS are flags for the C compiler. Libraries typically go into a variable called LDLIBS. Set LDLIBS=build/liblcthw.a and see if that works.
The first invocation doesn't succeed because the order of sources and libraries in the command line is wrong. The correct order is source files, then object files, followed by static libraries followed by dynamic libraries.

Installing PL/Ruby for PostgreSQL 8.3

This is to enable the development of postgres functions with embedded ruby code,
but I have been unable to build it.
As advised by
http://www.robbyonrails.com/articles/2005/08/22/installing-untrusted-pl-ruby-for-postgresql
I am trying to build the needed plruby.so from the latest version (plruby-0.5.3.tar.gz) provided at ftp://moulon.inra.fr/pub/ruby/
I've sorted out where my local postgres set up is and adjusted the invocation to:
ruby extconf.rb --with-pgsql-include=/usr/postgresql-8.3.4/include/server --enable-shared --disable-conversion --with-pgsql-version=83
I've tried quite number of variations on that, but it does not seem to be able to successfully make
the 'conftest.c' file
It says this:
checking for catalog/pg_proc.h... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
And here is what I end up with in my mkmf.log
have_header: checking for catalog/pg_proc.h... -------------------- yes
"gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -I/usr/postgresql-8.3.4/include/server -g -O2 -fPIC conftest.c -o conftest.i"
checked program was:
/* begin */
1: #include <catalog/pg_proc.h>
/* end */
When I run the gcc line manually, it says there is no 'conftest.c' (and there is not, but
it is supposed to be generated).
'uname -a' ... gives
Linux vdev1 2.6.18.8-xen #2 SMP Thu May 8 11:52:29 PDT 2008 x86_64 x86_64 x86_64 GNU/Linux
'ruby -v' ... gives
ruby 1.8.6 (2008-08-11 patchlevel 287) [x86_64-linux]
Any help and/or advice would be appreciated.
-- Mike Berrow
OK, I managed to hand build this (bypassing the fragile extconf.rb and makefile) by googling for a logfile of
a successful build, starting with the gcc lines I saw there, then fiddling with the gcc compile
flags and paths until it worked.
In plruby.h change the SAFE_LEVEL to 0
as shown below
#ifndef SAFE_LEVEL
//#define SAFE_LEVEL 12
#define SAFE_LEVEL 0
#endif
Compile each from shell then link
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -DHAVE_CATALOG_PG_PROC_H -DHAVE_RB_HASH_DELETE -DHAVE_ST_H -DHAVE_UTILS_ARRAY_H -I/usr/postgresql-8.3.4/include/server -D_FILE_OFFSET_BITS=64 -fPIC -fno-strict-aliasing -g -g -O2 -fPIC -DHAVE_RB_HASH_DELETE -DHAVE_RB_INITIALIZE_COPY -DPG_UTILS_ARRAY -DPG_PL_TRYCATCH -DPG_PL_VERSION=83 -DPLRUBY_CALL_HANDLER=plruby_call_handler -DPLRUBY_VALIDATOR=plruby_validator -c plruby.c
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -DHAVE_CATALOG_PG_PROC_H -DHAVE_RB_HASH_DELETE -DHAVE_ST_H -DHAVE_UTILS_ARRAY_H -I/usr/postgresql-8.3.4/include/server -D_FILE_OFFSET_BITS=64 -fPIC -fno-strict-aliasing -g -g -O2 -fPIC -DHAVE_RB_HASH_DELETE -DHAVE_RB_INITIALIZE_COPY -DPG_UTILS_ARRAY -DPG_PL_TRYCATCH -DPG_PL_VERSION=83 -DPLRUBY_CALL_HANDLER=plruby_call_handler -DPLRUBY_VALIDATOR=plruby_validator -c plplan.c
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -DHAVE_CATALOG_PG_PROC_H -DHAVE_RB_HASH_DELETE -DHAVE_ST_H -DHAVE_UTILS_ARRAY_H -I/usr/postgresql-8.3.4/include/server -D_FILE_OFFSET_BITS=64 -fPIC -fno-strict-aliasing -g -g -O2 -fPIC -DHAVE_RB_HASH_DELETE -DHAVE_RB_INITIALIZE_COPY -DPG_UTILS_ARRAY -DPG_PL_TRYCATCH -DPG_PL_VERSION=83 -DPLRUBY_CALL_HANDLER=plruby_call_handler -DPLRUBY_VALIDATOR=plruby_validator -c plpl.c
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -DHAVE_CATALOG_PG_PROC_H -DHAVE_RB_HASH_DELETE -DHAVE_ST_H -DHAVE_UTILS_ARRAY_H -I/usr/postgresql-8.3.4/include/server -D_FILE_OFFSET_BITS=64 -fPIC -fno-strict-aliasing -g -g -O2 -fPIC -DHAVE_RB_HASH_DELETE -DHAVE_RB_INITIALIZE_COPY -DPG_UTILS_ARRAY -DPG_PL_TRYCATCH -DPG_PL_VERSION=83 -DPLRUBY_CALL_HANDLER=plruby_call_handler -DPLRUBY_VALIDATOR=plruby_validator -c pltrans.c
gcc -shared -o plruby.so plruby.o plplan.o plpl.o pltrans.o -L. -L/usr/lib -L/usr/postgresql-8.3.4/lib -L. -Wl,-Bsymbolic -rdynamic -Wl,-export-dynamic -lruby -lpthread -ldl -lcrypt -lm -lc
Place the '.so' file built above in the dynamic library path ($libdir)
[ determined using pg_config --pkglibdir giving (in my case) /usr/postgresql-8.3.4/lib ]
Others taking this approach will most likely have to do their own tweaking.
Add these functions ...
CREATE OR REPLACE FUNCTION plruby_call_handler()
RETURNS language_handler AS
'$libdir/plruby', 'plruby_call_handler'
LANGUAGE 'c' VOLATILE
COST 1;
ALTER FUNCTION plruby_call_handler() OWNER TO postgres;
CREATE OR REPLACE FUNCTION plruby_validator(oid)
RETURNS void AS
'$libdir/plruby', 'plruby_validator'
LANGUAGE 'c' VOLATILE
COST 1;
ALTER FUNCTION plruby_validator(oid) OWNER TO postgres;
Add 'plruby' as a procedural language
CREATE PROCEDURAL LANGUAGE 'plruby' HANDLER plruby_call_handler;
Test it:
CREATE FUNCTION ruby_max(int4, int4) RETURNS text AS '
if args[0].to_i > args[1].to_i
return "The one on the left is bigger"
else
return "The one on the right is bigger"
end
' LANGUAGE 'plruby';
select ruby_max(8, 9);
There are other build options for this that enable type 'conversions'.
The above build is the simplest one and all function parameters actually
come into ruby as strings (even though they are declared as int4).
Thus the need for the 'to_i' call here.

Resources