On Linux, is there a way to pass arguments to gcc from a file. That is to gave file like compile.args
% cat compile.args
-g3
-ggdb
-pedantic
-pedantic-errors
-Wall
-Werror
-O0
vec1.cpp
-o vec1
and then give this file to g++/gcc. I can do this using cat compile.args | xargs g++, is they any other way? Does gcc support this?
thanks.
Yes, just run gcc #compile.args
For verbosity, also something like this should work (depending on running shell)
g++ `cat compiler.args|xargs`
or
COMPILE_ARGS=`cat compiler.args|xargs` g++ ${COMPILE_ARGS}
Related
I am about 3 hours new to Linux/Cygwin/virtually anything even borderline computer science. I have been tasked with installing a program for rotors/propellers for research (XROTOR), but I cannot figure out how to run the program. It seems to have been developed in Fortran (maybe?), and came with a README. The README is asking me to build the file, but I have no clue what that means. I have downloaded Cygwin, and have gotten as far as the "make libPLT.a" line. I then cd'ed to the bin folder, and typed in "make xrotor" like the README states, but I keep getting the following error:
$ make
ifort -c -I../src -O -static ../src/xrotor.f
sh: ifort: command not found
make: *** [Makefile:147: xrotor.o] Error 127
I've included the README as well. I don't know what I'm doing, and I figured this was a decent place to start. Any help is GREATLY appreciated!!!
EDIT: Left the README out for whatever reason, sorry. I've written it out here:
General
XROTOR and its plot library should compile on any Unix system
with normal Fortran-77, C, and X-Windows support. So far,
XROTOR has been tested on the following systems:
DEC-5000
Alpha
SGI
* Sun
* RS/6000
* HP-9000
* Pentium/Linux
The systems marked with "*" have peculiar features which require slight
modifications to the Makefiles in the plotlib/ and bin/ directories.
Examine these Makefiles before building the plot library and Xrotor.
Build Sequence
To install, first build the plot library in ./plotlib ...
% cd plotlib
% make libPlt.a
Then build the programs in ./bin ...
% make xrotor
% make jplot
The README is missing some details, but you need to compile the program from sources,
and to do so you need to adjust some variables in the Makefile's
As prerequisite for compiling you need gcc-fortran,make and library libX11-devel
plus the X11 system for the graphic. Installing xinit is a good start.
$ tar -xf Xrotor7.55.tar.tgz
$ cd Xrotor
$ cd plotlib
than modify config.make to set PLTLIB = libPlt.a
I used my preferred editor, but other are also ok
$ vim config.make
To build:
$ make libPlt.a
gfortran -c -O2 -fdefault-real-8 plt_base.f
gfortran -c -O2 -fdefault-real-8 plt_font.f
gfortran -c -O2 -fdefault-real-8 plt_util.f
gfortran -c -O2 -fdefault-real-8 plt_color.f
gfortran -c -O2 -fdefault-real-8 set_subs.f
gfortran -c -O2 -fdefault-real-8 gw_subs.f
gfortran -c -O2 -fdefault-real-8 ps_subs.f
gcc -c -O2 -DUNDERSCORE Xwin.c
gfortran -c -O2 -fdefault-real-8 plt_old.f
gfortran -c -O2 -fdefault-real-8 plt_3D.f
ar r libPlt.a plt_base.o plt_font.o plt_util.o plt_color.o set_subs.o gw_subs.o ps_subs.o Xwin.o plt_old.o plt_3D.o
ar: creating libPlt.a
ranlib libPlt.a
Than moving to program build directory
$ cd ../bin
again modify Makefile.gfortran to set PLTOBJ = ../plotlib/libPlt.a and LIBS = -L/usr/lib -lX11
$ vim Makefile.gfortran
and build all program in one shot
$ make -f Makefile.gfortran
gfortran -c -I../src -O ../src/xrotor.f
gfortran -c -I../src -O ../src/xoper.f
gfortran -c -I../src -O ../src/xdesi.f
gfortran -c -I../src -O ../src/xmodi.f
...
gfortran -c -I../src -O ../src/plotdata.f
gfortran -o xrotor xrotor.o xoper.o xdesi.o xmodi.o xaero.o xjmap.o xio.o xnoise.o xrotpl.o xcasepl.o xbend.o xinte.o xutils.o jputil.o plutil.o modify.o srclin.o spline.o userio.o vortex.o plotdata.o ../plotlib/libPlt.a -L/usr/lib -lX11
gfortran -c -I../src -O ../src/jplot.f
../src/jplot.f:107:72:
PAUSE 'Hit return to see J values'
1
Warning: Deleted feature: PAUSE statement at (1)
../src/jplot.f:112:72:
PAUSE 'Hit return to see CP values'
1
Warning: Deleted feature: PAUSE statement at (1)
gfortran -o jplot jplot.o xutils.o jputil.o userio.o ../plotlib/libPlt.a -L/usr/lib -lX11
gfortran -c -I../src -O ../src/jplote.f
gfortran -o jplote jplote.o xutils.o jputil.o userio.o ../plotlib/libPlt.a -L/usr/lib -lX11
The Warning means that the PAUSE command does not exist anymore so the progran will
likely not pause on the expected locations.
This could explain why it is not working as expected, but probably as the code is very old some code assumptions about the Unix system are not anymore valid.
Running it after starting the Xwindow graphic system from inside a Xterm
$ ./xrotor
=========================
XROTOR Version 7.55
=========================
Note: The following floating-point exceptions are signalling: IEEE_DENORMAL
STOP COLORSPECTRUM: Non-monotonic color axis. Check COLWIDTH.
Need to edit the COLORSPECTRUMTRP subroutine xrotor/plotlib/plt_color.f. Add the following after line 508
COLWIDTH=(/1.0,1.20000005,0.5,1.4,1.0,1.20000005,1.5/)
I'm trying to use a static library 'mylib.a' created with 'ar'. The examples I have seen use -L and -l to name the library. My attempts at using these fail. However, if I simply put the library file name on the linker command it works. (I'm overlooking something obvious?) Using gcc 4.8.4 Ubuntu 14.04 (see comment in code.) The f?.c and mymain.c are trivially simple. Thanks!
#!/bin/bash
# cc -v shows...
# gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1)
cc -c -Wall -Wstrict-prototypes -o fa.o fa.c
cc -c -Wall -Wstrict-prototypes -o fb.o fb.c
cc -c -Wall -Wstrict-prototypes -o fc.o fc.c
cc -c -Wall -Wstrict-prototypes -o mymain.o mymain.c
ar -rcs mylib.a fa.o fb.o fc.o
# THIS WORKS
#cc -o mypgm mymain.o mylib.a
# THESE FAIL WITH ERROR '/usr/bin/ld: cannot find -lmylib'
cc -o mypgm mymain.o -L. -lmylib
# OR
cc -o mypgm mymain.o -static -L. -lmylib
###
As noted in a comment…
When you use -lname, the linker looks for libname.a or libname.so in one of the directories that it has (already) been told to search for libraries.
You can either rename your library to libmine.a and then -L. -lmine will work, or rename it to libmylib.a and then -lmylib will work (but the repeated lib looks a bit clumsy, or neophytic).
I've been running ns3 sumulations in linux and every time I compiled I had to type
g++ -Wall -o simulacija simulacija.cc -DNS3_ASSERT_ENABLE -DNS3_LOG_ENABLE `pkg-config --libs --cflags
libns3.16-core-debug libns3.16-network-debug libns3.16-applications-debug libns3.16-internet-debug
libns3.16-point-to-point-debug libns3.16-point-to-point-layout-debug libns3.16-csma-debug
libns3.16-csma-layout-debug libns3.16-topology-read-debug libns3.16-wifi-debug`
Is there a way to shorten the flags to eg:
g++ -Wall simulacija.cc -o simulacija -my_params
Thank you
The GCC compiler supports the # notation to embed a sequence of arguments inside a file. Read near end of GCC overall options page.
So you could put in some file params.args the following lines
-Wall
-I /usr/local
-DNS3_ASSERT_ENABLE
-DNS3_LOG_ENABLE
-O
and just invoke
g++ #params.args simulacija.cc -o simulacija
You could have a Makefile rule to build that params.args (e.g. with pkg-config etc...)
Actually, it is time to learn how to use GNU make.
Notice that the # option is not understood by some other compilers like GCC handles it.
You can create a shell script myparams.sh that outputs your parameters:
#!/bin/sh
echo -n "-DNS3_ASSERT_ENABLE -DNS3_LOG_ENABLE"
pkg-config --libs --cflags libns3.16-core-debug [...]
Now you can run
g++ -Wall simulacija.cc -o simulacija `./myparams.sh`
(Don't forget to chmod +x myparams.sh)
I have a new c++ project built with autoconf, automake and libtool. Functionality is divided up into support libraries and user binaries. There is also a set of unittests binaries which link against these libraries, are built and run at make check time, but are not installed.
I said the the project is new. I'm actually just now getting around to extracting the first library that should be installed. Until now the (small amount of) written code was just compiled directly into a unittests.
My attempted Makefile.am snippet looks like this:
lib_LTLIBRARIES += libfoo.la
libfoo_la_SOURCES = foo.cc
In make check, I get this:
/bin/bash ./libtool --tag=CXX --mode=link g++ -Wall -Wextra -Werror -ansi -fprofile-arcs -ftest-coverage -g -O0 -fprofile-arcs -ftest-coverage -L/usr/local/lib -Wl,-rpath /usr/local/lib -o libfoo.la -rpath /usr/local/lib foo.lo -lboost_thread-mt -lboost_system-mt -pthread
libtool: link: g++ -fPIC -DPIC -shared -nostdlib /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6.1/crtbeginS.o .libs/foo.o -L/usr/local/lib -lboost_thread-mt -lboost_system-mt -L/usr/lib/gcc/x86_64-linux-gnu/4.6.1 -L/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/x86_64-linux-gnu/4.6.1/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/crtn.o -fprofile-arcs -O0 -fprofile-arcs -Wl,-rpath -pthread -pthread -Wl,-soname -Wl,libfoo.so.0 -o .libs/libfoo.so.0.0.0
/usr/bin/ld: cannot find libfoo.so.0: No such file or directory
collect2: ld returned 1 exit status
Notice the missing library is precisely the one I'm trying to compile.
(The library is not libfoo, but I am able to reproduce the same error with this stub library. The Makefile.am and error lines above are literal and unedited.)
If I change the automake lines to
check_LTLIBRARIES += libfoo.la
libfoo_la_SOURCES = foo.cc
then the compile looks like this:
/bin/bash ./libtool --tag=CXX --mode=link g++ -Wall -Wextra -Werror -ansi -fprofile-arcs -ftest-coverage -g -O0 -fprofile-arcs -ftest-coverage -L/usr/local/lib -Wl,-rpath /usr/local/lib -o libfoo.la foo.lo -lboost_thread-mt -lboost_system-mt -pthread
libtool: link: ar cru .libs/libfoo.a .libs/foo.o
libtool: link: ranlib .libs/libfoo.a
libtool: link: ( cd ".libs" && rm -f "libfoo.la" && cp -p "../libfoo.la" "libfoo.la" )
..and everything works fine (except my library isn't installed, being in check_.)
Notice the only difference in the command lines is some additional arguments in the 2nd one:
... -Wl,-rpath /usr/local/lib -o libfoo.la -rpath /usr/local/lib foo.lo -lboost_thread-mt ...
I don't know offhand if this new argument shouldn't be there, but it does appear to be causing the problem. Does anyone know what I'm missing?
Some more details:
On osx lion, this works fine (and the command lines are different.) This error manifests on
ubuntu 12.04, possibly other linuxes.
noinst_LTLIBRARIES and EXTRA_LTLIBRARIES work like check_LTLIBRARIES: no extra arguments, and it links. It seems libtool 'convenience' libraries are specifically the ones without these arguments.
automake 1.11.1
autoconf 2.68
libtool 2.4
EDIT
(Manually) dropping -Wl,-rpath /usr/local/lib from the arguments also fixes the problem.
I did it to myself. While bringing in autoconf support for boost, I encountered a bug described here. My work-around followed the suggestion of one post:
diff --git a/m4/boost.m4 b/m4/boost.m4
index 3d4e47c..9dd0c43 100644
--- a/m4/boost.m4
+++ b/m4/boost.m4
## -403,7 +403,7 ## dnl generated only once above (before we start the for loops).
LDFLAGS=$boost_save_LDFLAGS
LIBS=$boost_save_LIBS
if test x"$Boost_lib" = xyes; then
- Boost_lib_LDFLAGS="-L$boost_ldpath -Wl,-R$boost_ldpath"
+ Boost_lib_LDFLAGS="-L$boost_ldpath -Wl,-rpath $boost_ldpath"
Boost_lib_LDPATH="$boost_ldpath"
break 6
else
The -rpath introduced here is the same one apparently causing the issue. If I revert this change, the problem goes away (I am of course left with the first issue, but that's another story.)
I'm tryin to follow the direction to install id3v2. I installed id3lib and did not receive any errors. I now try to do "make" and then "make install" as they suggest that I do.
I get the following responses when I go through the process.
I was under the assumption that I would be able to use the program by typing "id3v2 ....."
However, it seems that the system doesn't find the command. Does that mean the program was not installed? If so, how would I try to find a solution?
[root#ip-xxx-xxx-xxx-xxx id3v2-0.1.12]# make
g++ -Wall -I/opt/local/include/ -DVERSION="\"0.1.12\"" -c -o convert.o convert.cpp
g++ -Wall -I/opt/local/include/ -DVERSION="\"0.1.12\"" -c -o list.o list.cpp
g++ -Wall -I/opt/local/include/ -DVERSION="\"0.1.12\"" -c -o id3v2.o id3v2.cpp
g++ -Wall -I/opt/local/include/ -DVERSION="\"0.1.12\"" -c -o genre.o genre.cpp
g++ -L/opt/local/lib/ -pedantic -Wall -g -o id3v2 convert.o list.o id3v2.o genre.o -lz -lid3
[root#ip-xxx-xxx-xxx-xxx id3v2-0.1.12]# make install
install -c -s id3v2 /opt/local/bin/id3v2
nroff -man id3v2.1 > /opt/local/share/man/man1/id3v2.1
[root#ip-xxx-xxx-xxx-xxx id3v2-0.1.12]# id3v2
-bash: id3v2: command not found
I've looked at the make file itself and it says:
install: all
install -c -s id3v2 ${PREFIX}/bin/id3v2
nroff -man id3v2.1 > ${PREFIX}/share/man/man1/id3v2.1
The Prefix hard coded into the make file is:
/opt/local
Now I think it must be true that it is installing it in the wrong directory. Is it normal to adjust the Makefile? am I barking up the wrong tree?
Most likely path where you installed is not in $PATH. You can either call it with the full path:
/opt/local/bin/id3v2
or add this path to your $PATH:
export $PATH=$PATH:/opt/local/bin
To make it permanent append this line to $HOME/.profile